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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
nic2023
Frequent Visitor

Remove duplicates based on conditions in Power Query

Hi everyone, I'm trying to remove some duplicates in a large list, which is formed from appending 2 lists of staff IDs.

Some of the Staff IDs have duplicate entries, I'd like to set up some conditions to remove duplicates: 

1) When there is a duplicate in [Staff ID], if the [End Date] is non blank, then keep the non-blank row, delete the blank row;

2) If there is no duplicate in [Staff ID], then keep the row. 

 

Thanks! 

 

The original table: 

Staff IDEnd Date
12319/11/2024
123 
45610/10/2024
456 
789 
1011 
10119/02/2024
1112 
1213 

 

The desired outcome would be:

Staff IDEnd Date
12319/11/2024
45610/10/2024
789 
10119/02/2024
1112 
1213 
1 ACCEPTED SOLUTION

Hi,

One of ways is using Table.Group function in Power Query Editor.

 

let
    Source = Data_Source,
    #"Grouped Rows" = Table.Group(Source, {"Staff ID"}, {{"End Date", each List.Max([End Date]), type nullable date}})
in
    #"Grouped Rows"

 

Jihwan_Kim_0-1731989005566.png

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

4 REPLIES 4
Kedar_Pande
Super User
Super User

@nic2023 

Power Query Code:

let
Source = YourTableName,
SortTable = Table.Sort(Source, {{"Staff ID", Order.Ascending}, {"End Date", Order.Descending}}),
RemoveDuplicates = Table.Distinct(SortTable, {"Staff ID"})
in
RemoveDuplicates

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

Jihwan_Kim
Super User
Super User

Hi,

Please try something like below whether it suits your requirement.

Please check the below picture and the attached pbix file.

It is for creating a new table.

 

Jihwan_Kim_0-1731988143274.png

 

expected result table =
VAR _list =
    DISTINCT ( Data[Staff ID] )
VAR _t =
    ADDCOLUMNS ( _list, "End Date", CALCULATE ( MAX ( Data[End Date] ) ) )
RETURN
    _t

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Sorry I'm using Power Query in Excel. 

Hi,

One of ways is using Table.Group function in Power Query Editor.

 

let
    Source = Data_Source,
    #"Grouped Rows" = Table.Group(Source, {"Staff ID"}, {{"End Date", each List.Max([End Date]), type nullable date}})
in
    #"Grouped Rows"

 

Jihwan_Kim_0-1731989005566.png

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors