Array formula with multiple Countifs

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
950
Office Version
  1. 2019
Platform
  1. Windows
I am using this formula which works fine:

=IF(ROWS(K$62:K62)>SUM(COUNTIFS(accounts_table[§],{"P","B"})),"",INDEX(accounts_table[Account Name],SMALL(IF(ISNUMBER(MATCH(accounts_table[§],{"P","B"},0)),ROW(accounts_table[§])-ROW(INDEX(accounts_table[§],1,1))+1),ROWS($K$62:K62))))

However, I need to add another COUNTIFS criteria:

COUNTIFS(accounts_table[§],{"P","B"},accounts_table[on],"On")

If I only make this change, the function doesn't work as expected. I presume I also need to change the second part of the function but can't figure out how.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
It it helps now, this is the structure of my spreadsheet

col A col B col C
P on item1
P off item2
B on item3
J on item4
P on item5
B off item6

So in the above example the array formula should pick item1, item3,item5

Hope it makes sense
 
Upvote 0
Hi, try like this, committed with CTRL+SHIFT+ENTER.

Code:
=IF(ROWS(K$62:K62)>SUM(COUNTIFS(accounts_table[§],{"P","B"},accounts_table[on],"on")),"",INDEX(accounts_table[account name],SMALL(IF(accounts_table[on]="on",IF(ISNUMBER(MATCH(accounts_table[§],{"P","B"},0)),ROW(accounts_table[§])-ROW(INDEX(accounts_table[§],1,1))+1)),ROWS($K$62:K62))))
 
Upvote 0
EDIT
I hadn't seen FormR's formula that used table references. Solution already provided!

Try

A
B
C
D
E
1
Header1​
Header2​
Header3​
List​
2
P​
on​
item1​
item1​
3
P​
off​
item2​
item3​
4
B​
on​
item3​
item5​
5
J​
on​
item4​
6
P​
on​
item5​
7
B​
off​
item6​
8

<tbody>
</tbody>


Array formula in E2 copied down
=IF(ROWS(E$2:E2)>SUM(COUNTIFS(A$2:A$7,{"P","B"},B$2:B$7,"On")),"",INDEX(C$2:C$7,SMALL(IF(ISNUMBER(MATCH(A$2:A$7,{"P","B"},0)),IF(B$2:B$7="on",ROW(C$2:C$7)-ROW(C$2)+1)),ROWS(E$2:E2))))
Ctrl+Shift+Enter

M.
 
Last edited:
Upvote 0
Hi, try like this, committed with CTRL+SHIFT+ENTER.

Code:
=IF(ROWS(K$62:K62)>SUM(COUNTIFS(accounts_table[§],{"P","B"},accounts_table[on],"on")),"",INDEX(accounts_table[account name],SMALL(IF(accounts_table[on]="on",IF(ISNUMBER(MATCH(accounts_table[§],{"P","B"},0)),ROW(accounts_table[§])-ROW(INDEX(accounts_table[§],1,1))+1)),ROWS($K$62:K62))))

thanks this works as expected :)
 
Upvote 0

Forum statistics

Threads
1,213,514
Messages
6,114,078
Members
448,547
Latest member
arndtea

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