【问题标题】:QoQ Calculation Power BI环比计算 Power BI
【发布时间】:2021-12-15 10:09:07
【问题描述】:

我在下面的数据表中计算 QoQ Imp 和 QoQ %Eng,这些数据表是通过添加“从 0 开始的索引”和“从 1 开始的 Index.1”来分组的。

我在此视觉对象的“过滤器”窗格中有一个“过滤器”列。请帮助我计算上表 A 中的 QoQ Imp 和 QoQ %Eng。预期结果/输出应如下表所示:-

【问题讨论】:

  • 这些计算的逻辑是什么?

标签: powerbi dax powerquery


【解决方案1】:

在 Power Query(M 代码)中,假设您的数据具有代表性,您可以在过滤/分组等之前计算 QoQ 值。

  • 在显示时添加索引列
  • 然后添加一个模数列(值 = 4,因为您有四个季度)
  • 然后为您的两个计算添加自定义列:

  • 然后根据需要过滤

这是假设数据源是 Excel 表的 M 代码。根据需要修改 Source 行

let
    Source = Excel.CurrentWorkbook(){[Name="Table7"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Qtr", type text}, {"Filter", type text}, {"Imp", Int64.Type}, {"Eng", Int64.Type}}),

//Compute % Eng column
    #"Added Custom" = Table.AddColumn(#"Changed Type", "% Eng", each [Eng]/[Imp], Percentage.Type),

//Add Index and Modulo columns
    #"Added Index" = Table.AddIndexColumn(#"Added Custom", "Index", 0, 1, Int64.Type),
    #"Inserted Modulo" = Table.AddColumn(#"Added Index", "Modulo", each Number.Mod([Index], 4), type number),
 
 //Compute QOQs -- (current row - previous row)/previous row (unless first row in the group in which case => null
    #"Added Custom1" = Table.AddColumn(#"Inserted Modulo", "QoQ Imp", each if [Modulo]=0 then null
        else ([Imp] - #"Inserted Modulo"[Imp]{[Index]-1}) / #"Inserted Modulo"[Imp]{[Index]-1}),
 
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "QoQ %Eng", each if [Modulo]=0 then null
        else ([#"% Eng"] - #"Inserted Modulo"[#"% Eng"]{[Index]-1}) / #"Inserted Modulo"[#"% Eng"]{[Index]-1}),

//remove now superfluous Index and Modulo columns and re-order the others
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"Index", "Modulo"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Qtr", "Filter", "Imp", "QoQ Imp", "Eng", "% Eng", "QoQ %Eng"})
in
    #"Reordered Columns"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-05
    • 1970-01-01
    • 2020-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多