[英]Using RANKX in PowerBI DAX
I am a PowerBI newbie and I have been playing with DAX functions, more specifically, the RANKX function. 我是PowerBI新手,并且一直在使用DAX功能,更具体地说是RANKX功能。 Here is my data set: 这是我的数据集:
+----------+-------------------------------------+-----------------+----------+
| Category | Sub Category | Date | My Value |
+----------+-------------------------------------+-----------------+----------+
| A | A1 | 2018-01-01 | 2 |
| A | A2 | 2018-01-02 | 4 |
| A | A3 | 2018-01-03 | 6 |
| A | A4 | 2018-01-04 | 6 |
| B | B1 | 2018-01-05 | 21 |
| B | B2 | 2018-01-06 | 22 |
| B | B2 | 2018-01-07 | 23 |
| C | C1 | 2018-01-08 | 35 |
| C | C2 | 2018-01-09 | 35 |
| C | C3 | 2018-01-10 | 35 |
+----------+-------------------------------------+-----------------+----------+
And below is my code: 下面是我的代码:
Rank all rows as Column =
RANKX(
'Table',
'Table'[My Value]
)
Unfortunately, I am getting the following error: 不幸的是,我收到以下错误:
A single value for column 'My Value' in table 'Table' cannot be determined. 无法确定表“表”中“我的值”列的单个值。 This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result. 当度量公式引用包含许多值的列而未指定汇总(例如最小值,最大值,计数或总和)以获得单个结果时,可能会发生这种情况。
Any help would be greatly appreciated. 任何帮助将不胜感激。
Thanks 谢谢
Create a mesure to sum "My value" column: 创建一个确定以总结“我的价值”列:
Sum value = SUM(Table[My value])
Then use this measure to get your rank: 然后使用此度量获取您的排名:
Rank all rows as Column =
RANKX(ALL(Table);[Sum value])
This will give you the rank of each sub category. 这将为您提供每个子类别的排名。
There is nothing wrong with your formula, you just put it in a wrong place. 您的公式没有错,只是将其放在错误的位置。
There are 2 ways you can write DAX formulas in PowerBI: 您可以通过两种方法在PowerBI中编写DAX公式:
The difference is critical, you need to learn it if you want to use PowerBI. 区别至关重要,如果要使用PowerBI,则需要学习它。
The formula you wrote is for calculated columns. 您编写的公式适用于计算列。 If you create it as a measure, you will get an error. 如果将其创建为度量,则会出现错误。 To fix the problem, go to tab "Model", click "New Column", paste your code and it should work. 要解决此问题,请转到“模型”选项卡,单击“新建列”,粘贴您的代码,它应该可以工作。
If you need RANKX as a measure, Chrisoffer has given you a good answer. 如果您需要RANKX作为衡量标准,Chrisoffer会给您一个很好的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.