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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
Vishnu812
Frequent Visitor

Power Bi dax query

Hi,

I have table contains multiple values with same name in Id column and has corresponding rank value in Rank column.

Need to remove the old rank values and keep the latest one.

For example:

Sample data

IdRank
abc0
abc1
xyz0
pqr0
xyz1
abc2

 

Expected output

IdRank
abc2
xyz1
pqr0
1 ACCEPTED SOLUTION

 

No problem. Just include the new [Branch] column within the Group By step, so you group on both [Branch] and [ID].

 

New example code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUUpMSgaSBkqxOsh8Qzi/orIKRb6gsAiFD5E3RNNvBOYnIcvHAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Branch = _t, Id = _t, Rank = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"Rank", Int64.Type}}),

// Relevant steps from here ----->
    addIndex = Table.AddIndexColumn(chgTypes, "Index", 1, 1, Int64.Type),
    groupBranchId = Table.Group(addIndex, {"Branch", "Id"}, {{"data", each _, type table [Branch=nullable text, Id=nullable text, Rank=nullable number, Index=number]}}),
    addLatestRecord = Table.AddColumn(groupBranchId, "latestRecord", each Table.Max([data], "Index")),
    expandLatestRecord = Table.ExpandRecordColumn(addLatestRecord, "latestRecord", {"Rank"}, {"Rank"}),
    removeDataColumn = Table.RemoveColumns(expandLatestRecord,{"data"})
in
    removeDataColumn

 

New output:

BA_Pete_0-1689752464086.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

5 REPLIES 5
BA_Pete
Super User
Super User

Hi @Vishnu812 ,

 

Do you want this done in Power Query or in the data model?

You've posted in the Power Query forum but referenced DAX in your title.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Hello @BA_Pete

 

Power Query

 

Ok. Try this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKVtJRMlCK1YGxDcHsisoquHhBYRGcDRE3RFJvpBQbCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Id = _t, Rank = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"Id", type text}, {"Rank", Int64.Type}}),

// Relevant steps from here ----->
    addIndex = Table.AddIndexColumn(chgTypes, "Index", 1, 1, Int64.Type),
    groupId = Table.Group(addIndex, {"Id"}, {{"data", each _, type table [Id=nullable text, Rank=nullable number, Index=number]}}),
    addLatestRecord = Table.AddColumn(groupId, "latestRecord", each Table.Max([data], "Index")),
    expandLatestRecord = Table.ExpandRecordColumn(addLatestRecord, "latestRecord", {"Rank"}, {"Rank"}),
    removeDataColumn = Table.RemoveColumns(expandLatestRecord,{"data"})
in
    removeDataColumn

 

To get this output:

BA_Pete_0-1688992618420.png

 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Hi, thanks for the help. I need little modify in the question like if there are two rank with same number then it should display both in output because it has another column branch so it should separate it by branch also. Refer below table for example

 

sample data

BranchIdRank
aabc0
aabc1
axyz0
apqr0
axyz1
aabc2
bxyz1

 

Output

BranchIdRank
aabc2
axyz1
bxyz1
apqr0

 

No problem. Just include the new [Branch] column within the Group By step, so you group on both [Branch] and [ID].

 

New example code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUUpMSgaSBkqxOsh8Qzi/orIKRb6gsAiFD5E3RNNvBOYnIcvHAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Branch = _t, Id = _t, Rank = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"Rank", Int64.Type}}),

// Relevant steps from here ----->
    addIndex = Table.AddIndexColumn(chgTypes, "Index", 1, 1, Int64.Type),
    groupBranchId = Table.Group(addIndex, {"Branch", "Id"}, {{"data", each _, type table [Branch=nullable text, Id=nullable text, Rank=nullable number, Index=number]}}),
    addLatestRecord = Table.AddColumn(groupBranchId, "latestRecord", each Table.Max([data], "Index")),
    expandLatestRecord = Table.ExpandRecordColumn(addLatestRecord, "latestRecord", {"Rank"}, {"Rank"}),
    removeDataColumn = Table.RemoveColumns(expandLatestRecord,{"data"})
in
    removeDataColumn

 

New output:

BA_Pete_0-1689752464086.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

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.