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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Tan_LC
Helper I
Helper I

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Solution Authors
Top Kudoed Authors