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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Moliems
Frequent Visitor

Max Date within a Group + extra condition

Hi there, could anyone help me in Power Query to pick the row for each student that has the max date below?

 

I have an extra issue that for some students there is more than one max date, so i would then choose the status column that has the earliest letter in the alphabet!

 

Example data below with required output.  Thank you in advance for any help!

 

Student

Name        Date           Status
Student 1 12/01/2021 A
Student 1 10/01/2021 C
Student 1 12/01/2021 B
Student 2 09/01/2021 B
Student 2 08/01/2021 C
Student 2 09/01/2021 A
Student 3 01/01/2021 A
Student 3 03/01/2021 B
Student 3 04/01/2021 C
Student 3 18/01/2021 D

Desired Output:
Student

Name        Date           Status
Student 1 12/01/2021 A
Student 2 09/01/2021 A
Student 3 18/01/2021 D

1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

Hi, @Moliems 

let
    Source = you_table,
    gr = 
        Table.Group(
            Source, "Name", 
            {"r", 
            each 
                Table.FirstN(
                    Table.Sort(_, {{"Date", Order.Descending}, {"Status", Order.Ascending}}), 
                    1
                )
            }
        ),
    z = Table.Combine(gr[r])
in
    z

View solution in original post

2 REPLIES 2
Moliems
Frequent Visitor

Thank you!  I think this does the trick!

AlienSx
Super User
Super User

Hi, @Moliems 

let
    Source = you_table,
    gr = 
        Table.Group(
            Source, "Name", 
            {"r", 
            each 
                Table.FirstN(
                    Table.Sort(_, {{"Date", Order.Descending}, {"Status", Order.Ascending}}), 
                    1
                )
            }
        ),
    z = Table.Combine(gr[r])
in
    z

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.