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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Zaibass81
Helper I
Helper I

Subtract running totals based on condition (M Code)

Hello,

 

I'm looking for a m code solution that subtracts running totals and re-iterates calculation when a new FG Item is found, also to return last value from iteration to the beginning row Subtract.png

2 REPLIES 2
wdx223_Daniel
Super User
Super User

NewStep=Table.FromRecords(List.Accumulate(Table.ToRecords(PreviousStepName),{{},[]},(x,y)=>let a=Record.FieldOrDefault(x{1},y[FG_Item],y[#"RM#QTY in WHS"]),b=a-y[#"RM Part# Monthly Consumtion"] in {x{0}&{y&[Remaining Qty=b]},x{1}&Record.AddField(y[FG_Item],b)}){0})

Unfortunateley I am getting errors.

First one related to the null value converting to text

Error1.png

then if I am filling up FG_Item colunm to replce nulls i am getting another error that record wasn't found..

Error2.png

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