Array formula with multiple Countifs

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
939
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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
939
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
 

FormR

MrExcel MVP
Joined
Aug 18, 2011
Messages
6,517
Office Version
  1. 365
Platform
  1. Windows
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))))
 

Marcelo Branco

MrExcel MVP
Joined
Aug 23, 2010
Messages
16,558
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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:

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
939
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 :)
 

Watch MrExcel Video

Forum statistics

Threads
1,132,794
Messages
5,655,339
Members
418,190
Latest member
Timex

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
Top