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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
TD21
Helper II
Helper II

How to delete some but not all duplicates

In my dataset, I have a "Request_ID" column. For some records, this value is set to "TBD" when the Request ID is unavailable.

 

What I would like to do is delete duplicate Request IDs while keeping all the "TBD"s. I can't use Delete Duplicate Rows in PowerQuery because it will delete the "TBD"s as well. How do I delete duplicate Request IDs while keeping the "TBD" values?

 

Would like to delete duplicates (in red) but keep the TBDs.

 

Request_ID

MS012345

MS662234

MT789458

TBD

MA640001

MA640001

MC987453

MK239800

TBD

MK239800

4 REPLIES 4
FarhanAhmed
Community Champion
Community Champion

What is the data source ? Can't it be done at Datasource level ?

Some sample data along with output will be appreciated.

 







Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!

Proud to be a Super User!




@FarhanAhmed

Can't edit datasource as we don't own it (was granted SELECT only).

I updated the original post to include sample data. Thanks.

FarhanAhmed
Community Champion
Community Champion

Try this

 

 

let
    Source = Excel.Workbook(File.Contents("D:\BI\Power BI\Community\Book1.xlsx"), null, true),
    RequestID_Table = Source{[Item="RequestID",Kind="Table"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(RequestID_Table,{{"RequestID", type text}}),
    #"Filtered RowsTBD" = Table.SelectRows(#"Changed Type", each ([RequestID] = "TBD")),
    #"Removed Duplicates" = Table.Distinct(#"Changed Type"),
    #"Filtered Rows" = Table.SelectRows(#"Removed Duplicates", each ([RequestID] <> "TBD")),
    #"Appended Query" = Table.Combine({#"Filtered Rows", #"Filtered RowsTBD"})
in
    #"Appended Query"

 

 

Follow the simple steps to remove duplicates and filter the table to exclude "TBD"

Then you need to add 2 things in your Power Query....

Add "#"Filtered RowsTBD" = Table.SelectRows(#"Changed Type", each ([RequestID] = "TBD"))," to select all rows of TBD just before removing duplicates

 

After filtering out your data you need to append this data with your filtered removed duplicates rows to get all "TBD" and distinct other values.

 

Hope you understand the logic

 

If this helps kindly mark it as "Answer" and give Kudos.

 







Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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