powerbi - Power BI 计算多级矩阵中两列之间的差异
问题描述
这是源数据:
列:[版本、单位、客户、季度、销售额)
以下是潜在价值:
*注意:我们可能有 10 种不同的版本和 20 多种不同的季度组合。
这是 Power BI 中的输出矩阵:
*用户可以选择一个版本和两个季度进行比较。
以下是 Power BI 可视化和字段:
我想创建一个度量来计算版本 1 和 2 之间的差异,如下所示(E 列和 H 列):
我可以创建一个新表,其中包含版本 1、2、3 的销售列,然后计算差异。问题是我需要版本和季度是动态的。任何想法如何在 Power BI 中执行此操作?
解决方案
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.
推荐阅读
- reactjs - 对象作为反应子无效(react-native)
- interrupt - STM32 SPI在使用中断时丢弃数据
- php - 在woocommerce中将任何产品添加到购物车后,如何立即删除客户端浏览器上的“PHPSESSID”cookie?
- swift - Swift 和 Cloud Firestore 事务 - getDocuments?
- java - Hibernate Envers - 请求更改对象列表
- c++ - c++ 中的汇编内联(float 和 _cdecl)
- javascript - 诗浓中的 spyOn.and.callFake 是什么?
- python-2.7 - Python MySQLdb 打印表 A 中不在表 B 中的行
- spring-boot-admin - 需要更新 Spring-boot-admin UI url
- c - 如何为 print() 编写 Python 包装器?