Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos
Catch up on one of our webinars
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
394 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Some other pages relevant to this blog include:
You can also book hourly online consultancy for your time zone with one of our 7 expert trainers!
| Removing duplicates by specified sort order in Power Query |
|---|
| Removing duplicates by specified sort order in Power Query |
In Power BI, I have data that includes people and their completion percentage for a form.
I want to return each person once with their highest completion percentage.

Currently, the data is in its original order.
Click the dropdown next to the column you want to sort by (in this case Completion %) and select Sort Descending.

Sorting a numeric column in descending order will place the largest values first.
The data is now ordered from the highest completion percentage to the lowest.

I don't want to remove duplicates from this column, as two people could have the same score.
To keep only one copy of each person, right-click the Person column and choose Remove Duplicates from the menu.

M is case-sensitive, meaning that Sally and sally would be treated as separate values.
This returns one row for each person, but the results are incorrect.
Power BI has ignored the sort order we applied and has instead returned the first item based on the original order of the data.

For example, Bob 50 appeared before Bob 43, and Sally 20 appeared before Sally 100.
To fix this, we need to apply an action to the Sorted Rows step before the Removed Duplicates step.

Click on the Query Settings | Applied Steps | Sorted Rows step.
Edit the M code at the top of the table, add Table.Buffer( in front of the existing code and a closed bracket at the end.

The Table.Buffer function tells Power BI to freeze the table in its current state, preventing implicit reordering.
Click back to the last final step, Query Settings | Applied Steps | Removed Duplicates to view the end result.

Some actions do not create separate steps.
Now, the Remove Duplicates action keeps the first item encountered based on the Completion % sort order.

This technique also works when sorting by multiple columns.
Some other pages relevant to this blog include:
You can also book hourly online consultancy for your time zone with one of our 7 expert trainers!
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Elementa Workspace
6 Bevis Marks
LONDON
EC3A 7BA
c/o Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2026. All Rights Reserved.