Grouping ages in PQ

INN

Board Regular
Joined
Feb 3, 2021
Messages
124
Office Version
  1. 365
Platform
  1. Windows
Hello
Can I group by age in Power Query? I know how to do that using Pivot Table but I am wondering if I can do the same in Power Query without writing a M code. I tried Group By in PQ but that did not group ages to sub group rather it merge (unique) ages.

Book1
AB
1AgeSalary
26177958
36552484
44492752
52634557
651101803
73198396
826159911
95441524
106577425
1164105667
1248130918
1324150019
1466112070
1536131130
163989904
1735185295
1852100840
193559644
2057186253
Sheet1


I want to create table like below using PQ

Book1
HI
3Row LabelsSum of Salary
424-33442883
534-43465973
644-53426313
754-63305735
864-73347646
9Grand Total1988550
Sheet1
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Age", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Age Range", each if [Age]>23 and [Age]< 34 then "24-33"
else if [Age]>33 and [Age]<44 then "34-43"
else if [Age] >43 and [Age]<54 then "44-53"
else if [Age] > 53 and [Age]<64 then "54-63"
else "64-73"),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Age"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns", {"Age Range"}, {{"Sum Salary", each List.Sum([Salary]), type number}}),
    #"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Age Range", Order.Ascending}})
in
    #"Sorted Rows"
 
  • Like
Reactions: INN
Upvote 0

Forum statistics

Threads
1,223,693
Messages
6,173,877
Members
452,536
Latest member
Chiz511

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top