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
kpickle
Frequent Visitor

Running Total with nested calculation

Hi there, 

Is there a way to add a nested calculation within a running total? 

Example:

When the running total hits 1,000 subtract 900 and continue the running total...

2022-09-27_15-32-01.png

Would it better to try this as a measure or a calculated column?

Thank you.

 

1 ACCEPTED SOLUTION

@kpickle 

you can update the DAX like below

Column = 
VAR _SUM=SUMX(FILTER('Table','Table'[date]<=EARLIER('Table'[date])),'Table'[Daily])
VAR _reach=int(_SUM/1000)
VAR _result=_SUM-_reach*900
return if (_result>1000,_result-900,_result)




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

Proud to be a Super User!




View solution in original post

6 REPLIES 6
ryan_mayu
Super User
Super User

@kpickle 

agree with @PhilipTreacy , measure is better.

you can try his solution

if you want to create a column, you can try this

Column = 
VAR _SUM=SUMX(FILTER('Table','Table'[date]<=EARLIER('Table'[date])),'Table'[Daily])
VAR _reach=int(_SUM/1000)
return _SUM-_reach*900

1.PNG





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

Proud to be a Super User!




Hey Guys, 

I tried it both ways and a couple issues - both work for the first trigger. 

2022-09-28_11-43-11.png

 

As a measure:

2022-09-28_11-50-34.png

 

2022-09-28_11-52-14.png

 

Question 1 - is there any logic I can add behind the measure to calculate off the previous days result instead of SUM?

 

As a calcualted column:

2022-09-28_12-05-12.png

 

2022-09-28_12-18-57.png

 

Question 2 - Is there logic behind calculating the integer and rounding it up somehow? This seems like the more comlplex solution though.

I need to take a mental break from this so here is some sample data if anyone wants to take a crack at it. Thank you!

 

DateDailySUMreach_INTTest1 (column)Test2 (measure)CORRECTTriggerDecrease
9/26/202210510501051051051000900
9/27/20221002050205205205  
9/28/20221253300330330330  
9/29/20221504800480480480  
9/30/20221155950595595595  
10/1/20221607550755755755  
10/2/20221108650865865865  
10/3/202220010651165165165  
10/4/202210011651265265265  
10/5/202220513701470470470  
10/6/202218015501650650650  
10/7/202211016601760760760  
10/8/202219018501950950950  
10/9/2022170202022201120220  
10/10/2022180220024001300400  
10/11/2022195239525951495595  
10/12/2022115251027101610710  
10/13/2022115262528251725825  
10/14/2022160278529851885985  
10/15/20221102895210951995195  
10/16/2022200309533952195395  
10/17/2022100319534952295495  
10/18/2022205340037002500700  
10/19/2022180358038802680880  
10/20/2022110369039902790990  
10/21/20221903880311802980280  
10/22/2022180406044603160460  
10/23/2022110417045703270570  
10/24/2022190436047603460760  
10/25/2022170453049303630930  
10/26/20221604690410903790190  
10/27/20221104800412003900300  

@kpickle 

you can update the DAX like below

Column = 
VAR _SUM=SUMX(FILTER('Table','Table'[date]<=EARLIER('Table'[date])),'Table'[Daily])
VAR _reach=int(_SUM/1000)
VAR _result=_SUM-_reach*900
return if (_result>1000,_result-900,_result)




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

Proud to be a Super User!




Works beautifully. Thank you both!

you are welcome





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

Proud to be a Super User!




PhilipTreacy
Super User
Super User

Hi @kpickle 

 

Yes.  Let's say you are calcuting the RT like this (a measure, this is better than a static calculated column)

 

 

= CALCULATE(SUM([Actual]), FILTER(ALLSELECTED('Calendar'[Date]),ISONORAFTER('Calendar'[Date], MAX(Actual[Date]), DESC)))

 

 

 

You can modify that to check the value of the running total (storing it in a Variable called _RT) and carry out whatever modification you want based on the value of _RT e.g.

 

 

= VAR _RT = CALCULATE(SUM([Actual]), FILTER(ALLSELECTED('Calendar'[Date]),ISONORAFTER('Calendar'[Date], MAX(Actual[Date]), DESC)))

RETURN

IF(_RT > 1000, _RT - 1000, _RT)

 

 

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


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.