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
bvanevr
Frequent Visitor

Count duplicates with having constraint

I am working with data quality visualization and trying to count for duplicates with a filter and not seeing how to accomplish.  Below is some made up data that should help explain issue:

 

BrandChildParentsurrogate
ST1A123
ST2A123
ST3B456
ST4B789
LR5C567
LR6C890

 

First I need a filter for just Brand = ST, then for those that pass the filter I need validate a rule of each Parent has one Surrogate.

This is what I am looking for as Brand LR is not relevant thus Duplicate = NA, Parent A passes the duplicate rule since there is only one surrogate and Parent B Fails because there are multiple surrogates.

BrandChildParentsurrogateDuplicate
ST1A123Pass
ST2A123Pass
ST3B456Failure
ST4B789Failure
LR5C567N/A
LR6C890N/A

 

I have tried both DAX and M (power query) and am not able to get desired resutls.

 

For M I referenced https://www.excelguru.ca/blog/2015/12/09/identify-duplicates-using-power-query/ .  This does not work because Parent A has multiple rows and it count this as a duplicate and for me it is not since it only has one Surrogate.

 

For DAX I referenced https://community.powerbi.com/t5/Desktop/Identify-duplicates-and-show-up-records/td-p/210061.  This does not work because my data set is large and it returns with out of memory error.

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@bvanevr

 

Try This Calculated Column

 

Duplicates =
VAR mycount =
    CALCULATE (
        DISTINCTCOUNT ( TableName[surrogate] ),
        ALLEXCEPT ( TableName, TableName[Parent] )
    )
RETURN
    IF ( TableName[Brand] = "ST", IF ( mycount = 1, "Pass", "Failure" ), "N/A" )

Regards
Zubair

Please try my custom visuals

View solution in original post

3 REPLIES 3
Zubair_Muhammad
Community Champion
Community Champion

@bvanevr

 

Try This Calculated Column

 

Duplicates =
VAR mycount =
    CALCULATE (
        DISTINCTCOUNT ( TableName[surrogate] ),
        ALLEXCEPT ( TableName, TableName[Parent] )
    )
RETURN
    IF ( TableName[Brand] = "ST", IF ( mycount = 1, "Pass", "Failure" ), "N/A" )

Regards
Zubair

Please try my custom visuals

@bvanevr

 

7603.png


Regards
Zubair

Please try my custom visuals

You rock man.

 

I did not realize you could put a formula like that as a VAR.  It also does not impact user experience.

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.