PowerBI: how do you calculate the difference between two columns in matrix

耗尽温柔 提交于 2019-12-02 06:27:34

问题


I have a matrix defined as the values :

I wanted to run a difference between the values that is seen on each date from Baseline and Scenario1 (it can be more than 2) So the columns are defined as : (1) Date (2) Type

So the difference is from Baseline for each Date much as what we do in Calculation - Difference in Excel or Tablaeu

Does anybody have any materials where I can follow through? I have the following DAX but it does not give me the result I expect :

Diff = 
VAR currIndexDate = MIN (Date [TotalRundate]) 
VAR currIndexType = "Scenario1" 

var currVolume = 
CALCULATE ( SUM (Data[TotalVolume]), 
      FILTER( ALLSELECTED (Data) , Data[TotalRunDate] = currIndexDate && Date[Type] = currIndexType ),
      VALUES (Data[Type]), VALUES (Data[TotalRunDate])
)
var prevVolume = 
CALCULATE ( SUM (Data[TotalVolume]), 
      FILTER( ALLSELECTED (Data) , Data[TotalRunDate] = currIndexDate && Date[Type] <> currIndexType ),
      VALUES (Data[Type]), VALUES (Data[TotalRunDate])
)
RETURN 
IF (prevVolume <> BLANK , currVolume - prevVolume, currVolume)

Here is the result that I am getting which sums everything and not within the same grouping of Data[Type] Data[TotalRunDate]

What I want to accomplish is this type: (which is the Difference Calculation in Excel)


回答1:


My understanding: Show difference between column-header Type and Type=Baseline, without affecting any other context.

Volume = SUM ( 'Data'[TotalVolume] )
Diff from Baseline =
[Volume] - CALCULATE ( [Volume], 'Data'[Type] = "Baseline" )

You don't need to do anything special to preserve filtering context. Just use CALCULATE to change the bit of context you care about.



来源:https://stackoverflow.com/questions/56729037/powerbi-how-do-you-calculate-the-difference-between-two-columns-in-matrix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!