Forum Discussion
Create date difference value column ?
- 4 years ago
Hi Anonymous
Try this code to add a new column :
Column = VAR _CD = 'Table'[Date] VAR _YD = CALCULATE ( MAX ( 'Table'[Date] ), FILTER ( ALL ( 'Table' ), 'Table'[Date] < _CD && 'Table'[Country/Region] = EARLIER ( 'Table'[Country/Region] ) ) ) VAR _YDV = CALCULATE ( MAX ( 'Table'[Deaths] ), FILTER ( ALL ( 'Table' ), 'Table'[Date] = _YD && 'Table'[Country/Region] = EARLIER ( 'Table'[Country/Region] ) ) ) RETURN IF ( ISBLANK ( _YD ), 0, 'Table'[Deaths] - _YDV )output:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: www.linkedin.com/in/vahid-dm/
If you want to do this in the query editor, have a look at my previous solution here:
https://community.powerbi.com/t5/Power-Query/Optimize-performance-at-Un-Cumulate-calculation/m-p/2194983#M64867
You may want to review this simpler case explained with more detail first:
https://community.powerbi.com/t5/Desktop/Calculating-Daily-values-from-Cumulative-Total/m-p/2198969
Hello,
Your solution might not work as we have to take the country into the account as well.
thanks
- AlexisOlson4 years agoSuper User
The first one I linked to does handle this. The second one is the simpler example that does not.
- Anonymous4 years agoNot applicable
Sure thanks, will take a look.