嗨,我有一个PowerBI报告,它有1个静态列Object1和Value' s作为动态列。我想添加一个计算列来计算最后两列之间的差异,这是为了计算上个月销售额的增长。知道如何使用DAX或Power Query在PowerBI中完成这项工作吗?感谢
答案 0 :(得分:1)
这有点笨拙,但我认为它能满足您的需求。
#"Unpivoted Columns" = Table.UnpivotOtherColumns(PreviousStepNameHere, {"Object1"}, "Attribute", "Value"),
#"Filtered Last 2" = Table.SelectRows(#"Unpivoted Columns", each List.Contains(List.LastN(#"Unpivoted Columns"[Attribute], 2), [Attribute])),
#"Added Custom" = Table.AddColumn(#"Filtered Last 2", "Custom", each if List.Contains(List.LastN(#"Unpivoted Columns"[Attribute], 1), [Attribute]) then [Value] else -[Value]),
#"Grouped Rows" = Table.Group(#"Added Custom", {"Object1"}, {{"Value", each List.Sum([Custom]), type number}}),
#"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Attribute", each "Calculated_Column_Difference_Last2_Columns"),
#"Appended Query" = Table.Combine({#"Unpivoted Columns", #"Added Custom1"}),
#"Pivoted Column" = Table.Pivot(#"Appended Query", List.Distinct(#"Appended Query"[Attribute]), "Attribute", "Value")
Unpivot应保留列顺序。您过滤最后两个并将第2个符号切换为最后一个,以便在分组和求和时获得差异。将所需的列名称添加为名为Attribute
的自定义列。将其附加到原始的未转换表中,然后重新转动。