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
Wilm117
Helper I
Helper I

Filter out most recent date user level in PowerQuery

Hi Everybody,

 

I am looking for a solution to filter out or mark the most recent date in from a salary registration export. table 1 shows an example of the dataset, which in reality contains thousands of records. My goal is to generate a piece of M-code to filter out the records with the most recent "Start date Salary" per Employee_ID and obtain the desired outcome presented below in table 2.

 

- The amount of records differs per person. Some only have one record, but  others more than 20. 

- The sorting order per person is random, so not automatically from oldest to most recent date.

 

Is anybody able to help me with the correct M-code for this issue? Thanks in advance!

 

table 1: Demo

Employee_IDFTEStart date Salarymost recent date
P2100811-11-2021 00:00 
P2100811-1-2022 00:00 
P210080,91-1-2023 00:00X
P2100811-7-2022 00:00 
P2358511-1-2023 00:00X
P2358511-1-2022 00:00 
P2358511-7-2022 00:00 
P2358511-11-2021 00:00 
P2391411-11-2021 00:00 
P239141,11-1-2022 00:00 
P239141,11-7-2022 00:00 
P239141,11-1-2023 00:00 
P2391411-1-2024 00:00X
P26523025-9-2022 00:00X

 

Table 2: Desired outcome

Employee_IDFTEStart date Salary
P210080,91-1-2023 00:00
P2358511-1-2023 00:00
P2391411-1-2024 00:00
P26523025-9-2022 00:00
1 REPLY 1
DOLEARY85
Resident Rockstar
Resident Rockstar

Hi,

 

hopefully this helps, m - query:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jY9LDoAgDESvYliTMG1BwVO4J9z/GsJK+QgmndWbTqcxqosJ8EorygIZIsO0ASegku55HuYRhw6PQ2YJR5sgzrv6giz4dH+R338ogewfrr8btI6+wyBDJi0KtxXfHUthWewMwutCugE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Employee_ID = _t, FTE = _t, #"Start date Salary" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee_ID", type text}, {"Start date Salary", type datetime}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Employee_ID"}, {{"Maxdate", each List.Max([Start date Salary]), type nullable datetime}, {"Details", each _, type table [Employee_ID=nullable text, FTE=nullable number, Start date Salary=nullable datetime]}}),
#"Expanded Details" = Table.ExpandTableColumn(#"Grouped Rows", "Details", {"FTE", "Start date Salary"}, {"Details.FTE", "Details.Start date Salary"}),
#"Added Custom" = Table.AddColumn(#"Expanded Details", "Custom", each if [Details.Start date Salary] =[Maxdate] then 1 else 0),
#"Renamed Columns" = Table.RenameColumns(#"Added Custom",{{"Custom", "Flag"}}),
#"Filtered Rows" = Table.SelectRows(#"Renamed Columns", each ([Flag] = 1))
in
#"Filtered Rows"

 

DOLEARY85_0-1682161574639.png

If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

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.