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.
Related
I have values
AA,BB,CC
AA,CC
AA
AA,BB
BB
BB,CC
CC
CC,AA
CC,BB
BB,CC,DD
find all cells that have. how do I search for each values.
AA,BB = 2
BB,CC = 4
Example
COUNTIFS($A:$A,"*AA*",$A:$A,"*BB*") doesn't seem to work.
You could try this using wildcards * with TEXTBEFORE() & TEXTAFTER()
• Formula used in cell D2
=COUNTIFS(A1:A10,"*"&TEXTBEFORE(C2,",")&"*",A1:A10,"*"&TEXTAFTER(C2,",")&"*")
EDIT
As suggested by Tom Sharpe Sir,
• Formula used in cell D2
=LET(x,TEXTSPLIT(C2,","),y,COUNTA(x),
SUM(--(MMULT(N(ISNUMBER(SEARCH(x,$A$1:$A$10))),SEQUENCE(y,,1,0))=y)))
You could try:
Formula in D2:
=MAP(C2:C5,LAMBDA(z,SUM(MAP(A1:A11,LAMBDA(x,LET(y,TEXTSPLIT(z,,","),N(SUM(N(TEXTSPLIT(x,",")=y))=ROWS(y))))))))
Note: My answer assumes no duplicates in the values in column A:A. e.g.: AA,AA.
How about:
=LET(searchvalues, C2,
data, $A$1:$A$10,
split, TEXTSPLIT(searchvalues,","),
count, COLUMNS(split),
SUM(
--(MMULT(
--ISNUMBER(SEARCH(split,data)),
SEQUENCE(count,,1,0))
=count)))
It splits the values you want to search (stored in C2 in my example) into individual values: split
Than split is searched within each row of your data.
This returns TRUE or FALSE wrapped in -- changes TRUE to 1 and FALSE to 0.
This is used within MMULT and this returns the sum of the occurrences of each individual split value. Finally the MMULT result needs to equal the number of splitted search values.
The sum of this being true is the end result.
The following approach considers a variable number of words to search, not just 2 words as in the input sample:
=LET(lk, B1, A, $A$1:$A$11, lks, TEXTSPLIT(lk,, ","),
byr, BYROW(A, LAMBDA(x,SUM(COUNTIF(x,"*"&lks&"*")))), SUM(N(byr=ROWS(lks))))
It has a caveat that if the word is repeated more than one time per row in the first column, it is counted as 1, as you can see in the following output. This is because of how COUNTIF (or COUNTIFS) works with wildcards (other answers provided using SEARCH produce the same result). If that assumption is ok, then it works. The rest is just to drag the formula down (formula1).
UPDATE: Considering #JvdV's comment, to avoid false positive when the word to search could be a substring of the column A on a given row. Like for example, searching the word AA, in the string: AAA will produce a false positive. The following version avoids it:
=LET(lk, B1, A, $A$1:$A$11, lks, TEXTSPLIT(lk,, ","),
byr, BYROW(A, LAMBDA(x, SUM(N(TEXTSPLIT(x,",") = lks)))), SUM(N(byr=ROWS(lks))))
Here is the output:
I added intentionally the highlighted cases to test additional situations. Row 11 repeats the word: AA, and BB, but it is counted as 1 in the final result.
The following approach tries to identify the total number of counts considering repetitions of the word in column A (formula2):
=LET(lk, B1, A, $A$1:$A$11, lks, TEXTSPLIT(lk,, ","),
byr, BYROW(A, LAMBDA(x, LET(match, IFERROR(TOCOL(XMATCH(TEXTSPLIT(x, ","),
lks),2),0), ux, UNIQUE(match), IF(ROWS(ux) < ROWS(lks), 0,
MIN(MMULT(TRANSPOSE(N(match = TOROW(ux))), SEQUENCE(ROWS(match),,1,0))))))),
SUM(byr))
Now we get the following result:
Now we get an additional count for the case of AA, BB.
In formula2, match has the index position as a result of the XMATCH call, we use TOCOL to remove non-found values #N/A. In case no words were found, we use IFERROR to assign the zero value. The IF condition:
IF(ROWS(ux) < ROWS(lks)
Ensures to calculate non-zero counts only if all words were found. We use MMULT to calculate per row the number of repetitions of the lookup words. We take the minimum, to ensure we only consider the scenarios where all the words are present. There could be a situation, where one of the lookup words has more counts than another one, which is why we take the minimum. Therefore we are counting the entire set of lookup words found regardless of the order,
Answer was
COUNTIFS($A:$A,"*"&$C$2&"*",$A:$A,"*"&$C$3&"*")
C2 = AA
C3 = BB
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.
I am trying to create a formula that will count an ID in one column if it means several criteria in another column. Other formulas I've seen are close to what I want but none consider ID.
My data look like this:
The formula you see in the formula box is the closest thing I could get but it sums up the number of times it gets all the criteria.
My wish list simplified is:
to get a 1 in Column G based on ClientEnrollmentID if Column C has
"Initial" OR "Annual".
same as above except "Initial" AND "Annual".
For example, 1074328692 (the first ClientEnrollmentID--H2) should be 1 for the first wish and 0 for the second wish.
1074331324 (second row--H3-H5) should be 1 because it satisfies the two wishes (it would be okay for 1 to appear in multiple rows for the ClientEnrollmentID).
My third wish is that someone can help me with this. Thanks!
Just math. Maybe this can help:
=MIN(COUNTIFS(H:H, H:H, C:C, "Initial") + COUNTIFS(H:H, H:H, C:C,"Annual"), 1)
=COUNTIFS(H:H, H:H, C:C, "Initial") * COUNTIFS(H:H, H:H, C:C, "Annual")
A COUNTIFS function can be given OR criteria in the form of an array of constants if you wrap it in a SUM function.
The formula in G2 is,
The second wish can be derived as either a 1 or 0 with an AND function.
If they have to be in one cell, you could concatenate them together with something like a division symbol separating them like this.
Of course, that renders them completely ineffective for any totaling or mathematical comparison without parsing the string.
I need a formula that will look up a value in a 2-dimensional range and return the coordinates or cell address of the matching cell. For example:
R A B C
1 John Matt Pete
2 Sara Bret Chad
3 Lila Maya Cami
I want to search the range A1:C3 for Chad and return C2 or 2,3. How can I accomplish this using Excel formulas? (I'll actually end up applying this to Google Sheets).
Thanks!
Old question, but I thought I'd share a much simpler and elegant answer here that doesn't involve helper columns or complicated formulas, so that more people will get things done easier. Assuming that the table contains unique values and that you use E1 to store your search string Chad and E2 to display the result:
if you want the row and column result of 2,3 in E2:
=SUMPRODUCT((A1:C3=E1)*ROW(A1:C3)) & "," & SUMPRODUCT((A1:C3=E1)*COLUMN(A1:C3))
if you want the R1C1 style cell address string of C2 in E2:
=ADDRESS(SUMPRODUCT((A1:C3=E1)*ROW(A1:C3)),SUMPRODUCT((A1:C3=E1)*COLUMN(A1:C3)))
if you want the found cell's contents of Chad in E2:
=INDIRECT(ADDRESS(SUMPRODUCT((A1:C3=E1)*ROW(A1:C3)),SUMPRODUCT((A1:C3=E1)*COLUMN(A1:C3))))
How things work:
SUMPRODUCT returns in this case the sum of the products between a boolean array of TRUE (searched value found in cell) and FALSE (searched value not found in cell) for every cell in the table and the corresponding row/column (absolute) numbers of those cells in the sheet; thus, the result is essentially the row/column (absolute) number of the cell where the value has been found, since TRUE=1 and FALSE=0 in mathematical terms
ADDRESS returns a cell's address as text (not as reference!)
INDIRECT returns the reference corresponding to a cell's text address
Source and credit goes to: this answer by XOR LX. Could have added the link in a comment, mentioning the duplicate question, but I wanted to expand and explain the answer a little bit, therefore more characters were needed.
Assuming you're using Excel 2007 and above.
You will need a helper column. If your table looks like in your example, in cell D1 write:
=IFERROR(MATCH($E$1,$A1:$C1,0),0)
And drag it down. Then in cell E1 write your search value ("Chad" for instance). Then you have your search result in cell E2 with this formula:
=IF(MAX($D:$D)=0,NA(),MATCH(MAX($D:$D),$D:$D,1)&","&MAX($D:$D))
If you want a simpler solution, it is possible to use only one helper (or not at all, at the cost of a complicated formulae).
Let's say I take your example. I will use the D column to display result :
In D1, I put the name I want to find : Chad
In D2, I put the helper that will return an Index of the value searched (-1 if not found) : =IFERROR(MATCH(D1,SPLIT(TEXTJOIN(";",TRUE,A1:C3),";"),0),-1)
In D3, I put the formulae to get the row,column value (FALSE if not found) : =IF(D2<>-1,ROUNDUP(DIVIDE(D2,COLUMNS(A1:C3))) & "," & IF(MOD(D2,COLUMNS(A1:C3))=0,COLUMNS(A1:C3),MOD(D2,COLUMNS(A1:C3))))
If you really want to use only one formulae, it is possible in D3 to replace all references to D2 by the formulae used in D2.
This formula returns the row and column number of a given value in a two-dimensional array.
=LET(
array, B2:D4,
findvalues, C7,
arrayrows, ROWS(array),
arraycols, COLUMNS(array),
rowindex, SEQUENCE(arrayrows*arraycols,,1,1/arraycols),
colindex, MOD(SEQUENCE(arrayrows*arraycols,,0),arraycols)+1,
flatarray, INDEX(array,rowindex,colindex),
valueflatindex, MATCH(findvalues,flatarray,0),
valuerow, ROUNDUP(valueflatindex/arraycols,0),
valuecol, MOD(valueflatindex-1,arraycols)+1,
absvaluerow, MIN(ROW(array))+valuerow-1,
absvaluecol, MIN(COLUMN(array))+valuecol-1,
CHOOSE({1,2},absvaluerow,absvaluecol)
)
A B C D E
1
2 John Matt Pete
3 Sara Bret Chad
4 Lila Maya Cami
5
6
7 find: Chad
8 formula: 3 4
More precisely, this formula scans a given array row by row and returns the address of the first occurrence of a given value.
If you need the row and column numbers relative to the array's top left cell, then in CHOOSE(...), instead of absvaluerow/absvaluecol, use valuerow/valuecol.
If you want the values to be comma separated and in one cell, instead of CHOOSE(...), use absvaluerow & "," & absvaluecol
If your Excel version does not support the latest functions, such as LET, the formula should still work if you rewrite it so that it does not use the LET variables.
Find Multiple Values
You can also find multiple values in an array using this formula as explained in my answer in this thread.
I have a row that will have weekly values entered. Column B has the initial value, and E has the calculation; as I add values to C, D and so on, I want the calculation to skip the previous columns value when the next column gets a value.
B1-C1=E1 BUT when a value is added to D1, E1 would update to B1-D1=E1
Sorry for the horrible description. This is probably answered somewhere on this site but I am not sure what terms to search.
Many thanks!
you can use an if statement. I am not 100% sure of your problem but something like this might be helpful.
if(A1, A1, 0)
So for your example provided.
=B1-if(D1, D1, C1)
This says if there is a value in D1 use D1 else use C1. This works in this example, because if
D1 is empty or 0 you will use the other cell. This may change for any given problem.
Use this if function in E1:
=IF(D1>0,B1-D1,IF(C1>0,B1-C1,B1))
Then enter a value in B1, then C1 then D1 to see the results.
According to your question, you only have room for two entries after the default B1 value. This statement will handle that.
If you need more fields, nest more if functions. But if's can only be nested 7 deep, so you can only have an initial value in B1 and 7 more cells, C1 to I1 with your formula in J1
If you actual data is as simple as your sample data you could just use:
=IF(LEN(D2)>0, B2-D2,B2-C2)
You could also use:
=IF(ISBLANK(D2), B2-C2, B2-D2)
if you prefer but Len is a little shorter and I believe the ISBLANK() function has flaws, If you have a formula in D2 that has a calculation and you set the result to "" then it will pick up as false. It depends on your needs.
I would do the following.
In E1 paste the following:
=A1-INDEX(B1:D1,1,COUNT(B1:D1))
The count formula will tell how many values are present in the range of B:D column. This will be used to catch the last column with an index formula which will be deducted form A1.
One thing is very important! The values from A to D has to be written in sequence, if one column is missing than the calculation will be false.
Hope I could help!