使用“DAX"为描述性数据创建索引列在 Power BI 中 [英] Creating an Index Column for a Descriptive Data Using "DAX" in Power BI

查看:76
本文介绍了使用“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.

这篇关于使用“DAX"为描述性数据创建索引列在 Power BI 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆