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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

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
Anonymous
Not applicable

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 

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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