通过条件和顺序获得最高价值

时间:2019-06-26 02:55:13

标签: filter max powerbi dax rank

我正在尝试在Power BI中使用多个条件和顺序来计算最大值。

我已经调用了该函数来创建一个按Year,Branch,Group和Type Disonsidering Company排在前1位的列。

TOP1 = CALCULATE(MAX(data[Value]);
      FILTER(ALLEXCEPT(data;data[Company];
      data[Year] = data[Year] 
      && data[Branch] = data_segmento_anual[Branch]
      && data_segmento_anual[Group] = data_segmento_anual[Group]
      && data_segmento_anual[Bond] = data_segmento_anual[Bond]
      && data_segmento_anual[Type] = data_segmento_anual[Type]))

然后结果:

YEAR    COMPANY         BRANCH  GROUP     Value     TOP1
2016    BANCO DO BRASIL RISK    RETAIL    4061567   4061567
2016    BANCO DO BRASIL ACUM    RETAIL    1901920   1901920
2017    BANCO DO BRASIL RISK    CORPORATE 439499    439499
2017    BANCO DO BRASIL RISK    RETAIL    356231    356231
2016    BRADESCO        RISK    CORPORATE 347369    347369
2016    BANCO DO BRASIL RISK    RETAIL    310920    4061567
2016    BANCO DO BRASIL ACUM    CORPORATE 12091     12091
2016    BANCO DO BRASIL RISK    RETAIL    1021      4061567
2017    BANCO DO BRASIL RISK    CORPORATE 446       439499

但是我想插入另一列,该列将是第二,第三,第五个……更大的值,依此类推。结果将是:

YEAR    COMPANY         BRANCH  GROUP     Value   TOP1    TOP2
2016    BANCO DO BRASIL RISK    RETAIL    4061567 4061567 310920
2016    BANCO DO BRASIL ACUM    RETAIL    1901920 1901920 NA
2017    BANCO DO BRASIL RISK    CORPORATE 439499  439499  446
2017    BANCO DO BRASIL RISK    RETAIL    356231  356231  NA
2016    BRADESCO        RISK    CORPORATE 347369  347369  NA
2016    BANCO DO BRASIL RISK    RETAIL    310920  4061567 310920
2016    BANCO DO BRASIL ACUM    CORPORATE 12091   12091   NA
2016    BANCO DO BRASIL RISK    RETAIL    1021    4061567 310920
2017    BANCO DO BRASIL RISK    CORPORATE 446     439499  446

1 个答案:

答案 0 :(得分:1)

您可以在计算列中使用Earlier()函数来引用当前行的值。

查看以下两个计算列如何满足您的要求(您将需要更改名称以适合您的数据集):

V2 = CALCULATE(max(Test[V1]),
FILTER(all(Test),
Test[V1] < earlier(Test[V1]) 
&& EARLIER(Test[C2]) = Test[C2] 
&& EARLIER(Test[C3]) = Test[C3]))

_

V3 = CALCULATE(max(Test[V2]),
FILTER(all(Test),
Test[V2] < earlier(Test[V2]) 
&& EARLIER(Test[C2]) = Test[C2] 
&& EARLIER(Test[C3]) = Test[C3]))

Example