查询编辑器 - 基于参数值执行步骤
Query Editor - Perform a step based on a Parameter Value
我想在我的查询中添加一个步骤,执行类似以下操作:仅当参数值 = 1 时保留 1 行,如果参数值 > 1 则保留所有行。
我的参数名称是param_row_req
这是我当前的查询,
let
Source = table1,
#"Grouped Rows" = Table.Group(Source, {"Year", "Period"}, {{"EffDate", each List.Max([EffDate]), type nullable date}}),
#"Inserted Merged Column" = Table.AddColumn(#"Grouped Rows", "Merged", each Text.Combine({Text.From([Year], "en-GB"), Text.From([Period], "en-GB")}, ""), type text)
in
#"Inserted Merged Column"
作为最后一步,我该怎么做。
您可以使用 if
语句测试参数并相应地选择步骤
let
Source = table1,
#"Grouped Rows" = Table.Group(Source, {"Year", "Period"}, {{"EffDate", each List.Max([EffDate]), type nullable date}}),
KeepFirstRow = Table.FirstN(#"Grouped Rows",1),
Result = if param_row_req = 1 then KeepFirstRow else #"Grouped Rows"
in
Result
根据您的需要调整步骤
我想在我的查询中添加一个步骤,执行类似以下操作:仅当参数值 = 1 时保留 1 行,如果参数值 > 1 则保留所有行。
我的参数名称是param_row_req
这是我当前的查询,
let
Source = table1,
#"Grouped Rows" = Table.Group(Source, {"Year", "Period"}, {{"EffDate", each List.Max([EffDate]), type nullable date}}),
#"Inserted Merged Column" = Table.AddColumn(#"Grouped Rows", "Merged", each Text.Combine({Text.From([Year], "en-GB"), Text.From([Period], "en-GB")}, ""), type text)
in
#"Inserted Merged Column"
作为最后一步,我该怎么做。
您可以使用 if
语句测试参数并相应地选择步骤
let
Source = table1,
#"Grouped Rows" = Table.Group(Source, {"Year", "Period"}, {{"EffDate", each List.Max([EffDate]), type nullable date}}),
KeepFirstRow = Table.FirstN(#"Grouped Rows",1),
Result = if param_row_req = 1 then KeepFirstRow else #"Grouped Rows"
in
Result
根据您的需要调整步骤