我有一个计算表,其中包含以下字段。
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?
答案 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