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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
lbell
Frequent Visitor

Power query - remove row based on condition and if value exists

the data is similar to the example below

Field1  Field2

A       123456

A        125467

B        123456

B        3214

 

the value in Field2 must only occur once in the table, and the record with Field1 = A must be kept.  Must end up with:

 

Field1  Field2

A       123456

A        125467

B        3214

1 ACCEPTED SOLUTION
jthomson
Solution Sage
Solution Sage

First step I'd do would be to make a column that highlights whether your Field2 is duplicated, this explains it better than I can:

 

https://www.excelguru.ca/blog/2015/12/09/identify-duplicates-using-power-query/

 

Once you've got that, you can concatenate it with Field1, and filter out anything that has a value B1, B2 etc

View solution in original post

2 REPLIES 2
lbell
Frequent Visitor

Found a solution:

Create table1 with Field2 values where Field1 = A

Create table2 with Field1 and Field2 values where Field1 = B

Create new table3 using merge and do right antijoin of table1 and table2, resulting in table3 having only table2 records where Field2 does not exist in table1

remove extra columns from table3

append table3 to table1

 

this seems to work, but it would be good to know if there is a more elegant method for more complex datasets

jthomson
Solution Sage
Solution Sage

First step I'd do would be to make a column that highlights whether your Field2 is duplicated, this explains it better than I can:

 

https://www.excelguru.ca/blog/2015/12/09/identify-duplicates-using-power-query/

 

Once you've got that, you can concatenate it with Field1, and filter out anything that has a value B1, B2 etc

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors