答案 0 :(得分:0)
您可以通过在该行的当前行日期之前的最后一个日期查找该类别值来添加自定义列以计算比较量。删除Volume
列,将CalcType
从“ Individual”重命名为“ Comparison”,然后将该表追加到原始表中。
这是M代码的样子。
let
Source = <Insert Source Here>,
#"Changed Type" = Table.TransformColumnTypes(Source,
{{"Date", type date}, {"Category", type text},
{"CalcType", type text}, {"Volume", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Comparison", each
try Table.Max(Table.SelectRows(#"Changed Type",
(C) => C[Date] < [Date] and C[Category] = [Category]), "Date")[Volume]
otherwise null, Int64.Type),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Volume"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Comparison","Volume"}}),
#"Replaced Value" = Table.ReplaceValue(#"Renamed Columns",
"Individual","Comparison",Replacer.ReplaceText,{"CalcType"}),
#"Filtered Rows" = Table.SelectRows(#"Replaced Value", each ([Volume] <> null)),
#"Appended Query" = Table.Combine({#"Changed Type", #"Filtered Rows"})
in
#"Appended Query"