Power Query Grouping By

Sonia Bowditch
Sonia Bowditch used Ask the Experts™
on
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

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Managing Director/Excel VBA Developer
Distinguished Expert 2018
Commented:
Hi Sonia,

Have you tried creating Pivot Table? From Report you can select Level to list all the customers and their data field (please see attached). If you still wants grouping then please refer Group rows in a table (Power Query) or Grouping or Summarizing Data

Once you created groups, then select the group name in Pivot and in Formula Bar, change Level to desired name
Sonia_PQ-Test.xlsx
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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial