Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Mariam1991
Helper II
Helper II

cumulative sum

HI everyone;

i want to calculate cumulative sum of sales but when i change the date as a filter doesn't take it in consideration  like if  i chose 2017 in the filter , cumulative sums doesn't calculate correctly even more if i chose other filter like agency 

cumulative_sum= calculate(sum(tableA[sales]);filter(all(table A);tableA[number_month]<=Max(tableA[number_month])))

thank you in advance 

 

 

 

 

the cumulthe cumulcumul1.PNGCumul2.PNG

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Mariam1991

What you need is a date dimension. Without one, you can't achieve your goal.

Your measure is cumulating the values of the months with the same name number (1,2,....) and adding the result to the result of the next month with the same number. But it doesn't know anything about date. Month number could be anything but date, even it is derived from date in your case. 

 

Power BI needs a date dimension to achieve year-to-date calculations.

With a date dimension, the measure is straight forward:

 

NEW_cumulative_sum_with_date_dimension = 
calculate(
	sum(TableA[Sales]);
	DATESYTD('Calendar'[Date]))

 

your solution looks something like this:

 

grafik.png

with the measure in the code you will get this table:

grafik.png

Hope this helps. Please feel free to ask more questions if needed.

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @Mariam1991

Do you have any relationships between the tables?

Especially from date to Sales?

Or do you have just one table for all the data?

Thank you for your feedback , no i have 5 tables but date, sales and agency are in the same table A 

Anonymous
Not applicable

Hi @Mariam1991

What you need is a date dimension. Without one, you can't achieve your goal.

Your measure is cumulating the values of the months with the same name number (1,2,....) and adding the result to the result of the next month with the same number. But it doesn't know anything about date. Month number could be anything but date, even it is derived from date in your case. 

 

Power BI needs a date dimension to achieve year-to-date calculations.

With a date dimension, the measure is straight forward:

 

NEW_cumulative_sum_with_date_dimension = 
calculate(
	sum(TableA[Sales]);
	DATESYTD('Calendar'[Date]))

 

your solution looks something like this:

 

grafik.png

with the measure in the code you will get this table:

grafik.png

Hope this helps. Please feel free to ask more questions if needed.

sorry for being late , thank you for ur solution but how can i create a date dimension knowing that i have just a date column in table A

Anonymous
Not applicable

I've written a few times on my blog powerbi-pro.com about this, but it is in German..

Matt Masson wrote an article: https://www.mattmasson.com/2014/02/creating-a-date-dimension-with-a-power-query-script/

 

thank you , i create a dimension date but the measure cumulative_sum= calculate( sum(TableA[Sales]); DATESYTD('Date'[Date]))

 But it doesn't work correcty , 

even more i use this column cumulative_sum=calculate(sum(tableA[sales]);filter(allselected('date');'date'[date]<=max('date'[date])))

i need help 😞

Anonymous
Not applicable

what is the name of your newly created date table?
Can you post a picture of it?

 

Thanks very much,that's working correctly now 😉

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.