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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Cumulative total in stacked bar graph

Hi everyone, I am quite new to Power BI.

 

I'm trying to present a graph that adds the cumulative total of a column over each month. The data set is from April 2020 to March 2021. 

 

I have used the following Measure to calculate the running total: 

Running Total MEASURE = CALCULATE (SUM ( 'Data'[Savings] ), FILTER (ALLSELECTED( 'Data' ), Data[Date] <= MAX(Data[Date])))
 
This measure works well for a basic bar graph:
T-M-W_0-1597113494002.png

 

However, I would like to split this by category in a stacked bar graph. Whenever I try and add a data field in the legend, it doesn't seem to be splitting up the allocations correctly:

T-M-W_1-1597113577232.png

 

This second graph should ideally show the same total values as the first one, only split by status, ideally looking something like this:

T-M-W_2-1597113858743.png

 

Any help would be appreciated, thank you!

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Here is my sample data.

sample data.png

 

1. Create three calculated columns to sort the months of the chart by year.

Month = MONTH([Date])

Year = YEAR([Date])

Year-Month = [Year]&"-"&[Month]

ca.png

 

2. You can write your measure as below. I changed ALLSELECTED to ALLEXCEPT.

Running Total MEASURE =
CALCULATE (
    SUM ( 'Data'[Savings] ),
    FILTER (
        ALLEXCEPT ( Data, Data[Categories] ),
        Data[Date] <= MAX ( Data[Date] )
    )
)

result.png

 

You can check more details from here.

 

 

Best Regards,

Icey

 

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
rruthSL
Advocate I
Advocate I

This solution works. Though if you have a calendar table, be sure to mind the differences below. Also, note the difference in the CALCULATE function's first operand - This is the solution to overcounting which you may or may not encounter.

Running Total MEASURE =
CALCULATE (
DISTINCTCOUNT ( 'Data'[ID] ),
FILTER (

/* 1. Keep all days in the Calendar table, then
2. Keep only those up to the last visible day */

ALL ( 'Calendar' ), 
'Calendar'[Date] <= MAX ( 'Calendar'[Date] )
),
ALLEXCEPT ( 'Data', 'Data'[Line No.] )
)
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Here is my sample data.

sample data.png

 

1. Create three calculated columns to sort the months of the chart by year.

Month = MONTH([Date])

Year = YEAR([Date])

Year-Month = [Year]&"-"&[Month]

ca.png

 

2. You can write your measure as below. I changed ALLSELECTED to ALLEXCEPT.

Running Total MEASURE =
CALCULATE (
    SUM ( 'Data'[Savings] ),
    FILTER (
        ALLEXCEPT ( Data, Data[Categories] ),
        Data[Date] <= MAX ( Data[Date] )
    )
)

result.png

 

You can check more details from here.

 

 

Best Regards,

Icey

 

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

This solution works. Though if you have a calendar table, be sure to mind the differences below. Also, note the difference in the CALCULATE function's first operand - This is the solution to overcounting which you may or may not encounter.

Running Total MEASURE =
CALCULATE (
DISTINCTCOUNT ( 'Data'[ID] ),
FILTER (

/* 1. Keep all days in the Calendar table, then
2. Keep only those up to the last visible day */

ALL ( 'Calendar' ), 
'Calendar'[Date] <= MAX ( 'Calendar'[Date] )
),
ALLEXCEPT ( 'Data', 'Data'[Line No.] )
)

@Icey 

That was smart !

Another alternative will be 

Running Total MEASURE = 
CALCULATE (
    SUM ( 'Data'[Savings] ),
    FILTER (
        ALL(Data[Date],Data[Year-Month]),
        Data[Date] <= MAX ( Data[Date] )
    )
)


Thanks
Fowmy

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Fowmy
Super User
Super User

@Anonymous 

Each category will have its own data and will not allocate into anything. insert a slicer for the category, select each and check it works when the graph has only one. It stacks one on top of the other. Change the graph to line or area chart to what you are expecting.

________________________

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

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

amitchandak
Super User
Super User

@Anonymous , Create a date table and join date with date and try like

Running Total MEASURE = CALCULATE (SUM ( 'Data'[Savings] ), FILTER (ALLSELECTED( 'Date' ), Date[Date] <= MAX(Date[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.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors