Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
I have a table as shown below and want it to be transformed to
Input
EID | StartDate | MGRID |
100884 | 3/1/2018 | 101516 |
100884 | 8/1/2022 | 76728 |
10077 | 6/12/2000 | 10080 |
102083 | 4/1/2018 | 82224 |
102083 | 5/2/2023 | 82224 |
102085 | 5/7/2018 | 15384 |
102086 | 5/7/2018 | 15384 |
102558 | 6/11/2018 | 76728 |
102558 | 12/11/2023 | 101516 |
102558 | 9/6/2022 | 24976 |
Output
EID | StartDate | MGRID |
100884 | 8/1/2022 | 76728 |
10077 | 6/12/2000 | 10080 |
102083 | 5/2/2023 | 82224 |
102085 | 5/7/2018 | 15384 |
102086 | 5/7/2018 | 15384 |
102558 | 12/11/2023 | 101516 |
For each employee, I only want to keep the latest start date.
I have seen several similar posts but just can't make this work. Can someone please help. I want to do this in Power Query Editor / M Query in Power BI
Regards,
-Debo
Solved! Go to Solution.
In Power Query, sort the date column in descending order, add an index column, then remove duplicates on Employee ID. Only the most recent item for each EID will stay.
Here is an example I did:
This is when I am on the sorted rows step:
This is when I am on the remove duplicate step:
Proud to be a Super User! | |
let
#"Grouped Table" = Table.Group(DATA, "EID", {"grp", each Table.Sort(_, {"StartDate", Order.Descending}){0}}),
#"Expanded grp" = Table.ExpandRecordColumn(#"Grouped Table", "grp", {"StartDate", "MGRID"}, {"StartDate", "MGRID"})
in
#"Expanded grp"
Calculated table is way more concise and elegant,
Expertise = List.Accumulate( {Days as from Today}, {Skills and Knowledge}, (Current, Everyday) => Current & Day.LearnAndPractise(Everyday) ) |
let
#"Grouped Table" = Table.Group(DATA, "EID", {"grp", each Table.Sort(_, {"StartDate", Order.Descending}){0}}),
#"Expanded grp" = Table.ExpandRecordColumn(#"Grouped Table", "grp", {"StartDate", "MGRID"}, {"StartDate", "MGRID"})
in
#"Expanded grp"
Calculated table is way more concise and elegant,
Expertise = List.Accumulate( {Days as from Today}, {Skills and Knowledge}, (Current, Everyday) => Current & Day.LearnAndPractise(Everyday) ) |
In Power Query, sort the date column in descending order, add an index column, then remove duplicates on Employee ID. Only the most recent item for each EID will stay.
Here is an example I did:
This is when I am on the sorted rows step:
This is when I am on the remove duplicate step:
Proud to be a Super User! | |
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
72 | |
70 | |
55 | |
38 | |
31 |
User | Count |
---|---|
75 | |
64 | |
64 | |
49 | |
45 |