COUNTIFS with MATCH INDEX (columns and rows)

KrsOne20

New Member
Joined
Dec 5, 2014
Messages
21
So I want to count the number of cells which are not blank or contain '-' in a range conditional based on column and row criteria. For example for firm 006 and period Q1-2011 I want to know the number of cells which are not empty or contain '-'. Answer should be 2.

For this purpose I want to combine COUNTIFS and MATCH INDEX formula. I have provided a screenshot of my data below (file is also included as attachment)

BkZezoM.png


Im using this formula in cell C13, however it keeps returning 1. I think it doesnt look at the whole column but just at the first match of column/header.

Code:
=COUNTIFS(INDEX(A1:E10;MATCH(A13;A1:A10;0);MATCH(B13;A1:E1));"<>";INDEX(A1:E10;MATCH(A13;A1:A10;0);MATCH(B13;A1:E1));"<>—")

Anyone knows how I should adjust my formula? Thanks in advance!

Link to file: https://sheet.zoho.com/sheet/editor...762eed875098bf192d1a6a22ecbce1799f02eedfbf8f2
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Excel 2010
ABCDE
1FirmCaptionQ1-2011Q2-2011S1-2011
26Net Premiums Earned Non - Life638599.91130.1
36Net Premiums Earned - Life548.61290.6
46Gross Premiums Written (Life)557.51329.5
56Gross Premiums Written (Non-Life)881424.61305.6
67Net Premiums Earned Non - Life966.227960.6221926.85
77Net Premiums Earned - Life1112.591031.0662143.66
87Gross Premiums Written (Life)1135.311032.1282167.43
97Gross Premiums Written (Non-Life)1468.11093.7162561.81
10....
11
12
136Q1-20112Should return number of cells which are not blank or contain
Sheet18
Cell Formulas
RangeFormula
C13=SUMPRODUCT(--($A$2:$A$9=A13)*--($C$1:$E$1=B13)*--(ISNUMBER($C$2:$E$9)))


works in your example, but there are no zeroes. If that's a problem I can change the formula.
 
Upvote 0
After getting more into it, I have two minor observations (not a big deal, but maybe it can be fixed):

1) The weird thing is, for firms over #100 it doesn't work. Maybe due to the fact that the the firm number is stored as text (note: both data as my critera number is stored as text). 006 works fine, but 124 for example does not. In other formulas I have no issues looking up these firm numbers. However if I literally copy the number (e.g. 124) from the datasheet shown above and paste as my Lookup criteria it does work (but then the other lookup formulas dont work anymore)

2) Less important but just curious: Is this the only solution or is it still possible to do this with INDEX MATCH? The sumproduct seems quite heavy on the excel sheet (takes longer time to calculate), however Im not sure whether index match (or any other formula) would fix this.
 
Last edited:
Upvote 0
After getting more into it, I have two minor observations (not a big deal, but maybe it can be fixed):
1) The weird thing is, for firms over #100 it doesn't work. Maybe due to the fact that the the firm number is stored as text (note: both data as my critera number is stored as text). 006 works fine, but 124 for example does not. In other formulas I have no issues looking up these firm numbers. However if I literally copy the number (e.g. 124) from the datasheet shown above and paste as my Lookup criteria it does work (but then the other lookup formulas dont work anymore)

2) Less important but just curious: Is this the only solution or is it still possible to do this with INDEX MATCH? The sumproduct seems quite heavy on the excel sheet (takes longer time to calculate), however Im not sure whether index match (or any other formula) would fix this.

The 1st issue got solved by applying trim on the search criteria. For the 2nd if there is no better solution, I can just hardcode the values. But still curious if there is a alternative
 
Upvote 0
Is this any faster?


Excel 2010
ABCDE
1FirmCaptionQ1-2011Q2-2011S1-2011
26Net Premiums Earned Non - Life638599.91130.1
36Net Premiums Earned - Life548.61290.6
46Gross Premiums Written (Life)557.51329.5
56Gross Premiums Written (Non-Life)881424.61305.6
67Net Premiums Earned Non - Life966.227960.6221926.85
77Net Premiums Earned - Life1112.591031.0662143.66
87Gross Premiums Written (Life)1135.311032.1282167.43
97Gross Premiums Written (Non-Life)1468.11093.7162561.81
10....
11
12
136Q1-20112Should return number of cells which are not blank or contain
Sheet18
Cell Formulas
RangeFormula
C13=COUNTIFS($A$2:$A$9,A13,INDEX($C$2:$E$9,,MATCH($B$13,$C$1:$E$1,0)),">=0")


It assumes positive numbers (otherwise there are workarounds)

You can convert numbers stored as text (common when importing from a database) by typing 1 in an unused cell, then copy-paste special-multiply to the range. Or a single line of VBA code. Don't just look at the format though to determine which is which, use the istext/isnumber functions.
 
Last edited:
Upvote 0
Is this any faster?
..

Thanks that defintely made it faster! I also have negative numbers. The workaround I did is the formula below (not the most fancy method, I just added another COUNTIFS to it). Is this the most efficient? Performance is still good tho.

Code:
=COUNTIFS([COLOR=Blue]$A$2:$A$9,A13,INDEX([COLOR=Red]$C$2:$E$9,,MATCH([COLOR=Green]$B$13,$C$1:$E$1,0[/COLOR])[/COLOR]),">=0"[/COLOR])+COUNTIFS([COLOR=Blue]$A$2:$A$9,A13,INDEX([COLOR=Red]$C$2:$E$9,,MATCH([COLOR=Green]$B$13,$C$1:$E$1,0[/COLOR])[/COLOR]),"<0"[/COLOR])
 
Last edited:
Upvote 0
Try

=SUM(COUNTIFS($A$2:$A$9,A13,INDEX($C$2:$E$9,,MATCH($B$13,$C$1:$E$1,0)),{"<0",">=0"}))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,629
Messages
6,120,630
Members
448,973
Latest member
ChristineC

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