cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Gdps
Helper IV
Helper IV

Cumulative Sum depending on the selected month

Greetings everyone,

 

Here's my problem:

 

I am using the following database to track some metrics:

 

Database 

 

What I would like to have is:

 

When selecting a month inside the slicer (ex: March), I would have a measure that returns the sum of all months until March (Jan, Feb, Mar).

 

For now, I’ve selected every month on the slicer to achieve this condition ... but i know that it’s not the best way.

 

Any ideas?

 

Best regards

1 ACCEPTED SOLUTION
v-xicai
Community Support
Community Support

Hi @Gdps ,

 

You may create column and measure like DAX below.

 

Column:

YearMonth = VALUE(FORMAT('Table1'[Date],"yyyymm"))    
//put this column into Slicer visual as filter options


Measure:

Cumulative sum= CALCULATE(SUM(Table1[Value]),FILTER(ALLSELECTED(Table1), Table1[Metric] =MAX(Table1[Metric])&& Table1[YearMonth]<= MAX(Table1[YearMonth])))

 

Best Regards,

Amy 

 

Community Support Team _ Amy

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

2 REPLIES 2
v-xicai
Community Support
Community Support

Hi @Gdps ,

 

You may create column and measure like DAX below.

 

Column:

YearMonth = VALUE(FORMAT('Table1'[Date],"yyyymm"))    
//put this column into Slicer visual as filter options


Measure:

Cumulative sum= CALCULATE(SUM(Table1[Value]),FILTER(ALLSELECTED(Table1), Table1[Metric] =MAX(Table1[Metric])&& Table1[YearMonth]<= MAX(Table1[YearMonth])))

 

Best Regards,

Amy 

 

Community Support Team _ Amy

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

TomMartens
Super User
Super User

Hey @Gdps ,

 

first you have to shape your data, meaning pivoting the month/year columns into a single month/year column with additional value column. This step will create rows from columns.

Read about this function here: https://radacad.com/pivot-and-unpivot-with-power-bi

Then you have to transform the month/year column into a real date or datetime column.

 

After that you can finally use a dedicated Calendar table. Almost everything you need that is related to timeintelligence related calculations is described in this article: https://www.daxpatterns.com/time-patterns/

 

Hopefully, this provides some new ideas to tackle your challenge.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 24 without aka link and time 768x460.jpg

Ted's Dev Camp - July 28, 2022

Watch Session 24 of Ted's Dev Camp along with past sessions!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors