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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Tan_LC
Helper II
Helper II

SUMIF using M Query

Hi, in below table, I would like to calculate Sum of Qty based on Date with additional column created.

I've tried using below M Query but error pop up.

Please refer Desired Outcome table for details:

 

DateFactoryQty
10/01/2023Ph1139
11/01/2023Ph128
08/02/2023Ph2-151
23/02/2023Ph11
27/02/2023Ph2-128
10/03/2023Ph139
20/03/2023Ph137
23/03/2023Ph12
23/03/2023Ph2-11
29/03/2023Ph13
29/03/2023Ph2-11
12/04/2023Ph2-11

 

Below M Query was used but failed.

[CurID = [Date],
res = List.Sum(Table.SelectRows(#"Changed Type", each [Date] = CurID) [Qty])]
[res]

 

Desire Outcome with "Sum of Qty" column created:

DateFactoryQtySum of Qty
10/01/2023Ph1139139
11/01/2023Ph12828
08/02/2023Ph2-15151
23/02/2023Ph111
27/02/2023Ph2-12828
10/03/2023Ph13939
20/03/2023Ph13737
23/03/2023Ph123
23/03/2023Ph2-113
29/03/2023Ph134
29/03/2023Ph2-114
12/04/2023Ph2-111

 

Thank you.

Tan LC

3 REPLIES 3
wdx223_Daniel
Community Champion
Community Champion

NewStep=let a=Table.Group(#"Changed Type","Date",{"n",each List.Sum([Qty])}) in Table.AddColumn(#"Changed Type","Sum of Qty",each a{[Date=[Date]]}[n])

@AlienSx @wdx223_Daniel , possible to attach me the solution in pbix. format coz I've tried inserting both of your formulas but still error.

 

Thank you.

Tan LC

AlienSx
Super User
Super User

Hi, @Tan_LC 

    groups = Table.Group(before, {"Date"}, {{"rows", each _, type table [Date=nullable date, Factory=nullable text, Qty=nullable number]}, {"Sum of Qty", each List.Sum([Qty]), type nullable number}}),
    after = Table.ExpandTableColumn(groups, "rows", {"Factory", "Qty"}, {"Factory", "Qty"})

Helpful resources

Announcements
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.