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

Get Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher 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
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

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.