Count based on on criteria

ORoxo

Board Regular
Joined
Oct 30, 2016
Messages
149
Hello, everyone
I have three columns, F, AC and E. On column F I have the name of a Risk and on AC I have the department which have identified such risk. I'm trying to give a serial code to risks on colum E. Things to consider:

- Each department can identify the same risk more than once. In such case, the serial code should be the same
- Each time the department changes I would like the serial code to reset the counting (regardless of the name of the risk)

This is what I have so far:

Code:
=IF(COUNTIFS(F$2:F2;F2;AC$2:AC2;AC2)=1;MAX(E$1:E1)+1;INDEX($E$2:E2;MATCH(F2;$F$2:F2;0)))

I think I was able to address the first point. However, I can't figure out how to manage the second one.

Could you help me out?
Thanks!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Could we have a small set (say 10-12 rows) of dummy sample data (in columns A & B would do) and the expected results for that sample data (in column C would do)?
 
Upvote 0
Could we have a small set (say 10-12 rows) of dummy sample data (in columns A & B would do) and the expected results for that sample data (in column C would do)?

Sure, Peter.

This is what I'm looking for:

Capture.png


If you want that sample data:

https://ufile.io/5gfym
 
Last edited:
Upvote 0
In C2 control+shift+enter, not just enter, and copy down:

=IF(ISNUMBER(MATCH($A2&"|"&$B2,$A$1:A1&"|"&$B$1:B1,0)),INDEX($C$1:C2,MATCH($A2&"|"&$B2,$A$1:A1&"|"&$B$1:B1,0)),SUM(IF(FREQUENCY(IF(1-($A$2:A2=""),IF($B$2:B2=B2,MATCH($A$2:A2,$A$2:A2,0))),ROW($A$2:$B2)-ROW(INDEX($A$2:$B2,1,1))+1),1)))
 
Upvote 0
In C2 control+shift+enter, not just enter, and copy down:

=IF(ISNUMBER(MATCH($A2&"|"&$B2,$A$1:A1&"|"&$B$1:B1,0)),INDEX($C$1:C2,MATCH($A2&"|"&$B2,$A$1:A1&"|"&$B$1:B1,0)),SUM(IF(FREQUENCY(IF(1-($A$2:A2=""),IF($B$2:B2=B2,MATCH($A$2:A2,$A$2:A2,0))),ROW($A$2:$B2)-ROW(INDEX($A$2:$B2,1,1))+1),1)))

Ok, this some wizardry...but it worked perfectly though.

Can you please explain what does in practice using &"|"&?

Thanks!
 
Last edited:
Upvote 0
If you have MAXIFS and MINIFS, you could use this standard-entry formula in C2, copied down.
=IF(COUNTIF(B$2:B2,B2)=1,1,IF(COUNTIFS(A$1:A1,A2,B$1:B1,B2),MINIFS(C$1:C1,A$1:A1,A2,B$1:B1,B2),MAXIFS(C$1:C1,B$1:B1,B2)+1))

Otherwise you could use this (also standard-entry)
=IF(COUNTIF(B$2:B2,B2)=1,1,IF(COUNTIFS(A$1:A1,A2,B$1:B1,B2),INDEX(C$1:C1,MATCH(A2&"|"&B2,INDEX(A$1:A1&"|"&B$1:B1,0),0)),AGGREGATE(14,6,C$1:C1/(B$1:B1=B2),1)+1))
 
Upvote 0
Ok, this some wizardry...but it worked perfectly though.

Can you please explain what does in practice using &"|"&?

Thanks!

You are welcome. The | symbol is used as preacaution against undesired results which might occur due to concatenation like in A and 01 vs A0 and 1. Both would end up as A01 instead of A|01 and A0|1.
 
Upvote 0
If you have MAXIFS and MINIFS, you could use this standard-entry formula in C2, copied down.
=IF(COUNTIF(B$2:B2,B2)=1,1,IF(COUNTIFS(A$1:A1,A2,B$1:B1,B2),MINIFS(C$1:C1,A$1:A1,A2,B$1:B1,B2),MAXIFS(C$1:C1,B$1:B1,B2)+1))

Otherwise you could use this (also standard-entry)
=IF(COUNTIF(B$2:B2,B2)=1,1,IF(COUNTIFS(A$1:A1,A2,B$1:B1,B2),INDEX(C$1:C1,MATCH(A2&"|"&B2,INDEX(A$1:A1&"|"&B$1:B1,0),0)),AGGREGATE(14,6,C$1:C1/(B$1:B1=B2),1)+1))

It also worked, Peter. Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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