我目前正在创建一个带有三个参数的自定义函数:
此函数的目的是按标记为“Appl Nbr”的列对表 report 进行分组,然后计算指定 字段的最大值,将结果放入名为 columnNewName 的新列中。 我会喜欢将此自定义函数复制到多个表中:
但是,我遇到了以下代码片段的问题:
(report as table, field as text, columnNewName as text) =>
let
Source = report,
SelectedField = Table.SelectColumns(Source, field),
#"Grouped Rows" = Table.Group(Source, {"Appl Nbr"}, {{columnNewName, each List.Max(SelectedField), type nullable number}})
in
#"Grouped Rows"
如果我将 SelectedField 替换为“天数”,它会起作用:
(report as table, field as text, columnNewName as text) =>
let
Source = report,
SelectedField = Table.SelectColumns(Table1, "No. of Days"),
#"Grouped Rows" = Table.Group(Source, {"Appl Nbr"}, {{columnNewName, each List.Max([No. of Days]), type nullable number}})
in
#"Grouped Rows"
我附上了下表:
表1:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFDSUTI0BRKheZklqSkKwSWJJanFQL5vZnJGYmqOQnByfkmJUqwOQjWYdCtKzEtOxa8OSLinFuUm5lUCWT6lKeWZ6QpOqaklGfllqXlQpaZwpegOQOVDVJuDXGqMzbloqmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Appl Nbr" = _t, #"No. of Days" = _t, Country = _t, Name = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Appl Nbr", Int64.Type}, {"No. of Days", Int64.Type}, {"Country", type text}, {"Name", type text}})
in
#"Changed Type"
表2
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFDSUTIC4tC8zJLUFIXgksSS1GIg3zczOSMxNUchODm/pEQpVgeu2BCI3YoS85JT8akyAWL31KLcxLxKIMunNKU8M13BKTW1JCO/LDVPKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Appl Nbr" = _t, #"No. of Weeks" = _t, Country = _t, Name = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Appl Nbr", Int64.Type}, {"No. of Weeks", Int64.Type}, {"Country", type text}, {"Name", type text}})
in
#"Changed Type"
(report as table, field as text, columnNewName as text) =>
let
#"Grouped Rows" = Table.Group(report, {"Appl Nbr"}, {{columnNewName, (x)=> List.Max( Table.Column(x, field)), type nullable number}})
in
#"Grouped Rows"