Forum Discussion

bvanevr's avatar
bvanevr
Advocate II
8 years ago
Solved

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.

  • 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" )

3 Replies

  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    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" )
      • bvanevr's avatar
        bvanevr
        Advocate II

        You rock man.

         

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