使用“DAX"为描述性数据创建索引列在 Power BI 中
我有一张这样的桌子,
Table1
ColA ColB
Orange Apple
Mango Not Apple
Mango Not Apple
我想使用 DAX 而不是查询编辑器 (M) 创建一个名为 RowNumber 的列.
I want to create a column called as RowNumber using DAX and not Query Editor (M).
所以预期输出是,
ColA ColB RowNumber
Orange Apple 1
Mango Not Apple 2
Mango Not Apple 3
这可以在 M - Power Query Side 中完成.
This can be done in M - Power Query Side.
但是,我正在寻找使用 DAX 计算列的解决方案.
But, I am looking for a solution using DAX- Calculated Column.
我希望像 RowNumber (T-SQL) 或 Index 这样的函数出现在 DAX 中.
I expected functions like RowNumber (T-SQL) or Index to be present inside DAX.
如果您需要在 DAX 中创建索引,您可以使用以下公式:
If you need to create an Index in DAX you can use this formula:
Index = RANKX(ALL(Barges),Barges[Date],,ASC)
RANKX:创建您的指数值
RANKX: create your Index values
ALL:如果您有任何过滤器,则避免部分生成您的索引
ALL: to avoid your Index to be partially generated if you have any filter
第二个参数是您想要对数据进行排序的位置,在我的示例中,我有一个索引号,我的日期按升序递增,如果我使用 Barges[name] 代替例如我将生成索引对我的驳船名称进行 AZ 排序.
The second parameter is from where you want to sort your data, in my example I have an Index number increasing with an ascending order on my date, if I use Barges[name] instead for example I'll have my index generating with an A-Z sorting on my barges names.