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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
Super User
Super User

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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.