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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
Anonymous
Not applicable

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.