如何从power行中减去前一行的当前行等等

时间:2017-05-22 11:01:03

标签: powerbi

我有一个计算表,其中包含以下字段。

Year          Revenue
2005          200
2006          300
2007          400
2008          300

上表是根据以下DAX生成的

revenue_summary = SUMMARIZE('WA_Retail-SalesMarketing_-ProfitCost',[Year],"Total Revenue",SUM('WA_Retail-SalesMarketing_-ProfitCost'[Revenue]))

我的desrired表将是

Year          Revenue       Differrence
2005          200           0
2006          300           (300-200)= 100
2007          400           (400-300)=100
2008          300           (300-400)=-100

我如何实现这种力量BI?

1 个答案:

答案 0 :(得分:1)

Difference = 
  var curYear = MyTable[year] 
  var curVal = MyTable[value]
  var oldYear = MyTable[year]-1
  var oldVal = CALCULATE(
    FIRSTNONBLANK(MyTable[value],1),
    FILTER(MyTable, 
    MyTable[year]=oldYear))
  return IF(CONTAINS(MyTable,MyTable[year],oldYear), curVal-oldVal, 0)

结果:

Year          Revenue       Differrence
2005          200           0
2006          300           100
2007          400           100
2008          300          -100