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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
cottrera
Post Prodigy
Post Prodigy

Group by Max date

Hi

I have a resonably large table with the three fields shown below.

Surveyor NameUnit ReferenceDate Completed
Oliver808808/09/2015
Chris808828/09/2023
Rizwan808808/09/2015
Scott15311431/08/2023
Kuldip15311407/08/2015
Kuldip15311407/08/2015


I require some help to how I can group the Unit Reference to display the Max Completion Date and who the Surveyor was.
I would expect this result

Surveyor NameUnit ReferenceDate Completed
Chris808828/09/2023
Scott15311431/08/2023


Please note I already have some M-Code steps being performed on this table.
thankyou
Richard

1 ACCEPTED SOLUTION

So, sorry. I misread the requirement.

See below code.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8s/JLEstUtJRsjCwsABSRgaGproGlroGFkqxOtFKzhlFmcXIskbGIFkjiGxQZlV5Yh5OzcHJ+SUlQGFDU2NDQxO4dgtdY0OwvHdpTkpmAaoCkAEWugbmRCiIBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Surveyor Name" = _t, #"Unit Reference" = _t, #"Date Completed" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Surveyor Name", type text}, {"Unit Reference", Int64.Type}, {"Date Completed", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Unit Reference"}, {{"All", each Table.SelectRows(_, (x)=>x[Date Completed] = List.Max(_[Date Completed]))}})[[All]],
    #"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"Surveyor Name", "Unit Reference", "Date Completed"}, {"Surveyor Name", "Unit Reference", "Date Completed"})
in
    #"Expanded All"

 

View solution in original post

8 REPLIES 8
Vijay_A_Verma
Super User
Super User

Insert the below step where #"Changed Type" is my previous step

= Table.Group(#"Changed Type", {"Surveyor Name", "Unit Reference"}, {{"Date Completed", each List.Max([Date Completed]), type nullable date}})

 

Hi thank you for responding so quickly. However the output is stillthe same os before
Surveyor NameUnit ReferenceDate Completed

Oliver Goldsmith808808/09/2015
Rizwan Ahmed808808/09/2015
Kuldip Jassal15311407/08/2015
Scott Williams15311431/08/2023
Chris Donczyk808828/09/2023

 Richard

 

So, sorry. I misread the requirement.

See below code.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8s/JLEstUtJRsjCwsABSRgaGproGlroGFkqxOtFKzhlFmcXIskbGIFkjiGxQZlV5Yh5OzcHJ+SUlQGFDU2NDQxO4dgtdY0OwvHdpTkpmAaoCkAEWugbmRCiIBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Surveyor Name" = _t, #"Unit Reference" = _t, #"Date Completed" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Surveyor Name", type text}, {"Unit Reference", Int64.Type}, {"Date Completed", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Unit Reference"}, {{"All", each Table.SelectRows(_, (x)=>x[Date Completed] = List.Max(_[Date Completed]))}})[[All]],
    #"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"Surveyor Name", "Unit Reference", "Date Completed"}, {"Surveyor Name", "Unit Reference", "Date Completed"})
in
    #"Expanded All"

 

That works fine thank you

Maybe not as elegant but after that I would sort the date column descending and delete duplicates by Unit Reference so you only get the max date for Unit Reference and it's surveyor.

Hi 

 

thanks for the tip.  I have tried this however whenremoving duplicates it removes the wrong ones and does not leave the max date.
Richard

That happens sometimes after sorting, power query doesn't reflect it. Add an index column after the sorting that would fix it.

Thank you😀

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.