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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

How to group a table with a detail column ?

Hello 🙂

 

Is it possible with power query to use Table.Group with a min or max as an aggregated column and also having some other columns associated to the result of the min or max ? 

 

For example if I have : 

 

First Name           Last Name              Age                   Job

 

Marie                     Doe                       23                     Nurse

Celia                      Doe                       38                     Painter

Frederic                 Martin                   40                     Estate Agent

Thomas                 Martin                    25                    Student

Cedric                    Martin                    33                   Doctor

 

I would like to have as a result (grouping by the first name and having the minimum of the age as an aggregated column) :

 

Last Name              Age                   Job

 

 Doe                       23                     Nurse

Martin                    25                    Student

 

If it is not clear, let me know I will try to use another example ! 

 

Thanks !

 

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@Anonymous Here is one way:

OriginalTable query:
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8k0sykxV0lFyyQeRRsZAwq+0qDhVKVYnWsk5NSczES5pbAEkAhIz80pSi8DSbkWpKalFmclAYaAxJZl5QIaJAZBwLS5JLElVcExPzSsBqwzJyM9NLEZWZ2QKJIJLSlNgSpxTU9CMMjYGW51ckg+0LhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"First Name" = _t, #"Last Name" = _t, Age = _t, Job = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"First Name", type text}, {"Last Name", type text}, {"Age", Int64.Type}, {"Job", type text}})
in
    #"Changed Type"



Grouping Table query:
let
    Source = OriginalTable,
    #"Grouped Rows" = Table.Group(Source, {"Last Name"}, {{"Age", each List.Min([Age]), type nullable number}}),
    #"Merged Queries" = Table.NestedJoin(#"Grouped Rows", {"Last Name", "Age"}, OriginalTable, {"Last Name", "Age"}, "OriginalTable", JoinKind.LeftOuter),
    #"Expanded OriginalTable" = Table.ExpandTableColumn(#"Merged Queries", "OriginalTable", {"Job"}, {"OriginalTable.Job"})
in
    #"Expanded OriginalTable"


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
ngct1112
Post Patron
Post Patron

Same solution in one Query. @Anonymous 

Please try

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8k0sykxV0lFyyQeRRsZAwq+0qDhVKVYnWsk5NSczES5pbAEkAhIz80pSi8DSbkWpKalFmclAYaAxJZl5QIaJAZBwLS5JLElVcExPzSsBqwzJyM9NLEZWZ2QKJIJLSlNgSpxTU9CMMjYGW51ckg+0LhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"First Name" = _t, #"Last Name" = _t, Age = _t, Job = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Age", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Last Name"}, {{"Age", each List.Min([Age]), type nullable number}}),
    #"Merged Queries" = Table.NestedJoin(#"Grouped Rows", {"Age","Last Name"}, #"Changed Type", {"Age","Last Name"}, "Grouped Rows", JoinKind.LeftOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"Job"}, {"Grouped Rows.Job"})
in
    #"Expanded Grouped Rows"

 

Anonymous
Not applicable

Perfect, thanks ! 

@Anonymous If it solves your issue, please mark as solution so that it benefits others.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

@Anonymous Here is one way:

OriginalTable query:
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8k0sykxV0lFyyQeRRsZAwq+0qDhVKVYnWsk5NSczES5pbAEkAhIz80pSi8DSbkWpKalFmclAYaAxJZl5QIaJAZBwLS5JLElVcExPzSsBqwzJyM9NLEZWZ2QKJIJLSlNgSpxTU9CMMjYGW51ckg+0LhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"First Name" = _t, #"Last Name" = _t, Age = _t, Job = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"First Name", type text}, {"Last Name", type text}, {"Age", Int64.Type}, {"Job", type text}})
in
    #"Changed Type"



Grouping Table query:
let
    Source = OriginalTable,
    #"Grouped Rows" = Table.Group(Source, {"Last Name"}, {{"Age", each List.Min([Age]), type nullable number}}),
    #"Merged Queries" = Table.NestedJoin(#"Grouped Rows", {"Last Name", "Age"}, OriginalTable, {"Last Name", "Age"}, "OriginalTable", JoinKind.LeftOuter),
    #"Expanded OriginalTable" = Table.ExpandTableColumn(#"Merged Queries", "OriginalTable", {"Job"}, {"OriginalTable.Job"})
in
    #"Expanded OriginalTable"


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors