Forum Discussion
Calculate difference between values per category at irregularly spaced dates
- 6 years ago
Hi Anonymous ,
We can create measure use following formula to meet your requirement:
LastChange = VAR LastDay = MAX ( 'Table'[Date] ) VAR LastTwoday = CALCULATE ( MAX ( 'Table'[Date] ), FILTER ( 'Table', [Date] < LastDay ) ) RETURN CALCULATE ( SUM ( 'Table'[MyValue] ), FILTER ( 'Table', 'Table'[Date] = LastDay ) ) - CALCULATE ( SUM ( 'Table'[MyValue] ), FILTER ( 'Table', 'Table'[Date] = LastTwoday ) )If use your index column, this formula can be more easier:
LastChangeUseIndex = CALCULATE ( SUM ( 'Table'[MyValue] ), FILTER ( 'Table', 'Table'[IndexCategory] = MAX ( 'Table'[IndexCategory] ) ) ) - CALCULATE ( SUM ( 'Table'[MyValue] ), FILTER ( 'Table', 'Table'[IndexCategory] = MAX ( 'Table'[IndexCategory] ) - 1 ) )
BTW, pbix as attached.Best regards,
Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous ,
We can create measure use following formula to meet your requirement:
LastChange =
VAR LastDay =
MAX ( 'Table'[Date] )
VAR LastTwoday =
CALCULATE ( MAX ( 'Table'[Date] ), FILTER ( 'Table', [Date] < LastDay ) )
RETURN
CALCULATE (
SUM ( 'Table'[MyValue] ),
FILTER ( 'Table', 'Table'[Date] = LastDay )
)
- CALCULATE (
SUM ( 'Table'[MyValue] ),
FILTER ( 'Table', 'Table'[Date] = LastTwoday )
)If use your index column, this formula can be more easier:
LastChangeUseIndex =
CALCULATE (
SUM ( 'Table'[MyValue] ),
FILTER ( 'Table', 'Table'[IndexCategory] = MAX ( 'Table'[IndexCategory] ) )
)
- CALCULATE (
SUM ( 'Table'[MyValue] ),
FILTER ( 'Table', 'Table'[IndexCategory] = MAX ( 'Table'[IndexCategory] ) - 1 )
)
BTW, pbix as attached.
Best regards,
Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi lc_finance & v-lid-msft ,
Thank you both so much for the explanations and example files! You helped immensily :smileyhappy:
- lc_finance6 years agoSolution Sage
Hi Anonymous ,
I'm very glad it helped you!
Best of luck for your analysis
LC