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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
susheeltyagi
Helper I
Helper I

How to get the find the recent records from the duplicate records using Power Query Editor

HI,

 

I need small help. I am importing the data from SQL Server database. I would like to get the most recent record on the basese of  Serial Number and UserTime using Power Query at the stage of Transformation of data.

How to do it ?

 

Input Data as below :

(Table : Device)

susheeltyagi_0-1680259194809.png

 

 

Expected output after Transform of data using Power Editor :

susheeltyagi_1-1680259229155.png

 

Thanks in advance

 

Susheel

1 REPLY 1
jennratten
Super User
Super User

Hello - this is how you can do it.

BEFORE

jennratten_0-1680260812505.png

AFTER

jennratten_1-1680260838414.png

SCRIPT

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jc5bCsQwCAXQrRS/2+FezcO4ldD9b6MGhs7HFGYgSFSOOqdQdhkoQG09v15HRrUVwHHAD+pGDSDfC4Cc+xT9rbjRAh5st6p/7UrVg36rln1jZm2UNaD7KhT/YmbBz4n9mdUnpm92Xg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Id = _t, SerialNumber = _t, RemaingItems = _t, ReadingRemaining = _t, UserTimer = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Id", Int64.Type}, {"SerialNumber", Int64.Type}, {"RemaingItems", Int64.Type}, {"ReadingRemaining", Int64.Type}, {"UserTimer", type datetime}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"SerialNumber"}, {{"MaxTimer", each List.Max([UserTimer]), type nullable datetime}, {"Data", each _, type table [Id=nullable number, SerialNumber=nullable number, RemaingItems=nullable number, ReadingRemaining=nullable number, UserTimer=nullable datetime]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "MaxValue", each Table.SelectRows ( [Data], (x) => x[UserTimer] = [MaxTimer] )),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"MaxValue"}),
    #"Expanded MaxValue" = Table.ExpandTableColumn(#"Removed Other Columns", "MaxValue", {"Id", "SerialNumber", "RemaingItems", "ReadingRemaining", "UserTimer"}, {"Id", "SerialNumber", "RemaingItems", "ReadingRemaining", "UserTimer"})
in
    #"Expanded MaxValue"

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.