本文介绍了DAX-获取当前行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题似乎很简单,但是我发现用DAX确实很难做到.我想在当前上下文数据中获取当前行号.与T-SQL中的ROW_NUMBER()相同.

The question seems to be easy but I found it really hard to be done in DAX.I'd like to get the current row number on my current context data. Same as ROW_NUMBER() in T-SQL.

有任何提示吗?

谢谢.

推荐答案

没有此类功能.最接近的是根据排序顺序来计算排名,例如:

There is no such function. Closest you can get is to calculate rank based on sort-order, like:

DEFINE MEASURE SomeTbl[ROW_NO] = SUMX(SomeTbl, RANKX(ALL(SomeTbl), SomeTbl[SortCol]))
EVALUATE ADDCOLUMNS(SomeTbl, "ROW_NO", SomeTbl[ROW_NO])

或者如果您不能使用 RANKX

EVALUATE ADDCOLUMNS (
  SomeTbl, "ROW_NO", COUNTROWS(FILTER(SomeTbl,
    EARLIER(SomeTbl[SortCol])<=SomeTbl[SortCol]))+0
)

注意:对于相同的值( SomeTbl [SortCol] ), ROW_NO 将相同.

Note: for same values (of SomeTbl[SortCol]) the ROW_NO will be the same.

如果您使用的是DirectQuery模式,则还可以在模型中添加额外的列,并将其定义为 SELECT *,... ROW_NUMBER()as Foo -并使用 Foo DAX中的列.

If you're using DirectQuery mode you can also in model add extra column and define it likeSELECT *, ... ROW_NUMBER() as Foo - and use Foo column in DAX instead.

这篇关于DAX-获取当前行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 16:26