Decrement/increment 在 DAX Power BI 中满足条件后自动排名

Decrement/increment rank automatically after condition is met in DAX Power BI

我有一个用 Power BI 编写的度量,如下所示,我根据新近度对日期进行排名,其中 1 将是最近日期的排名。 当有 2 个日期时,此度量给出正确的结果,但当有 3 个日期时,它始终将日期的引用保持为最小值,并执行下面的 calculation.Example

Snapshot Date   Overdue Total   Diff
5/09/2020       ,786         ,786
7/09/2020       ,434        -,352
9/09/2020       ,123         ,097 

有没有一种方法可以移动排名并在满足条件时将最短日期继续增加 1。这样我就得到了 Rank 1- Rank 2 ,然后是 Rank 2- Rank 3 等等。

Diff = 
VAR MAX_DATE=min('Account and SA'[Date Rank])

VAR PREV_VAL=
CALCULATE(
    sum('Account and SA'[Overdue(Total)]),
    FILTER(
        ALLSELECTED('Account and SA'),
        'Account and SA'[Date Rank] > MAX_DATE
    )
)

return
sum('Account and SA'[Overdue(Total)])-PREV_VAL

如果您正在寻找当前行过期与上一个可用日期的差异,您可以使用下面的 Measure-

Diff = 

VAR previous_date =
CALCULATE(
    MAX('Account and SA'[Snapshot Date]),
    FILTER(
        ALL('Account and SA'),
        'Account and SA'[Snapshot Date] < MIN('Account and SA'[Snapshot Date])
    )
)

VAR previous_date_overdue =
CALCULATE(
    MAX('Account and SA'[Overdue Total]),
    FILTER(
        ALL('Account and SA'),
        'Account and SA'[Snapshot Date] = previous_date 
    )
)

RETURN MIN('Account and SA'[Overdue Total]) - previous_date_overdue