Formulas to count duplicate rows on sheet

Deutz

Board Regular
Joined
Nov 30, 2009
Messages
191
Office Version
  1. 365
Platform
  1. Windows
Hi and thanks in advance,

I'm wondering how to build a couple of formulas that don't use a helper column/concat column. One formula should count duplicate rows (on a single sheet) including the first occurrence of the duplicate. The second formula should count duplicate rows (on a single sheet) and NOT include the first occurrence of the duplicate. The sheet can have multiple columns.

Thanks
Deutz
 
This seemed to work : =SUM(IF(COUNTIFS($A$1:$A$10,IF(ISBLANK(A1:A10),"",A1:A10),$B$1:$B$10,IF(ISBLANK(B1:B10),"",B1:B10),$C$1:$C$10,IF(ISBLANK(C1:C10),"",C1:C10))>1,1,0)). So, the criteria for each column becomes "" if the cell is empty. But this will count empty rows too (if you have 2 empty rows, it will increase the result).

You can affect this change to the 2nd formula too I guess!
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
This seemed to work : =SUM(IF(COUNTIFS($A$1:$A$10,IF(ISBLANK(A1:A10),"",A1:A10),$B$1:$B$10,IF(ISBLANK(B1:B10),"",B1:B10),$C$1:$C$10,IF(ISBLANK(C1:C10),"",C1:C10))>1,1,0)). So, the criteria for each column becomes "" if the cell is empty. But this will count empty rows too (if you have 2 empty rows, it will increase the result).

You can affect this change to the 2nd formula too I guess!

Thanks for your help with this, it is much appreciated. I will try to implement your suggestion with the second formula as well.

Cheers
Deutz
 
Upvote 0
Hi NotoriousPopol,

I modified your first formula to count all dupes except for the blank row dupes ...

{=SUM(IF(COUNTIFS($A$1:$A$10,IF(ISBLANK(A1:A10),"",A1:A10),$B$1:$B$10,IF(ISBLANK(B1:B10),"",B1:B10),$C$1:$C$10,IF(ISBLANK(C1:C10),"",C1:C10))>1,1,0))-IF(SUMPRODUCT(--(A1:A10=""),--(B1:B10=""),--(C1:C10=""))>1,SUMPRODUCT(--(A1:A10=""),--(B1:B10=""),--(C1:C10="")),"")}

Don't know if there is a simpler way to achieve this but it seems to get the right count without the blank dupe rows counted.



For your second formula, to get the count of dupes without first occurrence ...

=SUM(IF(COUNTIFS($A$1:$A$10,A1:A10,$B$1:$B$10,B1:B10)>1,(COUNTIFS($A$1:$A$10,A1:A10,$B$1:$B$10,B1:B10)-1)/COUNTIFS($A$1:$A$10,A1:A10,$B$1:$B$10,B1:B10),0))

... I am still trying to get it working in the cases where there are no values in some columns. Not sure how to implement the ISBLANK functions since there is also division involved in this formula?

Thanks
Deutz
 
Last edited:
Upvote 0
Hi, did you try to simply replace each 2nd argument of COUNTIFS with the IF(ISBLANK()) statement? No problem for the division, you do it only if the value is >1. The formula is quite ugly tho...
 
Upvote 0
Are the following what you are after?

1. In E1 control+shift+enter, not just enter:
Rich (BB code):
=SUM(IF(FREQUENCY(MATCH(A1:A8&"|"&B1:B8&"|"&C1:C8,A1:A8&"|"&B1:B8&"|"&C1:C8,0),ROW(A1:A8)-ROW(A1)+1),1))

2. In E2 control+shift+enter:
Rich (BB code):
=SUM(IF(LEN(A1:A8&B1:B8&C1:C8),1))-E1
 
Upvote 0
Could you explain a bit your formula Aladin? Seems interesting and much more efficient. But it doesn't give me the correct result in my Test workbook.
 
Upvote 0
Could you explain a bit your formula Aladin? Seems interesting and much more efficient. But it doesn't give me the correct result in my Test workbook.

I'm not sure about the specs the OP has provided. You seem to think otherwise. We can either wait for a reaction by Deutz or you post a small sample with the associated expected results.
 
Upvote 0
I'm not sure about the specs the OP has provided. You seem to think otherwise. We can either wait for a reaction by Deutz or you post a small sample with the associated expected results.

Hi Aladin and NotoriousPopol,

Thanks for your assistance.

I will try to make my specs a bit clearer.

Here is an example of what I'm trying to count for the first formula which should include all duplicate rows (in red) but not include blank rows, so the count would be 5 ...

1
aaa
x
1
aaa
x
4e
2
r
zz
2
r
1
aaa
x

<tbody>
</tbody>

Here is an example of what I'm trying to count for the second formula which should include duplicate rows (in red) but not include the first occurrence or blank rows, so the count would be 3 ...

1
aaa
x
1
aaa
x
4e
2
r
zz
2
r
1
aaa
x

<tbody>
</tbody>

Hope this is a bit clearer. Sorry about the table formatting which shows the blank rows a bit narrower than those with data.

thanks
Deutz
 
Last edited:
Upvote 0
Control+shift+enter...

[1]
Rich (BB code):
=SUM(IF(FREQUENCY(IF(LEN(A1:A9&B1:B9&C1:C9),MATCH(A1:A9&"|"&B1:B9&"|"&C1:C9,A1:A9&"|"&B1:B9&"|"&C1:C9,0)),
    ROW(A1:A9)-ROW(A1)+1)>1,FREQUENCY(IF(LEN(A1:A9&B1:B9&C1:C9),
    MATCH(A1:A9&"|"&B1:B9&"|"&C1:C9,A1:A9&"|"&B1:B9&"|"&C1:C9,0)),ROW(A1:A9)-ROW(A1)+1)))

[2]
Rich (BB code):
<strike></strike>=SUM(IF(FREQUENCY(IF(LEN(A1:A9&B1:B9&C1:C9),MATCH(A1:A9&"|"&B1:B9&"|"&C1:C9,A1:A9&"|"&B1:B9&"|"&C1:C9,0)),
     ROW(A1:A9)-ROW(A1)+1)-1>0,FREQUENCY(IF(LEN(A1:A9&B1:B9&C1:C9),
     MATCH(A1:A9&"|"&B1:B9&"|"&C1:C9,A1:A9&"|"&B1:B9&"|"&C1:C9,0)),ROW(A1:A9)-ROW(A1)+1)-1))<strike></strike>
 
Upvote 0
Control+shift+enter...

[1]
Rich (BB code):
=SUM(IF(FREQUENCY(IF(LEN(A1:A9&B1:B9&C1:C9),MATCH(A1:A9&"|"&B1:B9&"|"&C1:C9,A1:A9&"|"&B1:B9&"|"&C1:C9,0)),
    ROW(A1:A9)-ROW(A1)+1)>1,FREQUENCY(IF(LEN(A1:A9&B1:B9&C1:C9),
    MATCH(A1:A9&"|"&B1:B9&"|"&C1:C9,A1:A9&"|"&B1:B9&"|"&C1:C9,0)),ROW(A1:A9)-ROW(A1)+1)))

[2]
Rich (BB code):
<strike></strike>=SUM(IF(FREQUENCY(IF(LEN(A1:A9&B1:B9&C1:C9),MATCH(A1:A9&"|"&B1:B9&"|"&C1:C9,A1:A9&"|"&B1:B9&"|"&C1:C9,0)),
     ROW(A1:A9)-ROW(A1)+1)-1>0,FREQUENCY(IF(LEN(A1:A9&B1:B9&C1:C9),
     MATCH(A1:A9&"|"&B1:B9&"|"&C1:C9,A1:A9&"|"&B1:B9&"|"&C1:C9,0)),ROW(A1:A9)-ROW(A1)+1)-1))<strike></strike>

Thanks Aladin, that is impressive and works as required. I understand you are concatenating the column values with a pipe character in the MATCH and that makes sense to me but not sure how the next bit works in the FREQUENCY ... ROW(A1:A9)-ROW(A1)+1
Are you able to briefly shed some light on that? It is a bit hard for me to visualize how that works in an array formula.

Thanks also to NotoriousPopol for your helpful suggestions.

Regards
Deutz
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,892
Members
449,194
Latest member
JayEggleton

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top