You are here:

Excel/Index-Match-Countif?

Advertisement


Question
QUESTION: Hi,

I have a summary sheet (sheet 2, called January_SUM") for each month (Obviously renaming each month). I need to count the number of times an employee went to a certain location (only tracking how many times they went to Chicago, Boston, or Raleigh).

In sheet one ("January_Data"), the data to answer that question is provided. The unique identifier in both sheets is their employee number.

How it will work is that the WB will be set up with a January_Data sheet that will be empty until I paste the data in from another location. As you can see, it will provide the employee number in col-A and locations in B-E.

Sheet 1 "January_Data" below:

     col-A     Col-B   Col-C   Col-D   Col-E
Row-1 4467   Chicago   Boston   Raleigh   Raleigh   
Row-2 7230   Boston   Raleigh   Boston      
Row-3 213   Boston   Chicago   Raleigh   Chicago   
Row-4 99321   Raleigh   Raleigh   Boston   Raleigh   
Row-5 23187   Boston   Boston   Chicago   Boston


Sheet 2 "January_SUM" below:

  Col-A   Col-B   Col-C   Col-D  Col-E          
1: Name    Emp. #  Chicago Boston Raleigh
2: Smith   23187         
3: Jones   49983      
4: Doe     213         
5: Clemens 4467         
6: Reid    7230         
7: Kelly   1092         
8: Pappack 99321

So I need a formula to put in Col-C that will look on the January_Data sheet and find the employee number that matches the January_Sum sheet and counts the number of times Chicago appears in that employees row (on the January_Data sheet). I can then copy-fill down and use the formula on the next two columns by just changing the location in the formula I assume.

I was trying to put together an Index-Match-Countif formula thinking that was the way to go but got nowhere, (likely because I just don't have enough experience yet).

Thank you for taking the time to assist me (and thereby help teach me).

-Josh

ANSWER: Josh,

If you are using Excel 2007 or later, in C2 of January_Sum you can put in the formula

=countifs(January_Data!$A:$A,$B2,January_Data!$B:$E,C$1)

Note that the function is COUNTIFS with an "S" on the end.  This was added to excel in Excel 2007 and allows you to specify multiple criteria.

You can then copy this to the right, then select the cells with the formula (C2:E2 and fill down the columns

The C$1 picks up the city name from the top row (the $ fixes the row reference) for the same column so you don't have to edit the formula.  The $B2 fixes the column reference to column B and gets the employee number for that row.  

That should do what you want.

--
Regards,
Tom Ogilvy


---------- FOLLOW-UP ----------

QUESTION: I am getting a "value" error. From what I can gather by reading online, the error appears to be a result of the two ranges not having the same number of columns.

This statement caught my attention when looking for a resolution in an online excel forum:"Each additional range must have the same number of rows and columns as the first range (criteria_range1 argument)."

When I separate the criteria 1 range, criteria and the criteria 2 range, criteria as stand alone formulas, they work. However, I need them to work together since knowing how many times all the employee went to Chicago isn't what I need. I need to know how many times each employee went to each location.

Thank you for any clarification you might be able to provide.

Answer
Josh,

Your correct.  I wasn't thinking that through.  I was thinking of a different approach using array formula.   This is tested on your data and worked for me:

c2: =COUNTIFS(January_Data!$A:$A,$B2,January_Data!$B:$B,C$1)+COUNTIFS(January_Data!$A:$A,$B2,January_Data!$C:$C,C$1)+COUNTIFS(January_Data!$A:$A,$B2,January_Data!$D:$D,C$1)+COUNTIFS(January_Data!$A:$A,$B2,January_Data!$E:$E,C$1)

drag across and then fill down.

Produced:
Name   Emp No.   Chicago   Boston   Raleigh
Smith   23187   1   3   0
Jones   49983   0   0   0
Doe   213   2   1   1
Clemens   4467   1   1   2
Reid   7230   0   2   1
Kelly   1092   0   0   0
Pappack   99321   0   1   3

--
Regards,
Tom Ogilvy  
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 About.com. All rights reserved.