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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
faysanderson
New Member

Group by Max date without losing other bits of data

Using this table...

Client IDAssessment IDAssess Date
12310110/1/24
1231021/1/24
23430016/3/24
23430220/6/24
3454056/9/24
34541010/9/24

 

I want to group by Client ID number to show the Max Assess Date. When I use the UI to do this, the code comes out as...

= Table.Group(#"Changed Type", {"Client ID"}, {{"Max Assess Date", each List.Max([Assess Date]), type nullable datetime}})

and in the result, I lose the Assessment ID that corresponds to the Max Assess Date.  Result looks like this...

Client IDMax Assess Date
12310/1/24
23420/6/24
34510/9/24

 

But what I want is to keep the Assessment ID that corresponds to the Max Assess Date...

Client IDAssessment IDMax Assess Date
12310110/1/24
23430220/6/24
34541010/9/24

 

How do I change the code to do this?  Or is it possible to do through the UI boxes?

1 ACCEPTED SOLUTION
shafiz_p
Resident Rockstar
Resident Rockstar

Hi @faysanderson  Try below code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc1BCsAwCETRu7gOOI5W6FlC7n+NxpSSQjZ/MQ+xdzG6NDHYqpoSDBltC6t/oMecHChI9VPqhNDc4nHNLVBNvQ8wvP8/GQ8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Client ID" = _t, #"Assessment ID" = _t, #"Assess Date" = _t]),

    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Client ID", Int64.Type}, {"Assessment ID", Int64.Type}, {"Assess Date", type text}}),

    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type", {{"Assess Date", type date}}, "en-GB"),

    #"Grouped Rows" = Table.Group( 
             #"Changed Type with Locale",
             {"Client ID"},
             {
                {"Max Assess Date", each List.Max([Assess Date]), type nullable date},
                {"Assessment ID", each 
                    let
                        maxDate = List.Max([Assess Date]),
                        maxRow = Table.SelectRows(_, each [Assess Date] = maxDate)
                    in
                    maxRow{0}[Assessment ID], 
                type nullable number}
            }
)
in
    #"Grouped Rows"

Desired output:

shafiz_p_0-1728992045475.png

 

Hope this helps!!

If this solved your problem, please accept it as a solution!!

 

Best Regards,
Shahariar Hafiz

View solution in original post

4 REPLIES 4
ThxAlot
Super User
Super User

ThxAlot_0-1728994422800.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



slorin
Super User
Super User

Hi @faysanderson 

 

= Table.Group(#"Changed Type", {"Client ID"}, {{"Max Assess Date", each Table.Max(_, "Assess Date"), type record}})

 Expand "Assessment ID" and "Max Assess Date"

 

Stéphane

shafiz_p
Resident Rockstar
Resident Rockstar

Hi @faysanderson  Try below code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc1BCsAwCETRu7gOOI5W6FlC7n+NxpSSQjZ/MQ+xdzG6NDHYqpoSDBltC6t/oMecHChI9VPqhNDc4nHNLVBNvQ8wvP8/GQ8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Client ID" = _t, #"Assessment ID" = _t, #"Assess Date" = _t]),

    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Client ID", Int64.Type}, {"Assessment ID", Int64.Type}, {"Assess Date", type text}}),

    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type", {{"Assess Date", type date}}, "en-GB"),

    #"Grouped Rows" = Table.Group( 
             #"Changed Type with Locale",
             {"Client ID"},
             {
                {"Max Assess Date", each List.Max([Assess Date]), type nullable date},
                {"Assessment ID", each 
                    let
                        maxDate = List.Max([Assess Date]),
                        maxRow = Table.SelectRows(_, each [Assess Date] = maxDate)
                    in
                    maxRow{0}[Assessment ID], 
                type nullable number}
            }
)
in
    #"Grouped Rows"

Desired output:

shafiz_p_0-1728992045475.png

 

Hope this helps!!

If this solved your problem, please accept it as a solution!!

 

Best Regards,
Shahariar Hafiz

Thank you.  I haven't completely wrapped my head round why this works or how to implement it in other scenarios, but it has solved my issue. 😀

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors