Forum Discussion
Complex cumulative calculation
Hi Guys, need your help with the following calculation:
Each cumulative sum in a certain month needs to be divided by a certain regular sum from the month before. is that possible?
7 Replies
- vanessafvgCommunity Champion
I think you might be able to use the earlier function to get the desired result
- amitchandakSuper User
DenisStyrt , if it is column try These two columns
Last Date = maxx(filter(Table,[date]<earlier[date]),[date])
diff = [cummaltive measure] - maxx(filter(Table,[date]=earlier[Last Date]),[cummaltive measure] )if measure , join date with date table and then try
measure =
[cummaltive measure] - CALCULATE([cummaltive measure] ,filter(all('Date'),'Date'[Date] =MAXX(FILTER(all('Date'),'Date'[Date]<max('Date'[Date])),Table['Date'])))To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/
See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184
Appreciate your Kudos.- DenisStyrtHelper II
Unfortunately, I get Infinity when I use this formula.
- v-yingjlCommunity Support
Hi DenisStyrt ,
Have you tried my sample file? Or could you please consider sharing your .pbix file or some screenshots for further discussion?
Best Regards,
Yingjie Li
- v-yingjlCommunity Support
Hi DenisStyrt ,
To solve this issue, you can create a index column in power query editor first:
If Cumulative measure and Sum measure are columns, you can create a calculate column by this formula:
Column = VAR _index = 'Table'[Index] VAR _sum = CALCULATE ( MAX ( 'Table'[Sum] ), FILTER ( ALL ( 'Table' ), 'Table'[Index] = _index + 1 ) ) RETURN DIVIDE ( 'Table'[Cumulative], _sum, BLANK () )If both of them are measures, you can create another measure by this formula:
Measure = VAR _index = SELECTEDVALUE ( 'Table'[Index] ) VAR _cum = SELECTEDVALUE ( 'Table'[Cumulative] ) VAR _sum = CALCULATE ( [Sum measure], FILTER ( ALL ( 'Table' ), 'Table'[Index] = _index + 1 ) ) RETURN DIVIDE ( [Cumulative measure], _sum, BLANK () )My sample file attached that hopes to help you, please check and try it: Complex cumulative calculation.pbix
Best Regards,
Yingjie LiIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.