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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Conditional Row count

Hello guys, I'm newbie to PowerBI and I need some logical help.

 

I want to count each unique row value as '1' or if duplicate '0". Would appreciate your help. 

 

Thanks,

James

1 ACCEPTED SOLUTION
PurpleGate
Resolver III
Resolver III

Hi, hope this helps

 

In Transform Data:

 

Add index starting from 0

PurpleGate_0-1657019536599.png

 

Group rows by ID, or whatever column you want to be the unique identifier

 

PurpleGate_1-1657019608891.png

 

Expand the table, put the index back in order of ascending then you can delete that column

PurpleGate_2-1657019691268.png

 

 

I then added a conditional column called "duplicated" which I would use in a measure

PurpleGate_3-1657019776687.png

 

 

Then I can see how many times each of rows [Product with the same ID] appear in my table.

PurpleGate_4-1657019823840.png

The measure was

Measure = calculate(COUNTROWS('Table'),FILTER('Table','Table'[Number_of_Items]>1))
 
 

This was my original table:

PurpleGate_5-1657019924427.png    PurpleGate_6-1657020026085.png

 

 

View solution in original post

5 REPLIES 5
KT_Bsmart2gethe
Impactful Individual
Impactful Individual

Hi @Anonymous,

 

You use Group By to do the count then apply the conditional formula.

 

Below code is what I combine the codes for both group by and if formula:

Add a custom step:

Table.Group(TableName/PreviousStep, Table.ColumnNames(TableName/PreviousStep), {{"Count", each if Table.RowCount(_) > 1 then 0 else 1 , Int64.Type}}, GroupKind.Local)

 

Translate:

1. Get all column names from the previous step or a table with Table.ColumnNames(TableName/PreviousStep) ; hence, dynamically pick up all columns.

2. if Table.RowCount(_) > 1 then 0 else 1 , this formula does the count if each row is greater than 1 then 0 else 1

 

Regards

KT

PurpleGate
Resolver III
Resolver III

Hi, hope this helps

 

In Transform Data:

 

Add index starting from 0

PurpleGate_0-1657019536599.png

 

Group rows by ID, or whatever column you want to be the unique identifier

 

PurpleGate_1-1657019608891.png

 

Expand the table, put the index back in order of ascending then you can delete that column

PurpleGate_2-1657019691268.png

 

 

I then added a conditional column called "duplicated" which I would use in a measure

PurpleGate_3-1657019776687.png

 

 

Then I can see how many times each of rows [Product with the same ID] appear in my table.

PurpleGate_4-1657019823840.png

The measure was

Measure = calculate(COUNTROWS('Table'),FILTER('Table','Table'[Number_of_Items]>1))
 
 

This was my original table:

PurpleGate_5-1657019924427.png    PurpleGate_6-1657020026085.png

 

 

Nathaniel_C
Community Champion
Community Champion

Hi @Anonymous 
Here is a great article by that amazing author, @KenPuls .  After you have a count of the duplicates, you can use the conditional column to define no duplicates as 1 or duplicates as 0.


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





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

Proud to be a Super User!




Anonymous
Not applicable

How do we count duplicates?

Hi @Anonymous ,
Sorry, this did not display.  https://www.excelguru.ca/blog/2015/12/09/identify-duplicates-using-power-query/   Go here, a pretty quick read, but essentially you use a groupby and then replace all the columns in a second step.  You end up with one column that has the count of duplicates.  I use this all the time!


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





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

Proud to be a Super User!




Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Kudoed Authors