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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Vish_BI_Toddler
New Member

Maxifs - Power Query to get latest row details where duplicate available

Hey there,

I have sample table below based on MS form responses with response date, user details like ID and response for question. Problem is sometimes a user submits multiple responses for a single day - I would like to get latest response date and time for each user for each day response submitted.

IMG_8247.jpeg


in above example user 123 submitted 2 responses for 26 aug and 1 response for 24 aug. Column D is required output which will show for user 123 for response date 26 aug - 7 am (being latest reaponse) .. for 24 aug its single response hence same value being reported. Similar for other users too.

 

thanks in advance and really learning a lot from community 🙂

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJRstA3MtM3MjAyVjC3MjAACvjlK8XqRCtZWlpCZE0gsoZ4ZS0gspGpxWBpuNGmKEZjSJtgs9nc3BzFXaY4NGORjgUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"EMP ID" = _t, #"Response Date" = _t, Response = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"EMP ID", Int64.Type}, {"Response Date", type datetime}, {"Response", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"EMP ID"}, {{"Latest Response", each List.Max([Response Date]), type nullable datetime}, {"r", each _, type table [EMP ID=nullable number, Response Date=nullable datetime, Response=nullable text]}}),
    #"Expanded r" = Table.ExpandTableColumn(#"Grouped Rows", "r", {"Response Date", "Response"}, {"Response Date", "Response"})
in
    #"Expanded r"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJRstA3MtM3MjAyVjC3MjAACvjlK8XqRCtZWlpCZE0gsoZ4ZS0gspGpxWBpuNGmKEZjSJtgs9nc3BzFXaY4NGORjgUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"EMP ID" = _t, #"Response Date" = _t, Response = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"EMP ID", Int64.Type}, {"Response Date", type datetime}, {"Response", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"EMP ID"}, {{"Latest Response", each List.Max([Response Date]), type nullable datetime}, {"r", each _, type table [EMP ID=nullable number, Response Date=nullable datetime, Response=nullable text]}}),
    #"Expanded r" = Table.ExpandTableColumn(#"Grouped Rows", "r", {"Response Date", "Response"}, {"Response Date", "Response"})
in
    #"Expanded r"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

Thanks a lot for detailed response.. it works as expected.. ☺️

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors