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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Tobias106
Helper I
Helper I

Cumulative sum in a year per month

Hello everbody,

 

I have data per month from 2017 - now.

 

I want to show a cumulated line per month for e.g. 2021.

 

So in the x-axis are the month, FEB yhould be JAN + Februar for 2021 and so on.

 

How can I do this per DAX formula?

 

Thank you 🙂

 

Regards Tobias

 

1 ACCEPTED SOLUTION
v-yadongf-msft
Community Support
Community Support

Hi @Tobias106 ,

 

This is my test table:

vyadongfmsft_0-1665471927728.png

 

Please create a new column:

Cumulative sum in a year per month = CALCULATE(SUM('Table'[Sales]),FILTER('Table', 'Table'[Sales] <= EARLIER('Table'[Sales]) && 'Table'[Year] = EARLIER('Table'[Year])))

 

You can calculate the cumulative sum in a year per month:

vyadongfmsft_1-1665472005997.png

 

Best regards,

Yadong Fang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-yadongf-msft
Community Support
Community Support

Hi @Tobias106 ,

 

This is my test table:

vyadongfmsft_0-1665471927728.png

 

Please create a new column:

Cumulative sum in a year per month = CALCULATE(SUM('Table'[Sales]),FILTER('Table', 'Table'[Sales] <= EARLIER('Table'[Sales]) && 'Table'[Year] = EARLIER('Table'[Year])))

 

You can calculate the cumulative sum in a year per month:

vyadongfmsft_1-1665472005997.png

 

Best regards,

Yadong Fang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yadongf-msft @ Thank you very much for this simple and awesome code, that helps a lot :-).

 

One additional question. Beside the year and month I also have the date in the table, which can occure more than once.

 

Therefore I used your code and changed the year to the date:

 

Cumulative sum in a year per month = CALCULATE(SUM('Table'[Sales]),FILTER('Table', 'Table'[Sales] <= EARLIER('Table'[Sales]) && 'Table'[Date] = EARLIER('Table'[Date])))

 

 

But due to to topic that I have sometime the same date 2-3 times (or more), it cumulates in the following way:

 

Example:

dateSales**bleep** Sales

01.01.2022

10

10

01.01.2022

12

22

01.01.2022

14

36

 

Power Bi shows it now as one date an so 01.01.2022 is 10+22+36 = 68, which is of course wrong.

 

Which I need - If the same date is more than once, than it should only cumulate in the last date-line, so the following should be:

 

dateSales**bleep** Sales

01.01.2022

10

 

01.01.2022

12

 

01.01.2022

14

36

 

Can you please help me again :)?

Hi,

Please share some data (in format that can be pasted in an MS Excel file) and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi  @Tobias106 ,

 

You need to create some additional columns.

 

This is my test table:

vyadongfmsft_1-1665538439744.png

 

First, add an index column in Power Query:

vyadongfmsft_0-1665538397506.png

vyadongfmsft_2-1665538496719.png

 

Create a new column to count the number of occurrences of each date:

Count = CALCULATE(COUNT('data2'[Date]),FILTER('data2','data2'[Date] = EARLIER('data2'[Date]) && 'data2'[Index] <= EARLIER('data2'[Index])))

vyadongfmsft_3-1665538667958.png

 

The result you want:

Cumulative sum in a year per month = 
var sumsales = CALCULATE(SUM('data2'[Sales]),FILTER('data2','data2'[Sales] <= EARLIER('data2'[Sales])))
return
IF('data2'[Count] = MAXX(FILTER('data2','data2'[Date] = EARLIER('data2'[Date])),'data2'[Count]),sumsales)

vyadongfmsft_4-1665538707462.png

 

Best regards,

Yadong Fang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Tobias106 , Either you need have month in YYYYMM format, Make sure you create a month year table , with YYYYMM, Month , Year 

 

or if you date will do

 

Cumm Sales = CALCULATE(SUM(Sales[Sales Amount]),filter(all('Date'),'Date'[date] <=max('Date'[date])))

 

or

 

Cumm Sales = CALCULATE(SUM(Sales[Sales Amount]),filter(allselected('Date'),'Date'[date] <=max('Date'[date])))

 

or

Cumm Sales = CALCULATE(SUM(Sales[Sales Amount]),filter(all('Month'),'Month'[YearMonth] <=max('Month'[YearMonth])))

 

or

 

Cumm Sales = CALCULATE(SUM(Sales[Sales Amount]),filter(allselected('Month'),'Month'[YearMonth] <=max('Month'[YearMonth])))

 

Rolling Months Formula: https://youtu.be/GS5O4G81fww

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@amitchandak 

Thank you!

 

But as I understand, I get with your formulas the cumulative sum till the max Date I choose ("<=max('Month'[YearMonth])))").

 

But I need January 2021 till December 2021, for example.

And after I that I want to create a cumulative line with JAN 2020 - DEC 2020, and so on.

 

Do you have an idea :-)?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.