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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
abaak
Frequent Visitor

Count duplicates with condition only once

Hi,

 

I want to count all numbers who are duplicated with condition Custom start once. So when 6966 has two times the condition Custom start, I want to count it as one. there is one in this list (6973) has the condition Custom start 3 times. This one I need to count as 2 times. (The first occurance of custom start is normal and is alright to happen, the second and third time this condition occurs should not happen, this is why I need to make a counter of the total errors).

 

When a number (12495) has condition Return and custom start I do not need to count them. Also when a number has Custom start only once I also do not need to count them (5102).

 

At the end it should return a 9 in a visual, can someone help me with this?


Number          Condition

12495Custom Start
12495Return
2821Custom Start
2821Return
3729Custom Start
6966Custom Start
6966Custom Start
6973Custom Start
6973Custom Start
6973Custom Start
7130Custom Start
7130Custom Start
7444Custom Start
7574Custom Start
7574Custom Start
7604Custom Start
7604Custom Start
7864Custom Start
7864Custom Start
7994Custom Start
7994Return
8120Custom Start
8120Custom Start
8137Custom Start
8137Custom Start
9042Custom Start
9127Custom Start
5102Custom Start
2856Custom Start
2856Return

 

 

 

3 REPLIES 3
Greg_Deckler
Super User
Super User

You should be able to do something like:

 

Measure = 
VAR __table = SUMMARIZE('Table','Table'[Number],"__custom",COUNTROWS(FILTER('Table',[Condition]="Custom Start")),"__return",COUNTROWS(FILTER('Table',[Condition]="Return")))
VAR __table1 = FILTER(__table,[__return]<1)
VAR __table2 = ADDCOLUMNS(__table1,"__final",1)
RETURN
SUMX(__table2,[__final])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Sorry for late response, went on holliday!

 

I thinkt something went wrong with explaining.

 

The only thing it has to count when there is a duplicate of the Number. After that when there is a duplicate in the condition as Custom start. It has to count this as 1. When a Number apears 3 times and the custom start is there 3 times aswell it has to be a 2. For four times it has to be a 3. (see duplicates row in table below, I do not have this row in the table itself)

 

 

NumberConditionDuplicates
12495Custom Start0
12495Return0
2821Custom Start0
2821Return0
3729Custom Start0
6966Custom Start1
6966Custom Start1
6973Custom Start2
6973Custom Start2
6973Custom Start2
7130Custom Start1
7130Custom Start1
7444Custom Start0
7574Custom Start1
7574Custom Start1
7604Custom Start1
7604Custom Start1
7864Custom Start1
7864Custom Start1
7994Custom Start0
7994Return0
8120Custom Start1
8120Custom Start1
8137Custom Start1
8137Custom Start1
9042Custom Start0
9127Custom Start0
5102Custom Start0
2856Custom Start0
2856Return0

 

 

I don't know if it will go like this with the duplicate row. now it only has to count the duplicate one time per number. So then you will get a total of 9.  (7 numbers are duplicated once and 1 number is duplicated twice. This makes 9).

 

My data table is way bigger but what I get with your measure is way to high then I should.  Can you help me any further?

Cmcmahan
Resident Rockstar
Resident Rockstar

You should be able to make a minor adjustment to Greg's query then.  Notice the section in blue, which makes the measure ignore the first instance of a number/condition pair.

 

CountDupes = 
VAR __table = SUMMARIZE('Table', 'Table'[Number], 'Table2'[Condition], "Dupes", COUNTROWS('Table')-1)
RETURN
SUMX(__table, [Dupes])

You can also go about it this way, which has better performance, as long as the only columns in your input table are Number and Condition:

CountDupesAlt = COUNTROWS('Table') - COUNTROWS(DISTINCT('Table'))

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.