Forum Discussion
Calculate the difference between two columns in matrix
- 7 years ago
Day has to be numeric for this
as you want to have Measures in rows you actually will need a new table for that, you can create one in DAXRowLabels = UNION(ROW("Column","Amount"),ROW("Column","Difference"))then this measure will work
Measure = VAR __Amount = SUM('Table'[Amount]) VAR __DayIndex = MAX('Table'[Day]) VAR __CurrentDay = CALCULATE(SUM('Table'[Amount]),'Table'[Day]=__DayIndex) VAR __PreviousDay = CALCULATE(SUM('Table'[Amount]),'Table'[Day]=__DayIndex-1) VAR __Difference = DIVIDE(__CurrentDay-__PreviousDay,__PreviousDay) VAR __RowLabel = SELECTEDVALUE(RowLabels[Column]) RETURN SWITCH(__RowLabel, "Amount", __Amount, "Difference", __Difference, BLANK() ) - 7 years ago
Here DayIndex-1 is throwing error , I think for the very first index its giving -ve index which is not there.
VAR __PreviousDay = CALCULATE(SUM('Table'[Amount]),'Table'[Day]=__DayIndex-1)Kindly share how to handle that because PreviousDay value for first index i want as blank and same for difference column as well. For fisrt Day difference should come as blank
- Anonymous7 years ago
Hi,
Below is the solution screenshot for your requirement.
Click Here to download the sample application.
Hope it help you.
Regards,
Pavan Vanguri.
Hi I have data format something like this.
User Day Amount
U1 Day0 1000
U2 Day2 3000
U2 Day1 234
U3 Day0 345
Day has to be numeric for this
as you want to have Measures in rows you actually will need a new table for that, you can create one in DAX
RowLabels = UNION(ROW("Column","Amount"),ROW("Column","Difference"))then this measure will work
Measure =
VAR __Amount = SUM('Table'[Amount])
VAR __DayIndex = MAX('Table'[Day])
VAR __CurrentDay = CALCULATE(SUM('Table'[Amount]),'Table'[Day]=__DayIndex)
VAR __PreviousDay = CALCULATE(SUM('Table'[Amount]),'Table'[Day]=__DayIndex-1)
VAR __Difference = DIVIDE(__CurrentDay-__PreviousDay,__PreviousDay)
VAR __RowLabel = SELECTEDVALUE(RowLabels[Column])
RETURN
SWITCH(__RowLabel,
"Amount", __Amount,
"Difference", __Difference,
BLANK()
)- shibabrata277 years agoFrequent Visitor
Here DayIndex-1 is throwing error , I think for the very first index its giving -ve index which is not there.
VAR __PreviousDay = CALCULATE(SUM('Table'[Amount]),'Table'[Day]=__DayIndex-1)Kindly share how to handle that because PreviousDay value for first index i want as blank and same for difference column as well. For fisrt Day difference should come as blank