We help IT Professionals succeed at work.

Power Query Grouping By

328 Views
Last Modified: 2018-02-02
I have a Power Query from a table.  As I am still learning about what Power Query can do I am struggling with Grouping.

What I am trying to do is:

Group by Customer, by level 1, show the earliest date requested for all categories (in this case 2), lastest date updated by level 1, total quantity received by level 1.

If I can get help with putting together this bit, I will be able to work out everything else I need to do with this Power Query table.

I have attached a file containing test data.

I appreciate any help you can give me,
Thanks,
Infosec36
PQ-Test.xlsx
Comment
Watch Question

Managing Director/Excel VBA Developer
CERTIFIED EXPERT
Distinguished Expert 2018
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Sonia BowditchIT & Systems Administrator

Author

Commented:
Hello Shums,

Thanks for getting back to me.

I have attached an example of what I am trying to achieve with the Power Query, shown on Sheet 2.  The area I am struggling with is the dates as I can work out to do total of fields.

Thanks,
InfoSec36
PQ-Test.xlsx
Dan

Commented:
Sonia,
Over a month old, my guess is you have found a solution.
I think this is the Power Query M solution you seek:

let
    Source = Excel.CurrentWorkbook(){[Name="PQ_Test"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"customer", type text}, {"level_1", type text}, {"date_request", type datetime}, {"dt_created", type datetime}, {"last_updated", type datetime}, {"price", type number}, {"net_value", type number}, {"vat_value", type number}, {"total_value", type number}, {"qty_req", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"customer", "level_1"}, {{"Earliest date_request", each List.Min([date_request]), type datetime}, {"Last last_updated", each List.Max([last_updated]), type datetime}, {"Sum qty_req", each List.Sum([qty_req]), type number}})
in
    #"Grouped Rows"

Open in new window

Sonia BowditchIT & Systems Administrator

Author

Commented:
Perfect, thank you.