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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
cottrera
Post Prodigy
Post Prodigy

Max date per unique id

Hi 

 

I have a facts table with two columns  Unit ref, Completed Data. The unit ref can appear on more than one line , but with a different  completed date.  

 

I need a measure column that displays the Max Dates for each of the Unit refs

 

Unit refCompleted DateDAX Max Date
43734711/08/201911/08/2019
8767830/05/201016/04/2015
8767823/08/201116/04/2015
8767816/04/201516/04/2015
1804/04/202102/02/2022
1802/02/202202/02/2022
765430/05/201001/03/2022
765405/05/201101/03/2022
765409/04/201201/03/2022
765415/03/201301/03/2022
765418/02/201401/03/2022
67801/03/202201/03/2022
6869623/05/201802/04/2020
6869628/04/201902/04/2020
6869602/04/202002/04/2020

 

I would also be interested in how this could be done in power query.

 

thank you

 

RIchard

 

1 ACCEPTED SOLUTION
PC2790
Community Champion
Community Champion

Hey @cottrera ,

 

It can be done using "Group By" in Power Query.

See the screenshot of the parameters arrangement in Group By

PC2790_0-1649330795421.png

And this is the advanced editor code:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc/LDcQwCATQXnyOxB/jWqL030YCa8lCe30ChrnvoTJF57gGEQQw0hrPdY+YPuNTQUBLxsYsgDVNjckBNdmKKU0hhekIA6dwyXTT/5ytBnZCtq26R22bDFBSpWkAZhJp6X4R5IR7+PJdp5Kic+w6q/Ov0ffp8wI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Unit ref" = _t, #"Completed Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Unit ref", Int64.Type}, {"Completed Date", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Unit ref"}, {{"Max", each List.Max([Completed Date]), type nullable text}, {"All rows", each _, type table [Unit ref=nullable number, Completed Date=nullable text]}}),
    #"Expanded All rows" = Table.ExpandTableColumn(#"Grouped Rows", "All rows", {"Completed Date"}, {"Completed Date"})
in
    #"Expanded All rows"

The outcome will be:

 

PC2790_1-1649330848049.png

 

View solution in original post

2 REPLIES 2
cottrera
Post Prodigy
Post Prodigy

Thank you it works fine 😀

PC2790
Community Champion
Community Champion

Hey @cottrera ,

 

It can be done using "Group By" in Power Query.

See the screenshot of the parameters arrangement in Group By

PC2790_0-1649330795421.png

And this is the advanced editor code:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc/LDcQwCATQXnyOxB/jWqL030YCa8lCe30ChrnvoTJF57gGEQQw0hrPdY+YPuNTQUBLxsYsgDVNjckBNdmKKU0hhekIA6dwyXTT/5ytBnZCtq26R22bDFBSpWkAZhJp6X4R5IR7+PJdp5Kic+w6q/Ov0ffp8wI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Unit ref" = _t, #"Completed Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Unit ref", Int64.Type}, {"Completed Date", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Unit ref"}, {{"Max", each List.Max([Completed Date]), type nullable text}, {"All rows", each _, type table [Unit ref=nullable number, Completed Date=nullable text]}}),
    #"Expanded All rows" = Table.ExpandTableColumn(#"Grouped Rows", "All rows", {"Completed Date"}, {"Completed Date"})
in
    #"Expanded All rows"

The outcome will be:

 

PC2790_1-1649330848049.png

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.