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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

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
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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Kudoed Authors