這裏的一個方式...
如果我這個開始爲QueryOne:
並將此作爲QueryTwo:
我能得到此結果代碼如下:
這裏的M碼:
let
Source = QueryTwoSource,
#"Added Custom" = Table.AddColumn(Source, "QueryOne", each QueryOne),
#"Expanded QueryOne" = Table.ExpandTableColumn(#"Added Custom", "QueryOne", {"DateValue", "DateOfCompletion"}, {"QueryOne.DateValue", "QueryOne.DateOfCompletion"}),
#"Added Custom1" = Table.AddColumn(#"Expanded QueryOne", "Custom", each if ([QueryOne.DateOfCompletion] >= [StartDate]) and ([QueryOne.DateOfCompletion] <= [EndDate]) then "True" else "False"),
#"Renamed Columns" = Table.RenameColumns(#"Added Custom1",{{"Custom", "WithinPeriod"}}),
#"Grouped Rows" = Table.Group(#"Renamed Columns", {"PeriodName", "WithinPeriod"}, {{"CountWithinPeriod", each Table.RowCount(_), type number}, {"SumOfDateValuesWithinPeriod", each List.Sum([QueryOne.DateValue]), type number}, {"AllData", each _, type table}}),
#"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each ([WithinPeriod] = "True")),
#"Expanded AllData" = Table.ExpandTableColumn(#"Filtered Rows", "AllData", {"QueryOne.DateValue", "QueryOne.DateOfCompletion"}, {"QueryOne.DateValue", "QueryOne.DateOfCompletion"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded AllData",{"WithinPeriod"})
in
#"Removed Columns"
附:上面的代碼中的Source
只是電子表格的另一個查詢,它具有三列:PeriodName,StartDate和EndDate。 ...類似於QueryOne是如何使用DateValue和DateOfCompletion列查詢電子表格的表格。所以,基本上,Source = QueryTwoSource
是我如何得到QueryTwo,如上圖。我可以直接使用電子表格作爲QueryTwo的源代碼,但這是我做到的。