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

Counting only duplicates when condition is TRUE

Hi all, 

Hope to get some help here. I have a situation where I only want to count the UniqueID that has duplicates. Right now it is giving me 6 counts where as I expect to get only 4 accounts when selecting only Apple and Banana. 

 

DataTable

UniqueIDAttributeValue
31464GrapesFALSE
31464AppleTRUE
31766AppleTRUE
31464CoconutTRUE
31471AppleFALSE
31471GrapesFALSE
31471BananaFALSE
31471CoconutFALSE
36033AppleTRUE
31766CoconutFALSE
36390AppleTRUE
31766GrapesFALSE
31464BananaTRUE
32420AppleFALSE
32420GrapesFALSE
32420CoconutFALSE
32624GrapesFALSE
32624AppleFALSE
32624BananaFALSE
32624CoconutFALSE
35764AppleFALSE
35764GrapesTRUE
31766BananaTRUE
35764CoconutTRUE
32420BananaTRUE
36033GrapesTRUE
35764BananaTRUE
36033CoconutFALSE
36033BananaTRUE
36390BananaTRUE
36390GrapesFALSE
36390CoconutFALSE

 

Expected result when choosing Apple and Banana only, with True. 

UniqueIDAttributeValue
31464AppleTRUE
31464BananaTRUE
31766AppleTRUE
31766BananaTRUE
36033AppleTRUE
36033BananaTRUE
36390AppleTRUE
36390BananaTRUE
32420BananaTRUE
35764BananaTRUE

Untitled.png

 

 

 

 

 

 

 

Hope to get some help, thanks.

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@fever003,

 

Try this measure:

 

Count UniqueID Duplicates = 
SUMX (
    --iterate the distinct UniqueIDs in the filter context
    VALUES ( DuplicateCount[UniqueID] ),
    --current UniqueID
    VAR vUniqueID = DuplicateCount[UniqueID]
    --return the rows for the current UniqueID in the filter context
    VAR vUniqueIDRows = FILTER ( ALLSELECTED ( DuplicateCount ), DuplicateCount[UniqueID] = vUniqueID )
    --if the current UniqueID has more than one row, assign a count of 1
    VAR vUniqueIDCount = IF ( COUNTROWS ( vUniqueIDRows ) > 1, 1 )
    RETURN
        vUniqueIDCount
)

 

DataInsights_0-1606578989498.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
mahoneypat
Employee
Employee

Here is another similar way to do it.

 

IDs with Duplicates =
COUNTROWS (
    FILTER (
        DISTINCT ( UniqueDuplicates[UniqueID] ),
        CALCULATE (
            COUNTROWS ( UniqueDuplicates ) = 2
        )
    )
)

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thanks, this works too! 

DataInsights
Super User
Super User

@fever003,

 

Try this measure:

 

Count UniqueID Duplicates = 
SUMX (
    --iterate the distinct UniqueIDs in the filter context
    VALUES ( DuplicateCount[UniqueID] ),
    --current UniqueID
    VAR vUniqueID = DuplicateCount[UniqueID]
    --return the rows for the current UniqueID in the filter context
    VAR vUniqueIDRows = FILTER ( ALLSELECTED ( DuplicateCount ), DuplicateCount[UniqueID] = vUniqueID )
    --if the current UniqueID has more than one row, assign a count of 1
    VAR vUniqueIDCount = IF ( COUNTROWS ( vUniqueIDRows ) > 1, 1 )
    RETURN
        vUniqueIDCount
)

 

DataInsights_0-1606578989498.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you! This is the solution I needed because it works with Filter context and I can add many other slicers to it. You're the best!

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.