我试图了解DAX如何转换数据以及如何使用它来让我在Power BI中紧凑地显示一些数据。
我的Regional Sales Performance
数据看起来像这样:
+---------------+----------------------+----------------------+-------------------+------------------+-----+
| Sales Month | Northeast Calls Made | Northeast Sales Made | Northeast Revenue | South Calls Made | ... |
+---------------+----------------------+----------------------+-------------------+------------------+-----+
| February 2017 | 15 | 13 | 3000.00 | 12 | ... |
+---------------+----------------------+----------------------+-------------------+------------------+-----+
| March 2017 | 21 | 9 | 2000.00 | 30 | ... |
+---------------+----------------------+----------------------+-------------------+------------------+-----+
| April 2017 | 5 | 5 | 1000.00 | 18 | ... |
+---------------+----------------------+----------------------+-------------------+------------------+-----+
最终,在过滤掉我的数据后(例如Sales Month = "February 2017"
),我希望显示如下:
+------------+-----------+-------+---------+------+
| | Northeast | South | Midwest | West |
+------------+-----------+-------+---------+------+
| Calls Made | 15 | 12 | ... | ... |
+------------+-----------+-------+---------+------+
| Sales Made | 13 | ... | ... | ... |
+------------+-----------+-------+---------+------+
| Revenue | 3000.00 | ... | ... | ... |
+------------+-----------+-------+---------+------+
由于我有一组已知的静态区域,我最好的猜测是创建一个DAX语句,每个区域有一个ROW()
联合在一起:
UNION(
ROW("Region", "Northeast", "Key", "Revenue", "Value", SUM('My Input')[Northeast Revenue], ...),
ROW("Region", "Northeast", "Key", "Sales", "Value", SUM('My Input')[Northeast Sales Made], ...),
ROW("Region", "South", "Key", "Revenue", "Value", SUM('My Input')[South Revenue], ...),
ROW("Region", "South", "Key", "Sales", "Value", SUM('My Input')[South Sales Made], ...),
ROW("Region", "Midwest", "Key", "Revenue", "Value", SUM('My Input')[Midwest Revenue], ...),
ROW("Region", "Midwest", "Key", "Sales", "Value", SUM('My Input')[Midwest Sales Made], ...)
)
这或多或少有效,但看起来非常单一,并且它不会保留列类型。例如,电话和销售是整数;收入是固定宽度的小数;其他列可能是百分比。
有更好的方法吗?
答案 0 :(得分:1)
是的,有!有' unpivot'查询编辑器的“变换”选项卡中的选项。在那里,您可以取消数据。
我已经使用您的数据创建了一个示例:
链接到PBIX,因此您可以看到我在查询编辑器中执行的步骤。 Link