Using vlookup and count in the same formula - excel

I am having difficulties combining Vlookup value with count.
As you can see here, CPR is a unique code for every employee and next to it is the type of mistakes that specific employee did.
In this sheet, i want to count the number of mistakes done by that specific employee from the first sheet which mean the code should only count the cells that only contain value.
Thank you.

You can use following formula:
=SUMPRODUCT(($A$1:$A$10=E2)*NOT(ISBLANK($B$1:$B$10)))

I think you want to use Excel's countif function. I don't think vlookup is helpful here.
For example, if you write =countif(G4:G999, 8345) it will count how many times the number 8345 occurs in that range of cells.

You could use:
=COUNTIF(Jan!G:G,Sheet13!D1)
The above formula count how many times the value in Sheet13!D1 appears in Jan!G:G

Related

Use VLOOKUP as criteria inside COUNTIFS

After years of using this community, I have a question that I can't find an answer to. I hope you all can help!
I am trying to get a count of the number of "Grounded" items that each individual is overdue for. My screenshot (Count Tracker) shows a very condensed version of what I'm working with. Columns A-C is my large (15,000 rows) data field that is imported from an external source. In columns G-H I have listed each possible task (about 100 rows) and the type (Grounded and Non-Grounding plus many others). Column F is where I am trying to get the count.
My formula in F9 currently uses COUNTIFS to get a count of the instances in the large array that equal E9 ("Smith" in this case) and where the due date in the large array is less than or equal to the current date in F8. What I can't figure out is how to also add to count the Tasks in the large array where the task type in Column H equals "Grounded". I tried VLOOKUP, but it seems it doesn't like it and tells me there is a problem with the formula. It doesn't work, but here's the general idea of what I'm after:
=COUNTIFS($A$2:$A$7,$E9,$C$2:$C$7,"<="&$F$8,VLOOKUP($B$2:$B$7,$G$2:$H$4,2,FALSE),"=Grounded")
With how the data is currently presented, Smith should have a count of 1 and Jones should have a count of 0. I have a feeling that this is more simple than I'm making it to be, but I can't figure it out. I am using Excel 2016.
Hopefully I explained the problem well enough. Thank you for your assistance.
With Excel 2016 I'd say MMULT() is a good alternative here:
CSE-Formula in F9:
=SUM((A$2:A$7=E9)*(MMULT((TRANSPOSE(G$2:G$4)=B$2:B$7)*(TRANSPOSE(H$2:H$4)="Grounding"),ROW(G$2:G$4)^0))*(C$2:C$7<=F$8))
You could add a fourth column that stores whether that Task is Grounded
The formula for D2 would then be:
=INDEX($H$2:$H$4,MATCH(B2,$G$2:$G$4,0))
Modify your CountIfs formula to use this new column as a criteria
=COUNTIFS($A$2:$A$7,$E9,$C$2:$C$7,"<="&$F$8,$D$2:$D$7, "Grounded")
Try this Sumproduct+Vlookup formula without helper solution, and can work for your Excel 2016
In F9, formula copied down :
=SUMPRODUCT((A$2:A$7=E9)*(VLOOKUP(T(IF({1},$B$2:$B$7)),G$2:H$4,2,0)="Grounded")*($C$2:$C$7<=$F$8))

How to Exclude 0 values from my =Count formula?

DESPERATE for any help :-)
I need to exclude 0 values from my =COUNT excel formula in order to get an automated frequency value feeding another formula in my model.
Actual Base Formula:
=COUNT(J10,J11,J12,N10,N11,N12,J14,J15,J16,N14,N15,N16)
I am trying to get the formula to NOT count when any of these cells have O values. For instance, if J10 is greater than 0, include it in the count.
I have tried several different "IF" statements, but am failing miserably!
I basically need to dummy proof this by automating it versus having users simply count the cells with values and enter the number into the frequency field for my score calculator. Thanks so much for any help!!
Since your range is disjointed the best method is four(4) countifs:
=COUNTIF(J10:J12,">0")+COUNTIF(N10:N12,">0")+COUNTIF(J14:J16,">0")+COUNTIF(N14:N16,">0")
Fixed based on the comments.
=COUNTIF(J10:J12,">0")+COUNTIF(N10:N12,">0")+COUNTIF(J14:J16,">0")+COUNTIF(N14:N16,">0")

Count number of next cells based on criteria

Can we have a formula or a VBA code for counting number of next cells based on criteria.
For instance if we have a list
A
A
B
A
C
and we would like to count number of A's after A (the criteria), so in this case, it would be 1
If you just want to know the number of times A is followed by A then you can use a formula like this
=COUNTIFS(A1:A5,"A",A2:A6,"A")
Assuming your data is in A1:A5
This will also allow you to find out how many times A is followed by B or any other combination by changing the criteria
Use SUMPRODUCT():
=SUMPRODUCT(($A$1:$A$5="A")*($A$2:$A$6=$A$1:$A$5))
The simplest possible solution that I can think for this problem is
=IF(A2<>A1,0,INDEX(MATCH(FALSE,A2:A100=A1,0),1,1)-1)

Using WEEKDAY function inside a COUNTIFS

I want to count the times John was in the blue room and it was a thursday. I played with COUNTIFS and WEEKDAY and checked the documentation.
I tried COUNTIFS with two conditions but got errors or 0 as a result.
As #Gary'sStudent said with the column with the day already in place you do not need the WEEKDAY a simple COUNTIFS will work:
=COUNTIFS(B:B,"Thursday",C:C,"John")
If you did not have that column then you would need to revert to the SUMPRODUCT() formula similar to what #Gary'sStudent has:
=SUMPRODUCT((WEEKDAY(A4:A17)="Thursday")*(C4:C17="John"))
Both formulas will work, the main difference is that the COUTNIFS() is not an array formula, and therefore you are able to use full column references without detriment. The SUMPRODUCT, to minimize calc times, one would need to reference only the dataset.
Consider:
=SUMPRODUCT(--(B4:B17="Thursday")*(C4:C17="John"))
You do not need WEEKDAY() because you have a column that specifically defines each day.

How can I find the spreadsheet cell reference of MAX() in a range?

With a column range of A1:A20 I have found the largest number with =MAX(A1:A20). How can I find the reference (e.g. A5) of the MAX() result?
I'm specifically using Google Spreadsheets but hope this is simple enough to be standard across excel and Google Spreadsheets.
=MATCH(MAX(A1:A120),A1:A120,0)
The problem is if you get more than one match: it will only give you the first one.
Either :
=ADDRESS(MATCH(MAX($A:$A),$A:$A,0),1)
if you know it's going to be in column A (1)
Or:
=CELL("address",INDEX($A:$A,MATCH(MAX($A:$A),$A:$A,0)))
And yes, it only gives you the first match
You can use something on the lines of the following
=MATCH(MAX(E7:E9),E7:E9)
This will give you the offset from the formula to the biggest number. If you use this in conjunction with ADDRESS you could get the actual cell. However, using offset should probably help you get there if you want to do something on that cell, or another number in the same row as that cell
As of now, there is a QUERY formula that can help with this situation
=ARRAYFORMULA(query({ROW(A2:A), A2:A},
"SELECT MAX(Col1)
WHERE Col2 IS NOT NULL
ORDER BY Col2 DESC"))
ROW(A2:A) represents the row number of each row which you can use the result with ADDRESS to create a reference to a cell.

Resources