Using COUNTIFS with a range as criteria - excel

I have a situation where in I have to use COUNTIFS(range1, Criteria1, Range2, Criteria2...), where criteria should be a range in the same excel that has text in it. Is there a way for that?
My actual situation is
Sheet 1 : col A and Col B - Text values
Sheet 2 : Col C and Col D - Text values
For every value in Col A, check if it is there in Col C, the take the corresponding value from Col D and check if it is the same in Col B. I need the count of how many matches or doesn't match. I tried to use Vlookup on this, but couldn't get what I wanted. I appreciate your suggestions on this.
Thanks,
Ramya

The example uses a Named Table.
{=COUNT(IF(([#ColA]=[#ColC])*([#ColD]=[#ColB]),1))}
COUNT method counts the number of values.
([#ColA]=[#ColC])*([#ColD]=[#ColB]) compares the current row's Column A value against Column C value, then returns True/False then the same thing for Column D value against Column B value, and multiplies them together to get:
True
from True * True
or
False
from True * False or False * True or False *False`)
And when the IF statement is True, it returns 1 to be used in the COUNT.
You can use an Array Formula to calculate whether a specific row in a table matches your criteria, then add the ones that do match up.
Ctrl + Shift + Enter to create the Array Formula.

Related

Searching a column for a string in one array, and returning a value that corresponds to that array

I am going to do my best to describe this.
I want to search column C for any of the strings contained on a different sheet in column A, and if/when one of those strings is found, i want to return the column B that corresponds to the found string.
For example:
Sheet 1:
Column A
Column B
Column C
project 1
2/15/19
Status is Red, because....
Project 2
4/12/20
RAG- Green, PTG is....
And on another sheet I have common ways to describe their statuses in Column A, and in Column B, a simple letter R, A, G or NS (Not started) if no other common status is found.
Column A
Column B
Column C
Status is Red
R
Rag- Green
G
How can I Search Column C for a value on Column A (on a different sheet) and return column B in Column D on the original sheet?
Results should look like
Column A
Column B
Column C
Column D
project 1
2/15/19
Status is Red, because....
R
Project 2
4/12/20
RAG- Green, PTG is....
G
This may be a bit of an extended function and depends on how many rows you have in the second sheet.
You can hard code it with
=IF(ISNUMBER(SEARCH("Red",C2)),VLOOKUP("Status is Red",Sheet2!$A$2:$B$3,2,FALSE),IF(ISNUMBER(SEARCH("Green",C2)),VLOOKUP("RAG - Green",Sheet2!$A$2:$B$3,2,FALSE),"NS"))
Or use the more dynamic:
=IF(ISNUMBER(SEARCH(Sheet2!$A$2,Sheet1!C2)),VLOOKUP(Sheet2!$A$2,Sheet2!A2:B3,2,FALSE),IF(ISNUMBER(SEARCH(Sheet2!$A$3,Sheet1!C2)),VLOOKUP(Sheet2!$A$3,Sheet2!$A$2:$B$3,2,FALSE),"NS"))
Explanation
SEARCH(find_text,within_text) - returns the index of where the substring begins
ISNUMBER(value) - returns TRUE if a number, FALSE if not.
VLOOKUP(lookup_value,table_array,col_index_num,[range_lookup]) - finds the value within the array and returns the corresponding value in the specified column.
$X$Y - the dollar signs stop the values from changing when you use ctrl+d or ctrl+r to fill multiple cells
So to break it down:
IF (search returns an index)
THEN VLOOKUP (find this value and return the corresponding value from this column)
ELSE (repeat above as needed)
ELSE ("NS")

How to select certain rows in Excel that meet logical criteria of A & B

I have an excel sheet in CSV that has 8 columns A-H and thousands of rows with values 0 or 1 depending on truth value.
I'm looking for the Excel function in which I can select rows where column A and B are true so that I can check another columns probability given A&B. IE P((A&B)|D) (where | means given).
I'm really new to excel and having difficulties finding how to only select rows that meet this criteria.
The following formula entered in I1 will return a 1 if both A1 and B1 are true.
=IF(AND($A1=1,$B1=1),1,0)
Copy it down or autofill to identify all rows where A and B are true.
The $ sign before A and B make the column references absolute meaning if you drag the formula to the right, the references to columns A and B will remain.
Because Excel implicitly interprets 0 = FALSE and 1 (or any other number) = TRUE the formula could be shortened to:
=IF(AND($A1,$B1),1,0)
The probability of C being 1 given that A and B are 1 can be calculated by counting all rows where A, B and C are all 1 and dividing by the number of rows where both A and B are 1:
=COUNTIFS($A:$A,"1",$B:$B,"1",C:C,"1")/COUNTIFS($A:$A,"1",$B:$B,"1")
Again, references to A and B are absolute, while C is relative so you can drag right to get probabilities for columns D to H.
COUNTIFS only counts the rows where all of the criteria are met and allows you to specify up to 127 range/criteria pairs.
EDIT
You could also use:
=AVERAGEIFS(C:C,$A:$A,1,$B:$B,1)
to get the probability.

Excel- How do I Find and Replace using the values from adjacent columns

I'm a complete newbie to excel so apologies for my lack of knowledge!
I have a spreadsheet with 3 columnns.
Column 1 has cells with a range of values that can be repeated several times ie A B C A A D.
Column 2 has a list of the unique values in column 1 ie A B C D.
Column 3 contains the values that I would like to updated Column 1 with ie a b c d.
What I need to do is search Column 1 using Column 2 as an array of values when a match is found replace it with the adjacent value in column 3. Ie find all the A's in Column 1 and replace with a.
I did start writing a very long if statement if value = A replace with a etc but I have hundreds of unique values so I'm sure this isn't the most verbose way
Thanks in advance for your help
Consider the use of VLOOKUP
Result = Application.WorksheetFunction.Vlookup ( lookup_value, table_array, col_index_num, [range_lookup] )

Sum of multiple columns if they match

I have this table of data:
A B C D E
003B1016 1 003G1016 1 003B1016
003G1015 1 003G1391 2 003G1015
003H0121 4 003H6208 2 003H0121
003H6209 1 003H6209 1 003H6209
I want to sum B+D if A and C are identical , how would i do that?
I have another 32000 rows of data. :) Thanks for the help
Put this in cell E1 and copy down:
=IF(A1=C1,B1+D1,"")
This says - if A = C, then add B+D. Otherwise, return blank "".
EDIT for new requirements
In order to add all amounts from column B where column A matches the current row and from column D where column C matches that row, where the row in column A exists anywhere and the row in column C exists anywhere, do the following formula in E2 and drag down:
=IF(ISERROR(MATCH(A2,A$1:A1)),IF(ISERROR(MATCH(A2,C:C,0)),"",SUMIFS(B:B,A:A,A2)+SUMIFS(D:D,C:C,A2)),"")
This says: look above the current row in column A - have we seen this item before? If no, continue with the formula. If yes, ignore, to avoid double counting. Then, Look at all of column C - does the value in the current row of A occur anywhere in column C? If no, then don't add anything. If yes, Add all items from column B where column A matches the current row, and add all items from column D where column C matches the current row.

When B2=B1 AND C2=C1, return result of 1

I have a spreadsheet sorted by alphabetical order in Column B. I want a formula that yields a '1' in an extra Column E when B2=B1 AND C2=C1.
Column B is Account Name and Column C is state, I am looking for Name/State matches.
In E2 enter:
=--AND(B2=B1,C2=C1)
you can copy this down if required.
You use a combination if IF and AND in the column E cell, as in
=IF(AND(B2=B1, C2=C1), 1, 0)
This will leave either a 1 in column E if they both match properly, or a 0 if not.
You can also use simply =AND(...), but this will leave column E with either TRUE or FALSE.
=(B2=B1)*(C2=C1)
may suit. The elements return TRUE or FALSE and TRUE * TRUE returns 1.

Resources