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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register 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

4 REPLIES 4
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.

@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.

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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