Forum Discussion
Anonymous
6 years agoNot applicable
DAX Substract values in same column based on key
Hi, I'm trying to calculate daily increments of a value for each ID and timestamp. This is my as-is situation sample: ID timestamp value key01 20191101 150 key01 20191031 135 key0...
- 6 years ago
Hi Anonymous
Try something like this.
Column = VAR __timeStamp = 'Table'[timestamp] VAR __previousDate = CALCULATE( MAX( 'Table'[timestamp] ), ALLEXCEPT( 'Table', 'Table'[ID] ), 'Table'[timestamp] < __timeStamp ) VAR __previousValue = CALCULATE( SUM( 'Table'[value] ), TREATAS( { __previousDate }, 'Table'[timestamp] ), ALLEXCEPT( 'Table', 'Table'[ID] ) ) RETURN IF( __previousValue > 0, 'Table'[value] - __previousValue )Best Regards,
Mariusz
If this post helps, then please consider Accepting it as the solution.
Mariusz
Community Champion
6 years agoHi Anonymous
Try something like this.
Column =
VAR __timeStamp = 'Table'[timestamp]
VAR __previousDate =
CALCULATE(
MAX( 'Table'[timestamp] ),
ALLEXCEPT( 'Table', 'Table'[ID] ),
'Table'[timestamp] < __timeStamp
)
VAR __previousValue =
CALCULATE(
SUM( 'Table'[value] ),
TREATAS( { __previousDate }, 'Table'[timestamp] ),
ALLEXCEPT( 'Table', 'Table'[ID] )
)
RETURN IF( __previousValue > 0, 'Table'[value] - __previousValue )
Best Regards,
Mariusz
If this post helps, then please consider Accepting it as the solution.
Mariusz
If this post helps, then please consider Accepting it as the solution.