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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
gabrielmission7
Frequent Visitor

Calculate cumulative monthly total separate by different years

Hi there,
I'm trying to calculate monthly total of revenues but the current month's total is added on top of the previous months. Also, I'd like to separate total by years. Using below table example, I'm hoping to get the outcome in Total2 column but someone I'm getting Total1 (in other words, I'd like the cumulative sum to reset in each year). 

 

Table Sales

YearMonthRevenueTotal1Total2
2021Jan555
2021Feb101515
2021Mar72222
2022Jan3253
2022Feb4297
2022Mar53412

 

My DAX formula:

Revenue Sum =

CALCULATE(
    SUM('Sales'[Revenue]),
    FILTER(
        ALL('Sales'),
        'Revenue'[Month] <= MAX('Revenue'[Month])    
        )
)
 
 
Thank you!
1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @gabrielmission7 ,

Do you have an exact date column like "YYYY/MM/DD" in your data, such as the following:

vyangliumsft_0-1696229073220.png

 

If there is a date column, you can use Way1:

1. Create measure.

Way1 =
SUMX(
    FILTER(ALL('Table'),
    YEAR('Table'[Date])=YEAR(MAX('Table'[Date]))&&'Table'[Date]<=MAX('Table'[Date])),[Revenue])

2. Result:

vyangliumsft_1-1696229073228.png

If there is no date column, try Way2:

1. In Power Query -- Add Column – Index Column – From 1.

vyangliumsft_2-1696229121480.png

2. Create a calculated table.

Text =
SUMMARIZE(
    'Table','Table'[Year],'Table'[Month],    "Index",MINX(FILTER(ALL('Table'),'Table'[Year]=EARLIER('Table'[Year])&&'Table'[Month]=EARLIER('Table'[Month])),[Index]))

vyangliumsft_3-1696229121481.png

3. Create measure.

Way2_value =
SUMX(
    FILTER(ALL('Table'),
    'Table'[Year]=MAX('Text'[Year])&&'Table'[Month]=MAX('Text'[Month])),[Revenue])
Way2_sumvalue =
SUMX(
    FILTER(ALL('Text'),
    'Text'[Year]=MAX('Text'[Year])&&'Text'[Index]<=MAX('Text'[Index])),[Way2_value])

4. Result:

vyangliumsft_4-1696229176752.png

 

Best Regards,

Liu Yang

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

7 REPLIES 7
v-yangliu-msft
Community Support
Community Support

Hi  @gabrielmission7 ,

Do you have an exact date column like "YYYY/MM/DD" in your data, such as the following:

vyangliumsft_0-1696229073220.png

 

If there is a date column, you can use Way1:

1. Create measure.

Way1 =
SUMX(
    FILTER(ALL('Table'),
    YEAR('Table'[Date])=YEAR(MAX('Table'[Date]))&&'Table'[Date]<=MAX('Table'[Date])),[Revenue])

2. Result:

vyangliumsft_1-1696229073228.png

If there is no date column, try Way2:

1. In Power Query -- Add Column – Index Column – From 1.

vyangliumsft_2-1696229121480.png

2. Create a calculated table.

Text =
SUMMARIZE(
    'Table','Table'[Year],'Table'[Month],    "Index",MINX(FILTER(ALL('Table'),'Table'[Year]=EARLIER('Table'[Year])&&'Table'[Month]=EARLIER('Table'[Month])),[Index]))

vyangliumsft_3-1696229121481.png

3. Create measure.

Way2_value =
SUMX(
    FILTER(ALL('Table'),
    'Table'[Year]=MAX('Text'[Year])&&'Table'[Month]=MAX('Text'[Month])),[Revenue])
Way2_sumvalue =
SUMX(
    FILTER(ALL('Text'),
    'Text'[Year]=MAX('Text'[Year])&&'Text'[Index]<=MAX('Text'[Index])),[Way2_value])

4. Result:

vyangliumsft_4-1696229176752.png

 

Best Regards,

Liu Yang

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

Hi @v-yangliu-msft,

Thank you so much for the detailed explanation and example! One thing I noticed is that when we use 'filter' combined with 'All', it seems that other slicers don't seem to be functioning. Is there a way to have slicers (eg. product type) to still be applicable?

@v-yangliu-msft I solved the issue by replacing the 'All' function with 'Allexcept'. Thanks again for your help!

gabrielmission7
Frequent Visitor

@some_bih, further to my earlier comment, I think YTD is the right thing to do. However, for some reason, the outcome is not summing up. Any thoughts? Thank you!

Hi @gabrielmission7 in initial post you wrote

cumulative sum to reset in each year

This is YTD. Dou yoz have ćcalendar/Date table connected with yourtable?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






gabrielmission7
Frequent Visitor

Hi @some_bih ,

Thanks for the reply. However, YTD and MTD are probably not what I'm looking for. Essentially, I'm trying to pull this kind of graph that shows cumulative sum of sales but separate by year.

gabrielmission7_0-1695921124940.png

 

some_bih
Super User
Super User

Hi @gabrielmission7 for monthly amounts per year, you will need TOTALMTD (link below) as possible solution

Measure test MTD= TOTALMTD(SUM('Sales'[Revenue]]),YourCalendar[DateKey]) 

Adjust according your table / column name

 

If you do not have already calendar table create one as below and connect relationship with your table

https://learn.microsoft.com/en-us/power-bi/guidance/model-date-tables 

 

TOTALMTD

https://learn.microsoft.com/en-us/dax/totalmtd-function-dax?WT.mc_id=DP-MVP-4025372 

 

TOTALYTD (when you have MTD, usually YTD is pair)

https://learn.microsoft.com/en-us/dax/totalytd-function-dax?WT.mc_id=DP-MVP-4025372 

Measure test yTD= TOTALYTD(SUM('Sales'[Revenue]]),YourCalendar[DateKey]) 

Did I answer your question? Kudos appreciated / accept solution!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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