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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
StuartSmith
Power Participant
Power Participant

Remove Duplicates based on Condition

I have a table similar to the below...

 

VR Account Building Code City Country Region
VR1 B1 Blah    
VR2 B2      
VR2        
VR2        
VR3 B2      
VR3 B2      
VR4        

 

I want to remove duplicate "VR Account" values, but if there are duplicate "VR Account" vales that also has a "Building Code" value that take priority over a "VR Account" with no "Building Code".  Hope that makes sense & thanks in advance.

2 ACCEPTED SOLUTIONS
saud968
Memorable Member
Memorable Member

Create a Rank Column:

Use the RANKX function to assign a rank to each row based on your priority rule.
You can rank by "VR Account" and then within each "VR Account" rank by the presence of a "Building Code".
Rank = RANKX(ALL('YourTable'), 'YourTable'[VR Account], ASC, 'YourTable'[Building Code], DESC)
Filter for Unique Rows:

Create a new calculated table to filter for the top-ranked row for each "VR Account".
UniqueTable = FILTER(
ALL('YourTable'),
'YourTable'[Rank] = 1
)
Visualize the Result:

Use the UniqueTable in your visualizations to display the desired output.
Example DAX:

Rank = RANKX(
ALL('YourTable'),
'YourTable'[VR Account],
ASC,
IF(ISBLANK('YourTable'[Building Code]), 1, 0),
DESC
)

UniqueTable = FILTER(
ALL('YourTable'),
'YourTable'[Rank] = 1
)

Best Regards
Saud Ansari
If this post helps, please Accept it as a Solution to help other members find it. I appreciate your Kudos!

View solution in original post

Anonymous
Not applicable

Hi @StuartSmith ,

Based on the description, the method @ provided should be helpful.

Besides, try to open power query editor.

vjiewumsft_0-1732528230097.png

Then, add a custom column.

vjiewumsft_1-1732528247343.png

Select the data by custom column in descending.

vjiewumsft_2-1732528257798.png

Remove duplicates by selecting the VR Account column and using the Remove Duplicates option.

vjiewumsft_3-1732528263753.png

The desired result is shown below.

vjiewumsft_4-1732528272712.png

 

Best Regards,

Wisdom Wu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @StuartSmith ,

Based on the description, the method @ provided should be helpful.

Besides, try to open power query editor.

vjiewumsft_0-1732528230097.png

Then, add a custom column.

vjiewumsft_1-1732528247343.png

Select the data by custom column in descending.

vjiewumsft_2-1732528257798.png

Remove duplicates by selecting the VR Account column and using the Remove Duplicates option.

vjiewumsft_3-1732528263753.png

The desired result is shown below.

vjiewumsft_4-1732528272712.png

 

Best Regards,

Wisdom Wu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

saud968
Memorable Member
Memorable Member

Create a Rank Column:

Use the RANKX function to assign a rank to each row based on your priority rule.
You can rank by "VR Account" and then within each "VR Account" rank by the presence of a "Building Code".
Rank = RANKX(ALL('YourTable'), 'YourTable'[VR Account], ASC, 'YourTable'[Building Code], DESC)
Filter for Unique Rows:

Create a new calculated table to filter for the top-ranked row for each "VR Account".
UniqueTable = FILTER(
ALL('YourTable'),
'YourTable'[Rank] = 1
)
Visualize the Result:

Use the UniqueTable in your visualizations to display the desired output.
Example DAX:

Rank = RANKX(
ALL('YourTable'),
'YourTable'[VR Account],
ASC,
IF(ISBLANK('YourTable'[Building Code]), 1, 0),
DESC
)

UniqueTable = FILTER(
ALL('YourTable'),
'YourTable'[Rank] = 1
)

Best Regards
Saud Ansari
If this post helps, please Accept it as a Solution to help other members find it. I appreciate your Kudos!

Thanks, I will try later and let you know the outcome. 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.