Excel - CountIfs using column header and value from other column as criteria? - excel

I am trying to produce a countifs formula to put in a cell on sheet 1, that will count the number of entries for ID 'A' on sheet 2.
But also i need to add a criteria to say only count the entries where the date in the column header on sheet 2 matches the date in the column header on sheet 1.
Sheet1
ID 01/01/2016
A 1 (Formula goes here)
B 0 (Formula goes here)
C 1 (Formula goes here)
D 1 (Formula goes here)
Sheet2
ID 01/01/2016
A 1pm - 2pm
B
C 1pm - 2pm
D 1pm - 2pm
I am really struggling to get this to work. so far i have put together this, but it doesn't have the criteria for the dates.
=SUMPRODUCT((Data!$A$2:$A$1000=$A2)*(Data!$D$2:D$1000="$D$1"))
Please can somemone show me where i am going wrong?

Try something closer to,
=SUMPRODUCT(($F$2:$K$9<>"")*($F$1:$K$1=$B$1)*($E$2:$E$9=$A2))
I've put everything on one worksheet but you should have no trouble splitting it off to Sheet2.
      

Related

Count cell per month

I look for a code for the number of times a value is in a cell, on a monthly basis
So
1-1-19 KS
2-1-19
3-1-19 KS
.
.
1-2-19 KS
2-2-19
3-2-19
January 2
February 1
is this possible?
Assume that your dates are in column A, your KS is in column B.
In cell D1:D12 you have the first of each month entered and given a custom number format of mmmm so it just shows January, February, etc.
The formula =MATCH($D1,$A:$A,0) will give the row number that the month starts on.
For simplicity I'll call this Start_Row.
The formula =MATCH(EOMONTH($D1,0),$A:$A,0) will give the row number that the month ends on.
I'll call this End_Row.
The formula INDEX($B:$B,Start_Row):INDEX($B:$B,End_Row) will set a reference in column B to all rows between the first of the month and the end of the month.
I'll call this CountRange.
Now you just need to count what's in that reference using either:
=COUNTIF(CountRange,"KS") to count just KS
=COUNTA(CountRange) to count any non-blank cells.
So the full formula, without any helper columns, would be:
=COUNTIF(INDEX($B:$B,MATCH($D1,$A:$A,0)):INDEX($B:$B,MATCH(EOMONTH($D1,0),$A:$A,0)),"KS")
Keeping in mind that D1 contains 01/01/2019

how to get next non empty cell value in an excel column

Here is my excel looks
Column A Column B
1/1/2016
2/1/2016
3/1/2016
4/1/2016
5/1/2016
.
.
.
31/1/2016 1000
Now I will be referring one of the date in this month on another sheet and I would like to pull Column B value corresponding to last date on each month. There wont be any value till last date on column B.
Any hint to do this ?
First step is to make the condition:
=IF(A1=EOMONTH(A1,0),B1,"")
Note: if date in A1 is really the end of its month, it takes result from B1
Second step is to combine it with Vlookup. I assume that you would input some date in column C:
=IF(C1=EOMONTH(A1,0),VLOOKUP(C1,$A$1:$B$1000,2,FALSE),"")
Third step is... you can change the formula if your input is in another sheet. For the example: the data are in "sheet1" and the date input are in column C at "sheet2":
=IF(C1=EOMONTH(Sheet1!A1,0),VLOOKUP(C1,Sheet1!$A$1:$B$1000,2,FALSE),"")
Hope it'll help.

COUNTIFS with range criteria on different sheets

I have not read if there is a limitation with COUNTIFS function, but I am experiencing the following:
I want to count the number the number of times two conditions are true in a row. For example
Sheet 1
USERID DATE
SAM 12/1/2014
SAM 12/3/2014
SAM 12/4/2014
JON 12/3/2014
BOB 11/5/2014
Sheet 2
Dates to match against {12/3/2014, 12/4/2014, 12/5/2014}
Sheet 3
USERID DATECount
SAM 2
JON 1
BOB 0
If all this information is in the same sheet the following formula works (Assuming data in Sheet 1 is in columns A and B, and the data in Sheet 2 is in the first row D to F, and the data in Sheet 3 starts at D5.
=COUNTIFS(A:A,D5,B:B,"="&$D$1:$F$1)
Currently, to get over this, I have a SUM function and a COUNTIFS for each criteria in the range for criteria 2. But it's pretty ugly since there are 20 criteria.
What I trying to find is a more elegant way to do this, or if there is another function that can return the same results.
Note that the date range can change every month.
You need a SUMPRODUCT wrapper that will iterate the COUNTIFS results through the cells in Sheet2!$D$1:$F$1.
      
The formula in Sheet3!E5 is,
=SUMPRODUCT(COUNTIFS(Sheet1!A:A,D5,Sheet1!B:B,Sheet2!$D$1:$F$1))
Fill down as necessary.

Countif formula with multiple criteria

In my workbook, I have a 4 spreadsheets - Data, Amy, Betty, Connie. Data has the following columns:
Column A Column B Column C Column D
Row 3 Employee Total tasks last 30 days. Total tasks last 7 days. Date/Time Last task Assigned
Row 4 Amy
Row 5 Betty
Row 6 Connie
In A1 - worker with oldest task Date/Time Assigned. Cell B1 contains the answer to cell A1 by providing the employees name.
I enter the data in the individual workers spreadsheets (Amy, Betty, Connie) and my Data worksheet provides the summary. On my data worksheet, I have formulas that count the number of tasks within the last 7 days and last 30 days by using the date/time assigned column (Column E)in the individual worksheets. Currently, if someone is out of the office, on their individual worksheet, I enter OUT in the task column (Column B) and the date/time that they will return in the date/time assigned column (Column E)so it will skip them for B1 on my Data worksheet. I need a formula that would not count the date/time assigned if they were OUT as a task, when calculating in columns B and C in the data worksheet.
Here is the formula that I have currently for Column B (total tasks last 30 days)
{=COUNTIF(INDIRECT("'"&A4&"'!"&"E1:E1000"),">="&(NOW()-30))}
The formula that I have for cell B1 is:
{=INDEX(A4:A14,MATCH(MIN(E4:E14),E4:E14,0))}
Any help would greatly be appreciated.
I figured it out:
=COUNTIFS(Amy!E2:E1000,">="&(NOW()-30),Amy!A2:A1000,"<>out")
Like suggested in the comments, the COUNTIFS formula is what you want to use. Information about its usage can be found here.
Adding the condition for excluding the "OUT" values would make the formula look like this:
=COUNTIFS(INDIRECT(""&A4&"!"&"E1:E1000"),">="&(NOW()-30),INDIRECT(""&A4&"!"&"B1:B1000"),"<>OUT")

SUMIF statement returns a value from the incorrect row

My current formula on Worksheet1 is below:
SUMIF(Setup!$C$5:$C$375,"C-R",'PMS Input'!$K$13:$K$416)
On the Setup worksheet, I have confirmed that there is only one C-R in column C.
Row C39 C-R CAMPSITES
Row C40 G-S GROUP SHELTER
Row C41 G-S PICNIC SHELTER
Row C42 P-A SQUIRREL'S NEST
Row C43 P-A MISC. PARK REVENUE/VENDING
Row C44 P-A MINIATURE GOLF
Row C45 P-A CANOE RENTALS
Row C46 P-A BICYCLE RENTALS
Row C47 P-A PROGRAMMING FEES
Row C48 P-A MISC. PARK REVENUE/VENDING
On the PMS Input worksheet, the rows are as follows:
Row K48 CAMPSITES 9 18.25
Row K49 GROUP SHELTER - -
Row K50 PICNIC SHELTER - -
Row K51 SQUIRREL'S NEST - (195.00)
Row K55 BICYCLE RENTALS - -
Row K57 PROGRAMMING FEES - 108.00
Row K58 MISC. PARK REVENUE/VENDING - -
On Worksheet1, the value returned for the above formula looking for C-R is 0.
The actual responses should be C-R = 18.25. The incorrect response in consistent throughout the file.
I have three other locations using the same file, with no issues using the above formula.
Another formula issue:
=SUMIF($B$63:$D$82,"TIPS",R$63:R$82)
This formula is returning a value of 17, however there is no 17 in column R. The 17 is actually in column T. This same error is repeating on several other days.
I have compared, checked and re-checked the formulas, but to no avail.
Could this just be a problem with the overall worksheet, or have I been staring at my numbers too long?
On the second issue you need to know that SUMIF always works on a "one to one" basis. That means that both ranges need to be the same size and shape. If the second range isn't the same size and shape as the first then Excel implicitly makes it so, starting from the top left cell of range 2.
In short that means that with your formula like this:
=SUMIF($B$63:$D$82,"TIPS",R$63:R$82)
The sum range is extended to be the same size as the criteria range so that formula will do the same as this
=SUMIF($B$63:$D$82,"TIPS",R$63:T$82)
Note: second range covers 3 columns like the first. If any value in colums C and D are "TIPS" it will sum the relevant value from column S or T, so that's probably where your 17 comes from.
Can you explain in words what you are trying to do with this formula? Do you want to sum column R only if any value in B, C or D is equal to "TIPS" - what if all 3 cells are equal to "TIPS" in one row, do you want to sum column R 3 times for that row?
Your lookup and your values are not aligned correctly. C-R is on C39, and the value is on K48. They are 9 rows apart. However the lookup and values in your equation start eight rows apart.
So either you have an extra row in PMS or missing a row in Setup, or you just started at the wrong row and something like this would fix it:
SUMIF(Setup!$C$5:$C$375,"C-R",'PMS Input'!$K$14:$K$416)
SUMIF(Setup!$C$4:$C$375,"C-R",'PMS Input'!$K$13:$K$416)
to fix the second issue you'll need the following formula (based on the great detail provided by barry in his answer)
=SUMIF($B$63:$B$82,"TIPS",$R$63:$R$82)+SUMIF($C$63:$C$82,"TIPS",$R$63:$R$82)+SUMIF($D$63:$D$82,"TIPS",$R$63:$R$82)

Resources