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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Replicate excel formula - recursive substraction

Hi there. I am trying to replicate excel formula in power BI DAX. I have date column(A) with date, progress column(B) with integer, left column(C) with integer. This meant to be project progress monitoring tool. So the team is starting with 100k instances to process and on each day they do certain progress, so in the cell C2 = 100000-B2,but starting from C3 = C2 - B3, C4 = C3 - B4 and so on...

 

Help will be appreciated.

Thanks,

Michal

 

 

 

 

 

1 REPLY 1
ImkeF
Community Champion
Community Champion

Hi @Anonymous ,

if you're serious about performance here, I'd recommend this approach:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDUByIjAyMDJR0lQwMQUIrVgYgbIcThYsYwMSOEmAlMzBghZopFrxmy3lgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [date = _t, progress = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"date", type date}, {"progress", Int64.Type}}),
    ListToAccumulate =  List.Buffer(#"Changed Type"[progress]),
    AccumulateColumn = List.Generate( ()=>
        [Result = List.First(ListToAccumulate), Counter = 1 ],
        each [Counter] <= List.Count(ListToAccumulate),
        each [
                Result = [Result] - ListToAccumulate{[Counter]},
                Counter = [Counter] + 1
        ],
        each [Result]
        
    ),
    Custom2 = Table.FromColumns(Table.ToColumns( #"Changed Type") & {AccumulateColumn}, Table.ColumnNames(#"Changed Type") & {"Left"})
in
    Custom2

 

Copy the code, paste it into the advanced editor of a new query and follow the steps.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.