首页 > 解决方案 > Power BI 计算多级矩阵中两列之间的差异

问题描述

这是源数据:

https://i.stack.imgur.com/raYom.png

列:[版本、单位、客户、季度、销售额)

以下是潜在价值:

https://i.stack.imgur.com/REmnV.png

*注意:我们可能有 10 种不同的版本和 20 多种不同的季度组合。

这是 Power BI 中的输出矩阵:

https://i.stack.imgur.com/FA1UE.png

*用户可以选择一个版本和两个季度进行比较。

以下是 Power BI 可视化和字段:

https://i.stack.imgur.com/VWd5A.png

我想创建一个度量来计算版本 1 和 2 之间的差异,如下所示(E 列和 H 列):

https://i.stack.imgur.com/yWRQx.png

我可以创建一个新表,其中包含版本 1、2、3 的销售列,然后计算差异。问题是我需要版本和季度是动态的。任何想法如何在 Power BI 中执行此操作?

标签: powerbidaxdashboardpowerbi-desktop

解决方案


You can do something like

    Delta = IF (HASONEVALUE('Table'[Version]),
                   SUM('Table'[Sales]), 
                    CALCULATE(sum('Table'[Sales]), LASTNONBLANK('Table'[Version], sum('Table'[Sales]))) 
                  - CALCULATE(sum('Table'[Sales]), FIRSTNONBLANK('Table'[Version], sum('Table'[Sales])))
)

So whenever you have two versions in the filter context, it subtracts the first from the last, and whenever only one version is in the filter context, it passes the value through.


推荐阅读