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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
sya
Helper I
Helper I

Keep Duplicates with Conditions in Query Editor

Hi All,

 

I'm new to Power BI and need help with the following problem.

 

Start DateEnd DateCandidate NoCandidate Name
1-Mar-20228-Feb-2023100142992Ali
26-Oct-202128-Feb-2022100142992Ali
1-Jan-202131-Dec-2022100058909Bob
1-Jan-202131-Dec-2022100058909Bob
1-Nov-202131-Dec-2021100053113Cindy
1-Jan-202228-Feb-2022100053113Cindy

 

I need to keep duplicate Candidate No. that meets the following conditions:

 

1. If first Start Date/End Date equal to second Start Date/End Date, only keep one

2. If first Start Date/End Date does not equal to second Start Date/End Date, keep if End Date is in the future (compared to today's date)

 

The result should be as follows:

Start DateEnd DateCandidate NoCandidate Full Name
1-Mar-20228-Feb-2023100142992Ali
26-Oct-202128-Feb-2022100142992Ali
1-Jan-202131-Dec-2022100058909Bob
1-Jan-202228-Feb-2022100053113Cindy

 

Please help 

 

Regards,

Sya

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@sya , Power Query code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtT1TSzSNTIwMlLSUbLQdUtNAnGMgRxDAwNDEyNLS5CEY06mUqxOtJKRma5/cglIhSFQ1Aiu3giHekNdr8Q8mHJjQ12X1GQk5QamFpYGlkC2U34Secr98sswlRvClBsbGoI84pyZl1KJar4RNteja4gFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Start Date" = _t, #"End Date" = _t, #"Candidate No" = _t, #"Candidate Name" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Start Date", type date}, {"End Date", type date}, {"Candidate No", Int64.Type}, {"Candidate Name", type text}}),
    #"Removed Duplicates" = Table.Distinct(#"Changed Type"),
    #"Filtered Rows1" = Table.SelectRows(#"Removed Duplicates", each [End Date] > DateTime.Date(DateTime.LocalNow()))
in
    #"Filtered Rows1"

 

Option 2:

DAX code on the base table you share. Not on power query 

Table = FILTER( distinct(Data) , [End Date] >= today())
Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@sya , Power Query code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtT1TSzSNTIwMlLSUbLQdUtNAnGMgRxDAwNDEyNLS5CEY06mUqxOtJKRma5/cglIhSFQ1Aiu3giHekNdr8Q8mHJjQ12X1GQk5QamFpYGlkC2U34Secr98sswlRvClBsbGoI84pyZl1KJar4RNteja4gFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Start Date" = _t, #"End Date" = _t, #"Candidate No" = _t, #"Candidate Name" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Start Date", type date}, {"End Date", type date}, {"Candidate No", Int64.Type}, {"Candidate Name", type text}}),
    #"Removed Duplicates" = Table.Distinct(#"Changed Type"),
    #"Filtered Rows1" = Table.SelectRows(#"Removed Duplicates", each [End Date] > DateTime.Date(DateTime.LocalNow()))
in
    #"Filtered Rows1"

 

Option 2:

DAX code on the base table you share. Not on power query 

Table = FILTER( distinct(Data) , [End Date] >= today())
Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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