I am trying to work out working formula for CountIF with criteria which is out of the range and I am not sure if "If and Count" would be any differen. Nonetheless, the combination I am trying brings "0" which is certainly not correct.
Can someone please take a look and help?
https://drive.google.com/file/d/0B0aOVjxZjuyrSjdXWG9acWlZMDA/view?usp=sharing
I am trying =COUNTIF(B12:B11511, $A$2=A12:A11511) and have no idea if this will work or not?
Countif(s) for B2 - B8
Thanks a lot.
As you are looking at two cirteria you want to use COUNTIFS:
=COUNTIFS($A$11:$A$11511,A2,$B$11:$B$11511,1)
Put in B2 and copy down. It will count any that match the country and are marked with 1 in column B.
To count the 0, just change the last criterion:
=COUNTIFS($A$11:$A$11511,A2,$B$11:$B$11511,0)
To count both together just sum the two. It can be done two ways:
Add them manually:
=COUNTIFS($A$11:$A$11511,A2,$B$11:$B$11511,1) + COUNTIFS($A$11:$A$11511,A2,$B$11:$B$11511,0)
Use SUM:
=SUM(COUNTIFS($A$11:$A$11511,A2,$B$11:$B$11511,{0,1})
But by your data, which only has 1s and 0s, this formula will return the same numbers.
=COUNTIF($A$11:$A$11511,A2)
Which counts the number of cells in A that match A2.
Use this in B2,
=sum(countifs($A$12:$A$11511, MID($A2, 8, 2), $B$12:$B$11511, {0, 1}))
That counts US with ones and zeroes. Fill down to row 8.
Related
I hope someone can help, I am looking for a formula solution to the following problem if possible.
I have a column of people's names, and for each of those people I have 3 columns of data from 3 different sources - I need to determine how many times the data in those 3 columns matches for each person. After extensive Googling, I could only find solutions where the result is summarised in a cell derived from a COUNTIF range, however I need the results summarised in the same row for each person.
For example:
"Dave" is in cell A2, his results were: column B2 = FAIL, C2 = PASS and D2 = PASS - so in this instance we have 2 matches as there were 2 passes.
"Sue" is in cell A3, her results were: column B3 = FAIL, C3 = FAIL and D3 = FAIL - so in this instance we have 3 matches as there were 3 Fails.
"Colin" is in cell A4, his results were: column B4 = TBA, C4 = FAIL and D4 = PASS- so in this instance we have 0 matches as none of the results match.
Ideally, I would like the number of matches listed down in column E for each individual person, so Dave's matching results would be cell E2, Sue's would be in E3 and Dave's in E4.
Many thanks in advance for your help.
Kindest regards,
TE
You could try:
Formula in E1:
=INDEX({0,2,3},MAX(COUNTIF(B1:D1,B1:D1)))
A bit of explaination for those who are curious:
COUNTIF(B1:D1,B1:D1) - Will result in an array of three values (1 per column), on how often these values appear in the three cells.
MAX() - Get's the max value from the previous array.
INDEX({0,2,3}) - Since the outcome of MAX() can only be 1-3 we can feed this as the row parameter into an INDEX() function. This will then result in either 0, 2 or 3.
A little less verbose and possibly more explicit would be:
=MIN(((B1=C1)+(C1=D1)+(B1=D1))*2,3)
With this last formula we use the fact that TRUE and FALSE are the equivalent of 1 and 0, and therefor we can add multiple boolean values. With some math we can then get our wanted result.
You can use IF() MAX() and COUNTIF combined.
In E2:
=IF(MAX(COUNTIF(B2:D2,B2),COUNTIF(B2:D2,C2),COUNTIF(B2:D2,D2))=1,0,MAX(COUNTIF(B2:D2,B2),COUNTIF(B2:D2,C2),COUNTIF(B2:D2,D2)))
So it does three separate countif to see how many is "duplicated" from each cell.
Takes the max of them and compare against 1, if that is true then return 0, else return what the max value was.
Would something like this work, in column E?
=if(countif(B2:D2,B2)=3,3,if(countif(B2:D2,B2)=2,2,if(countif(B2:D2,C2)=2,2,0)))
Let me know if that works for you.
I want to get the count of cells used in an excel function.
For example say I have a sum function ='CV'!D11+Farmer!D11+'County'!D11+Rt!D11+WT!D11+'Country'!D11
I need a function that will tell me how many cells were used to get the total sum. In this case it is 6. The tricky part is if one of the cells used is blank I do not want it counted. For instance say cell D11 on the Farmer sheet is blank I do not want it counted in the total. So the total should be 5.
Use COUNT:
=COUNT('CV'!D11,Farmer!D11,'County'!D11,Rt!D11,WT!D11,'Country'!D11)
It will only count the cell if it has a number
You should really try to collate all your data in to a single sheet before running calculations. For the sake of example, I'll assume you have it in the range A1:A5, then you can add handling of the various cases using array formulas:
Get the count of non-empty cells (the ISBLANK function is untrustworthy in my experience): {SUM(IF(LEN(A1:A5)>0,1,0))}
Get the sum of those cells: SUM(A1:A5)
(must use Ctrl+Shift+Enter to enter the formula as an array formula, you will know it worked if the formula shows like {IF(...)} with the curly brackets)
Because blank/missing values are treated implicitly as 0 in the SUM function, this case is simple. If you have other validations then you'd have to write an array formula for the summation as well. For example, only including numbers between a min and max threshold (e.g. if you want to exclude outliers):
{SUM(IF(AND(A1:A5 >= yourMinValue, A1:A5 < yourMaxValue), A1:A5, 0)}.
If I understand your question correctly, you want to literately count the number of cells used in a formula which in your example is summing 6 values from 6 different locations.
I used the following example to demonstrate my solution:
The sum of =A1+B1+C1+D1+E1+F1 is 10 where cell C1 has a 0 value in it but cell E1 is blank.
Using the following array formula I was able to count the number of cells that have a value other than 0:
=SUMPRODUCT(IFERROR(ABS(N(INDIRECT(TRIM(MID(SUBSTITUTE(RIGHT(FORMULATEXT(A3),LEN(FORMULATEXT(A3))-1),"+",REPT(" ",100)),100*ROW(INDIRECT("1:"&LEN(FORMULATEXT(A3))))-99,100)))))>0,0)*1)
Please note you MUST press Ctrl+Shift+Enter upon finishing the formula in the formula bar otherwise they will not function correctly.
The logic is to use a combination of TRIM+MID+SUBSTITUTE+RIGHT+FORMULATEXT+REPT+ROW+INDIRECT to extract the cell addresses from the original formula, then use INDIRECT to convert the cell address into the values stored in those cells, then use a combination of IFERROR+ABS+N to find out if any of these values are not 0, and lastly use SUMPRODUCT to add up all the TRUE results.
It is obvious that there are a couple limitations of my solution:
If your actual formula is not strictly in the form of A+B+C+D+E+F, then my SUBSTITUTE part of formula will need further modification;
The formula will treat cells containing 0 as blank and does not include them in the count.
Let me know if you have any questions. Cheers :)
The question is slightly confusing, so I will do my best to elaborate. I have a series of cells in a row with all of the cells in the row with a value of 0 and one cell having a value of 1. I want to use the COUNT function to count all of the cells to the right of the cell that contains the value of 1, including that cell. I would then use this number of counted cells in another equation. Does anyone have any suggestions on how to do this? I have tried using a lookup function inside of the count function, but it has not worked. This is my closest guess:
=COUNT(Lookup(1,A1:J1):J1)
This results in an error. Do I need to use VBA to make this work or should I be able to write an equation? I appreciate the help, or if there are any other strategies that I can use to attain the result I am looking for.
Edit: I am adding in some sample data and expected results. I am trying to count all of the cells to the right of the "1" including the cell containing the "1". So in this example, I would expect the formula to return "13" as there are 12 cells to the right of the "1"
You can use OFFSET() and MATCH():
That last "50" is a bit of a guess since I'm not sure how far to the right you want to count...
...and re-reading your question it's not clear if you only want to count values of 1 or if you also need to count other values as long as they're to the right of the first 1.
With data in A1 through J1, consider:
=10-MATCH(1,A1:J1,0)+1
In this case. 4 is the number of cells from G1 through J1, inclusive.
Assuming your range of 0 and 1 values is in row 2, starting from column B, use this formula in B3 and copy it across for as far as you need:
=IFERROR(COUNT($B2:B2)+1-MATCH(1,$B2:B2,0),0)
You could also use a formula of
=IF(A3>0,1+A3,IF(B2=1,1,0))
but that could cause issues if you have something in cell A3 itself.
You can use this formula:
=COUNTA(INDEX($A$1:$J$1,1,MATCH(1,$A$1:$J$1,0)):INDEX($A$1:$J$1,1,10))
The benefit to use this is it is not a volatile function, and it will also work for 1 appears in the last column.
You can use "COUNTIF" formula to count number of occurrences of specific number in a range of cells.
To count no of occurrences in a row.
=COUNTIF(1:1,1)
If it is in a column then
=COUNTIF(A:A,1)
Hope you are looking for a countif function.
COUNTIF(A1:A10, 1)
The above function counts the cell that has value 1 within the range A1:A10
Is there a formula without using VB to sum up a total number form a specific range of data?
For example:
Example
I need to sum up the number of times Mary took up the cooking lesson.
I understand that just by using the sum and manually select the range (B3:D3) I will be able to get it. But is there a formula to determine the range (B3:D3) instead?
Please advise. Thanks
The use of the merged cells in row 1 necessitates building a range with a pair of INDEX functions which is then re-examined with another INDEX to pick the row of data with a MATCH function. Once the range has been defined, a SUM function produces the result.
The formula in C10 is,
=SUM(INDEX(INDEX($B$3:$J$6, 0, MATCH($B10, B$1:J$1, 0)):INDEX($B$3:$J$6, 0, MATCH($B10, B$1:J$1, 0)+2), MATCH($A10, $A$3:$A$6, 0), 0))
Fill down as necessary.
How do I average a list of numbers whose values are greater than 0? I know I can use AVERAGEIF function in Excel
My data is located in A2, A5, A6, A10, A17.
I only want to average it if the data is greater than 0.
Since my data is not an range, I am not able to use AVERAGEIF Function range.
Need some help on this.
EDIT
For example,
I tried with three numbers:
1) 98.068 and 98.954 and 0 so my forumla looked like this:
=AVERAGE(IF(N(OFFSET(A2,{0,5,10},))>0,N(OFFSET(A2,{0,5,10},))))
The answer came out as 99.106. Not sure why.
A few options:
1)=SUM(SUMIF(INDIRECT({"A2","A5","A6","A10","A17"}),">0"))/SUM(COUNTIF(INDIRECT({"A2","A5","A6","A10","A17"}),">0"))
2)=AVERAGE(IF(N(INDIRECT({"A2","A5","A6","A10","A17"}))>0,N(INDIRECT({"A2","A5","A6","A10","A17"}))))
3)
=AVERAGE(IF(N(OFFSET(A2,{0,3,4,8,15},))>0,N(OFFSET(A2,{0,3,4,8,15},))))
2) and 3) must be committed as array formulas**
Regards
(0) A simple method
=SUM(A2*(A2>0),A5*(A5>0),A6*(A6>0),A10*(A10>0),A17*(A17>0))/SUM(A2>0,A5>0,A6>0,A10>0,A17>0)
(4) A more general method
=SUM((A1:A20>0)*A1:A20*(ADDRESS(ROW(A1:A20),1,4)={"A2","A5","A6","A10","A17"}))/
SUM((A1:A20>0)*(ADDRESS(ROW(A1:A20),1,4)={"A2","A5","A6","A10","A17"}))
The second one is an array formula and must be entered with CtrlShiftEnter
If it's possible to have text in the cells rather than numbers, then this should replace the first formula:-
=SUM(N(A2)*(A2>0),N(A5)*(A5>0),N(A6)*(A6>0),N(A10)*(A10>0),N(A17)*(A17>0))/SUM(N(A2)>0,N(A5)>0,N(A6)>0,N(A10)>0,N(A17)>0)
(I haven't used N in the > brackets in the numerator because I reason that if A2 etc. is text, the product will always be zero)
I can't persuade N to work with arrays in the second formula, so at the moment I have the rather lengthy
=SUM((IF(ISNUMBER(A1:A20),A1:A20,0)>0)*IF(ISNUMBER(A1:A20),A1:A20,0)*(ADDRESS(ROW(A1:A20),1,4)={"A2","A5","A6","A10","A17"}))/
SUM((IF(ISNUMBER(A1:A20),A1:A20,0)>0)*(ADDRESS(ROW(A1:A20),1,4)={"A2","A5","A6","A10","A17"}))
but I have tested it on text values and negative numbers and it does seem fine.
The only exception is if one of the cells contains TRUE. In this case the first formula will count it as 1, the second formula will ignore it.