Dax 中的行号
Row number in Dax
我有以下 DAX 代码。我需要自动递增行号,其中 FileNo 和 CI_No 代码相同。我厌倦了 RANKX 函数,但它 return 在所有记录中排名为 1。任何人都知道我们如何使用 DAX 实现这一目标。
提前致谢。
Dax代码:
DEFINE
VAR A = UNION( ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 20, "CI_No", 201, "Amount" ,200)
,ROW ("FileNo", 20, "CI_No", 201, "Amount" ,200)
,ROW ("FileNo", 20, "CI_No", 301, "Amount" ,300))
VAR B= ADDCOLUMNS(A,
"RowNo", RANKX(
FILTER(A,
[FileNo]=EARLIER([FileNo]) && [CI_No]=EARLIER([CI_No])
),
[Amount], , DESC
) )
EVALUATE B
预期结果
您可以尝试混合使用 AddIndexColumn(来自 TransformData)和新的计算列:
RowNo =
RANKX(
FILTER( ALLEXCEPT('sample','sample'[RowNo]) , [FileNo] = EARLIER('sample'[FileNo]) && [CL_No] = EARLIER('sample'[CL_No]) ),
[DummySum], , DESC
)
DummySum = sum('sample'[索引])
编辑:
Table = VAR A = ADDCOLUMNS(UNION( ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 20, "CI_No", 201, "Amount" ,200)
,ROW ("FileNo", 20, "CI_No", 201, "Amount" ,200)
,ROW ("FileNo", 20, "CI_No", 301, "Amount" ,300)), "Index", [Amount]+RAND())
VAR B= ADDCOLUMNS(A,
"RowNo", RANKX(
FILTER(A,
[FileNo]=EARLIER([FileNo]) && [CI_No]=EARLIER([CI_No])
),
[Index], , DESC
) )
return B
我有以下 DAX 代码。我需要自动递增行号,其中 FileNo 和 CI_No 代码相同。我厌倦了 RANKX 函数,但它 return 在所有记录中排名为 1。任何人都知道我们如何使用 DAX 实现这一目标。
提前致谢。
Dax代码:
DEFINE
VAR A = UNION( ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 20, "CI_No", 201, "Amount" ,200)
,ROW ("FileNo", 20, "CI_No", 201, "Amount" ,200)
,ROW ("FileNo", 20, "CI_No", 301, "Amount" ,300))
VAR B= ADDCOLUMNS(A,
"RowNo", RANKX(
FILTER(A,
[FileNo]=EARLIER([FileNo]) && [CI_No]=EARLIER([CI_No])
),
[Amount], , DESC
) )
EVALUATE B
预期结果
您可以尝试混合使用 AddIndexColumn(来自 TransformData)和新的计算列:
RowNo =
RANKX(
FILTER( ALLEXCEPT('sample','sample'[RowNo]) , [FileNo] = EARLIER('sample'[FileNo]) && [CL_No] = EARLIER('sample'[CL_No]) ),
[DummySum], , DESC
)
DummySum = sum('sample'[索引])
编辑:
Table = VAR A = ADDCOLUMNS(UNION( ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 10, "CI_No", 101, "Amount" ,100)
,ROW ("FileNo", 20, "CI_No", 201, "Amount" ,200)
,ROW ("FileNo", 20, "CI_No", 201, "Amount" ,200)
,ROW ("FileNo", 20, "CI_No", 301, "Amount" ,300)), "Index", [Amount]+RAND())
VAR B= ADDCOLUMNS(A,
"RowNo", RANKX(
FILTER(A,
[FileNo]=EARLIER([FileNo]) && [CI_No]=EARLIER([CI_No])
),
[Index], , DESC
) )
return B