Forum Discussion

Tan_LC's avatar
Tan_LC
Helper II
3 years ago

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

Replies have been turned off for this discussion
  • 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"})
  • wdx223_Daniel's avatar
    wdx223_Daniel
    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])

    • Tan_LC's avatar
      Tan_LC
      Helper II

      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