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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Running Total with categories

Hi all, I have a question on running totals:
I have a table "Data" of projects (identified by ID). Each project has a generated power "Power", an operational start year "Op_Year" (in number format - not date), a current status (e.g. design, under construction, operative) "Status" and a country "Geo".

I successfully plotted in a stacked bar chart the additional power that will be available from 2020 to 2025 by Geo and in another by Status and I would like now to create other two bar charts with the cumulative installed power (also considering power already installed before 2020 but start plotting from 2020 onward). 

I used the following measure that worked to plot the cumulative power:

RunningTotal = CALCULATE(SUM('Data'[Power]]);FILTER(ALLSELECTED('Data');'Data'[Op_Year]<=MAX('Data'[Op_Year])))

(with minimum x-axis value 2020 and max 2025 to limit the years as needed).

But when I try to add a legend (Geo or Status) to the chart it does not work anymore (it even changes values and totals in the chart)! I also tried to modify the formula this way but again it did not work correctly (same for Status instead of Geo).

RunningTotal = CALCULATE(SUM('Data'[Power]]);FILTER(ALLSELECTED('Data');'Data'[Op_Year]<=MAX('Data'[Op_Year])&&'Data'[Geo]=MAX('Data'[Geo])))


Can you please help me to understand where I am mistaking? Thanks!

11 REPLIES 11
PavanLalwani
Resolver II
Resolver II

The issue you’re facing with your cumulative power measure when adding a legend (such as "Geo" or "Status") is likely due to how the DAX formula interacts with the context of the visualization. When you add a legend, it creates additional filtering contexts that affect the calculation, so it’s essential to modify the formula to account for these contexts properly.

Here's a solution you can try by modifying the `RunningTotal` measure to take into account the legend (e.g., "Geo" or "Status"):

### Running Total with Categories Solution:

```DAX
RunningTotal =
VAR CurrentGeo = MAX('Data'[Geo]) -- or MAX('Data'[Status]) if using Status as the category
VAR CurrentYear = MAX('Data'[Op_Year])

RETURN
CALCULATE(
SUM('Data'[Power]),
FILTER(
ALLSELECTED('Data'),
'Data'[Op_Year] <= CurrentYear
&& 'Data'[Geo] = CurrentGeo -- or 'Data'[Status] = CurrentStatus] for Status
)
)
```

### Explanation:
1. **`CurrentGeo` and `CurrentYear`**: These variables capture the current category and year that the chart is focusing on, based on the selected data points.

2. **Filtering with Context**: The `FILTER` function now includes both the year and the `Geo` (or `Status`), ensuring that the cumulative total is calculated only for the current category being plotted.

3. **ALLSELECTED**: This function ensures that the running total respects the selections made in the report (e.g., if you have other slicers affecting the data).

### Notes:
- If you're using `Status` as the legend instead of `Geo`, replace `Geo` with `Status` in the formula.
- You can use this formula for both charts with different legends (one for `Geo` and one for `Status`) by adapting the variable `CurrentGeo` to the relevant column.

This should allow you to properly display the running totals for each category (either by "Geo" or "Status") in the chart without affecting the totals or changing values unexpectedly.

Thanks for the explanation!
I have the issue that if there is no a category on the last period it does not show me from the previous period. So mark A from grade 2 is not showen on the grade 3. Is it possible to solve it somehow?

Elvi_well_0-1729505361522.png

 

Anonymous
Not applicable

@Anonymous 

Try replace ALLSELECTED('Data') to All(Data). 

If not working, try :

 

RunningTotal = CALCULATE(SUM('Data'[Power]]);FILTER(ALL('DATA'); SUMX(FILTER('DATA';EARLIER('DATA'[Op_Year])<='DATA'[Op_year);1)))

 

 

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

 

 

Anonymous
Not applicable

@Anonymous thank you for the input.
Again not working, unfortuntely. The output is the one below:
4.PNG

 

If it may help, below the raw data I am using for this example (the real db is much more bigger and confidential, but the below is fully representative of the problem)

Spoiler
IDPowerGeoStatusOp_Year
110RoWInstallation2021
25RoWOperational2019
34EuropeDesign2021
47AsiaOperational1996
510EuropeOperational1993
63AmericasInstallation2021
75AsiaOperational2000
83RoWOperational1990
97EuropeDesign2024
101EuropeOperational2006
111RoWDesign2025
124AsiaOperational1999
131RoWOperational2016
146AsiaInstallation2021
157RoWOperational2015
166RoWOperational2009
173RoWOperational2016
183EuropeOperational1997
198RoWOperational2001
204EuropeOperational1994
215RoWInstallation2022
222EuropeOperational2004
237RoWOperational2012
241AmericasOperational2017
259AsiaDesign2024
264AsiaOperational2018
272RoWInstallation2023
287RoWOperational2015
295AsiaOperational2017
303AmericasInstallation2020
314EuropeDesign2028
326AsiaOperational2019
338RoWOperational2017
3410EuropeOperational1993
359AsiaOperational2017
365RoWDesign2023
379RoWOperational2019
382AsiaDesign2024
393AsiaOperational2013
403AsiaOperational2017
417AmericasOperational1997
426AmericasDesign2027
435RoWOperational2002
445AmericasOperational2018
458AmericasDesign2022
466EuropeOperational2008
472RoWOperational2015
484AmericasOperational2011
496AsiaOperational2017
507AsiaOperational2000

 

 

Anonymous
Not applicable

@Anonymous 

 

With the current data your have, it is not possible to achieve your expected bar chart. The chart does not show data for other [Geo] (e.g.year 2020, 2023) is because you have no data to record the power of Year 2020 for [Geo] other than Americas, so you can not use the Year column show the value of that year. 

 

To make it clear, I create a pibx with 3 additional rows for each Geo of year 2020. (no value).

3 rows.JPG

3rows new chart.JPG

pibx: https://qiuyunus-my.sharepoint.com/:u:/g/personal/paul_qiuyunus_onmicrosoft_com/EZXm-HhQM_1BrgwJ6ASMA3YBZptgqjHJxH05SQBQYMsR7Q?e=pjwJEr

 

In my opinion, a line chart is more appropriate to see the trend with your current data. Or you can just edit your original data by adding rows to fill the blanks for years with no value like the 3 rows I added in the pbix.

 

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

Anonymous
Not applicable

@Anonymous thank you very much for your input and for letting me understand the limits of the visuals.
Line charts can be a solution even though the still keep some limitations.

I was just wondering if there is a way to automatically create a new table with Years as rows and Geo as columns summing up the values of the previous table without any particular input but just with DAX code. This way it should work and also the limit of the line chart (values are "interrupted" at a specific year if there is no further input for that Geo for a following year) can be overcome. 

Can you help on this please - if it is feasible?
Many thanks in advance!

Anonymous
Not applicable

@Anonymous sorry to bother you on this, but do you see a way to proceed as described in my previous message?
Many thanks!

Anonymous
Not applicable

Can anyone help on this?

Thanks! 😊

sturlaws
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

could you try changing your code to this:

RunningTotal =
CALCULATE (
    SUM ( 'Data'[Power] );
    FILTER (
        ALLEXCEPT ( 'Data'; Data[Geo] );
        'Data'[Op_Year] <= MAX ( 'Data'[Op_Year] )
    )
)
Anonymous
Not applicable

Hi @sturlaws, thanks for you reply.
Unfortunately it does not work . Until I try to categorize the thing it is working as expected (see picture).
1.PNG

 









When I add "Geo" to the legend of the chart, it changes to this:
2.PNG

 

 

 

 

 

 

 

 

While what I expect is something like this:

3.PNG

Hi!
did you solved the problem? I have the same issue.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors