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
CameronKudos
Helper I
Helper I

Stuck on Creating reverse running total based on other columns

Hi all,

I desperately need to figure this out for my work.

 

Here's the sample data: https://drive.google.com/file/d/1dI7COyElnNXb33iSk1eiau8ESONHLphf/view?usp=sharing

 

Here's the overview:

 

I have a table , named 'Future Date Service Agreement Plans (3)' with two columns that are giving me trouble. They are called:

[Total_Remaining_Cost__c] 

and 

[Daily_Rate_Based_On_Days_Remaining__c]

 

Both of these columns repeat the same number over and over again until another dimension in the table [Account Name] changes, then they repeat the process. 

 

Would I would like for them to do is subtract the [Daily_Rate_Based_On_Days_Remaining__c] from the [Total_Remaining_Cost__c]  and the have the [Total_Remaining_Cost__c] column go down with each day. So, it would look like this:

CameronKudos_0-1645615488706.png

But it would need to start over with each [Account ID] change (Which happens when the date in the Day By Day column reaches the date in the EndDate column .

 

Here's a picture of what the table currently looks like.

CameronKudos_1-1645615687784.png

 

 

1 ACCEPTED SOLUTION
Thingsclump
Resolver V
Resolver V

Hi @CameronKudos 

 

I believe you need to do a grouped running total. The only difference is that you need to subtract rather than add. My suggestion is multiply daily rate column with -1 and do a grouped total. It should work. You can search for running total grouped on Google and you will get lot of articles. I just found that this one is useful.

 

https://www.goodly.co.in/running-total-power-query/ 

 

Let me know how this works.

 

Thanks

View solution in original post

5 REPLIES 5
watkinnc
Super User
Super User

Is it correct that the [Days Remaining] column also resets at the Account ID change? If so, you could Group on the Account ID, use the Max aggregation on Days Remaining (let's name that column MaxDay) and an All Rows Aggregation, and then expand the All Rows column. Then, you could do row arithmetic like:

 

= Table.AddColumn(PriorStepOrTableName, "Amount Left", each [Total Remaining Cost] - (([MaxDays -Days Remaining) * Rate))

 

--Nate 


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

Thanks, but no luck: 

CameronKudos_1-1645713424824.png

 

 

Thingsclump
Resolver V
Resolver V

Hi @CameronKudos 

 

I believe you need to do a grouped running total. The only difference is that you need to subtract rather than add. My suggestion is multiply daily rate column with -1 and do a grouped total. It should work. You can search for running total grouped on Google and you will get lot of articles. I just found that this one is useful.

 

https://www.goodly.co.in/running-total-power-query/ 

 

Let me know how this works.

 

Thanks

All good, I got it by adding a running total to the daily rate, then using that colum to subtract from the total amount remaining. Thank you

Thanks for that. this is the code that I went with, but it didn't work. Where do I put the minus symbol? Should I not be using the Index column?
= Table.AddColumn(
BufferedTable,
"Running Total",
(OutTable) =>
List.Sum(
Table.SelectRows(
BufferedTable,
(InTable) => InTable[Index] <= OutTable[Index]
and
InTable[Daily_Rate_Based_On_Days_Remaining__c] = OutTable[Daily_Rate_Based_On_Days_Remaining__c])[Total_Remaining_Cost__c]))

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.

Top Solution Authors
Top Kudoed Authors