问题
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