cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
user10
Frequent Visitor

Applying filters to running total?

Hi,

 

I'm trying to create a chart that shows the progressive work completed on a project; So at week 1 0% (0hours) have been completed; by week 50 (end of project), it should show 100% (1000hours) complete.  I've added a column to my table to calculate the running total on hours completed per week.

 

CumulativeHours = CALCULATE ( SUM (WORK[TotalHours]), ALL(WORK), WORK[Week] <= Earlier(WORK[week]))

 

My tables look like this

 

ACTIVITIES (list of all activities)

Week

ActivityName

TypeOfWork

WorkArea

ActivityHours

 

WORK (distinct list of weeks and total hours per week, from the ACTIVITIES table)

Week

TotalHours

CumulativeHours

 

Tables are joined on the 'Week' Column (relationship is 1 (WORK) : M (ACTIVITIES)).

 

I want to add slicers to the report for TypeOfWork and WorkArea.  I have 2 issues:  1. The slicers do not seem to affect the chart when I apply them.  2. Even if the slicers worked, I'm not conviced the cumulativeHours would re-calculate based on the applied filters...?

 

Has anyone come across the same problem and have a solution?

1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft
Microsoft

Hi, @user10

 

You want to make the cumulativeHours re-calculate based on the selected filters, right? If so, please create a measure to calculate running total rather than calculated column.

 

The DAX formula should be like:

 

MeasureRunningTotal = 
CALCULATE(
SUM(Running[TotalDay]),
FILTER(ALLSELECTED(Running),
Running[WeekName]<=MAX(Running[WeekName])
))

Thanks,
Yuliana Gu

 

Community Support Team _ Yuliana Gu
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

9 REPLIES 9
user10
Frequent Visitor

Both solutions worked.  Thanks to @Greg_Deckler and @v-yulgu-msft!

 

 

Hi Greg,

 

I noticed u have provided some examples for calculating cumalative measures . So my scenario is i need to calculate a cumm total of all funds where work has commenced using a weekending column and team leaders should be able to filter using a slicer..the formula works before adding the slicer but falls over the moment i try to slice. The slicer im applying is in the eoy_AllFunds table.

 

Started_Cum_Actual = CALCULATE(count(eoy_AllFunds[Started Week Ending -2019]),filter(ALL('Plan Started'),('Plan Started'[Week Ending]<=max('Plan Started'[Week Ending]))))

Sample data would be great. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

The issue is probably your ALL clause. You should try ALLSELECTED or perhaps ALLEXCEPT instead of ALL in order to maintain the filter context provided by your slicer.


@ me in replies or I'll lose your thread!!!
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Learn Power BI 2nd Edition

eoy.JPGplan.JPG

Below are my two tables for dax 

Started_Cum_Actual = CALCULATE(count(eoy_AllFunds[Started Week Ending -2019]),filter(all('Plan Started'),'Plan Started'[Week Ending]<=max('Plan Started'[Week Ending])))
 
They have a many(oy_AllFunds) to one (Plan Started) relationship between them and the slicer needs to go on em csm
 
v-yulgu-msft
Microsoft
Microsoft

Hi, @user10

 

You want to make the cumulativeHours re-calculate based on the selected filters, right? If so, please create a measure to calculate running total rather than calculated column.

 

The DAX formula should be like:

 

MeasureRunningTotal = 
CALCULATE(
SUM(Running[TotalDay]),
FILTER(ALLSELECTED(Running),
Running[WeekName]<=MAX(Running[WeekName])
))

Thanks,
Yuliana Gu

 

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I tried the formula but it keep repeating the first number after that. It has 2 slicers, shop and date. Users select a shop and a date range. The running total is on the number of days machines are running during the selected date range for the selected shop.

 

Shop A has only 5 machines. But the running total ran past the maximum of 5 for Shop A. I think that's because other shops have more machines. One of the shop have 12 machines.

 

# of Machine# of DayRunning TotalDesired Result
0222
1688
241212
361818
462424
552929
6 2 
7 2 
8 2 
9 2 
10 2 
11 2 
12 2 
    

 

 

RunningTotal =  Calculate (SUM(Machine[MachineCount]), FILTER(ALL(Machine[NumberOfMachine], Machine[Shop]),

 

(Machine[NumberOfMachine] <= max(Machine[NumberOfMachine])  )))

 

Greg_Deckler
Super User
Super User

Hmm, well, the slicers aren't working because of your ALL clause, you might try ALLEXCEPT and list the columns of your slicers.


@ me in replies or I'll lose your thread!!!
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Learn Power BI 2nd Edition

Thank you @Greg_Deckler 

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

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.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors