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

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

Reply
James_White_199
Frequent Visitor

Help with a formula

Hi 

 

I need help creating a formula that gives me a running cumulative total of a material in one column based on the requirement qty in another column (EG Below). In Excel i can do this using the SUMIFS function but i do not know how to perform this in PowerQuery.

 

James_White_199_0-1724072217047.png

 

Thanks

 

 

 

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @James_White_199, check this:

 

Output

dufoq3_0-1724079494246.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIyMDLRNTAEIiDHUClWB03YCMgxBQs7oas2xxA2NAdyTDBVgwwxxjTbGMTBVA0SNlOKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Material = _t, Date = _t, #"Req qty" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Req qty", type number}}),
    GroupedRows = Table.Group(ChangedType, {"Material"}, {{"All", each 
        [ a = Table.Sort(_, {{"Date", Order.Ascending}}),
          b = List.Buffer(a[Req qty]),
          c = List.Generate( ()=> [ x = 0, y = b{x}], each [x] < List.Count(b), each [ x = [x]+1, y = [y] + b{x} ], each [y] ),
          d = Table.FromColumns(Table.ToColumns(a) & {c}, Value.Type(a & #table(type table[Cumulative Total=number], {})))
        ][d], type table}}),
    Combined = Table.Combine(GroupedRows[All])
in
    Combined

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

2 REPLIES 2
dufoq3
Super User
Super User

Hi @James_White_199, check this:

 

Output

dufoq3_0-1724079494246.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIyMDLRNTAEIiDHUClWB03YCMgxBQs7oas2xxA2NAdyTDBVgwwxxjTbGMTBVA0SNlOKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Material = _t, Date = _t, #"Req qty" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Req qty", type number}}),
    GroupedRows = Table.Group(ChangedType, {"Material"}, {{"All", each 
        [ a = Table.Sort(_, {{"Date", Order.Ascending}}),
          b = List.Buffer(a[Req qty]),
          c = List.Generate( ()=> [ x = 0, y = b{x}], each [x] < List.Count(b), each [ x = [x]+1, y = [y] + b{x} ], each [y] ),
          d = Table.FromColumns(Table.ToColumns(a) & {c}, Value.Type(a & #table(type table[Cumulative Total=number], {})))
        ][d], type table}}),
    Combined = Table.Combine(GroupedRows[All])
in
    Combined

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Ahmed_Kandil
New Member

 hello , If you want to use sumifs in power query try selecting the column you want and go to

transform tab or add column-->group by--->then select operation sum 

hope this helps you

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.