Count number of X in Column A when Y is in either Column B or C - excel

Simplified data in columns A, B and C:
A | B | C
X | | Y
| Y |
X | Y |
Z | | Y
X | |
How to count the number of X when the value of Y is present in column B or C?
(ie. result is 2). Was thinking about COUNTIFS but can't seem to get the formula right :(

You can't do this with a single COUNTIFS, because conditions in COUNTIFS are AND, not OR. You can do it with multiple COUNTIFS, or an Array Formula (not recommended - that's a bit overkill for this case)
You need to count up all the rows where Column A is X and Column B is Y, add all the rows where Column A is X and Column C is Y, and then decide of a row where Column A is X and both Column B and Column C are Y is possible and/or should be counted twice.
If it is possible, but should not be double-counted, then you will need to subtract all the rows where Column A is X and Columns B and C are both Y.
=COUNTIFS($A:$A,"X",$B:$B,"Y") + COUNTIFS($A:$A,"X",$C:$C,"Y") - COUNTIFS($A:$A,"X",$B:$B,"Y"",$C:$C,"Y")
If it can't be in both, or you want that to count as 2 rows instead of 1, then you don't need the third COUNTIFS
As an Array Formula (using SUMPRODUCT instead of SUM, because then we don't need to use Ctrl+Shift+Enter), for reference:
=SUMPRODUCT(--($A:$A="X")*--(--($B:$B="Y")+($C:$C="Y")>0))
(The >0 is so that the OR (+) doesn't double-count)

Because you never have a double-Y case, you can use:
=SUMPRODUCT((A1:A5="X")*(B1:B5="Y"))+SUMPRODUCT((A1:A5="X")*(C1:C5="Y"))

Related

EXCEL counting empty rows

A B C D E F G H
1 Y Y Y X
2 X X
3 Y Y
4 X X
5 Y Y Y X
Count the number of empty rows (from Columns A to E) and put result here. Answer should be 2 from example above.
Hi Folks,
I'm struggling to find the correct Excel formula to count the number of rows with no data from columns A through E, and putting that answer in a cell. These 'empty rows' may have data in later columns (like F, G, H), but I just want to count the rows with no data from columns A to E.
Any help would be appreciated.
Since array formulas tend to confuse people, here's a non-Array formula approach:
Place =IF(COUNTA(A1:E1)=0,1,0) into row 1 of (for example) column I and drag down to row 5. Then place a sum formula below that to get the answer, for example: =SUM(I1:I5)
Try this array formula,
=SUM(IF(ROW(1:5), IF(A1:A5&B1:B5&C1:C5&D1:D5&E1:E5="", 1)))
Remember to finalize with ctrl+shift+enter, not just enter.
You could also use a variation on the standard formula for getting row sums of a 2d array
=SUM(N(MMULT(N(A1:E5=""),TRANSPOSE(COLUMN(A1:E5)^0))=COLUMNS(A1:E5)))
or
=SUM(N(MMULT(N(A1:E5="Y"),TRANSPOSE(COLUMN(A1:E5)^0))=0))
Again they are array formulas and have to be entered with CtrlShiftEnter

How to sort 3 columns of data in excel

I'm using Microsoft Excel 2011 on a Mac, and I need help sorting 2200 rows of data.
Basically, what I want to do is to sort the Type column, while keeping its corresponding data beside it after the type is shifted.
I would like all the type A's, B's, and C's to be in order, and have their adjacent data from experiment 1 and 2 follow to the new position once sorted.
Each data group is separated by a few empty rows.
Here's a small example of what my data looks like:
Type EXPERIMENT 1 EXPERIMENT 2
A A F
F R
S S
E G
B Y A
A A
S H
F
A A E
D F
F S
E
Y
A F H
R G
E A
D F
Y W
S E
S
C F S
D D
S U
F J
Y
T
And this is what I want:
Type EXPERIMENT 1 EXPERIMENT 2
A A F
F R
S S
E G
A A E
D F
F S
E
Y
A F H
R G
E A
D F
Y W
S E
S
B Y A
A A
S H
F
C F S
D D
S U
F J
Y
T
In an unused column to the right (aka Helper column) put this formula into the second row.
=VLOOKUP("zzz",A$1:A2,1)&TEXT(COUNTIF(A$1:A2,VLOOKUP("zzz",A$1:A2,1)),"0000")
... and fill down as necessary. Select all of the columns and sort with the Helper column as the primary sort key. The results from your sample should mirror the following.
                 
Additional formulas can be provided if you need sorting key criteria on the Experiment x columns. Show what you've tried together with some example of the results expected and additional assistance will no doubt be offered.
It seems to me it would be easy to sort if you would concatenate each data set into a row. Type goes in column A; Exp 1 into one cell in column B; Exp 2 into one cell in column C. Then the sort is simple. Otherwise you'll require a complicated macro. You can always parse it out later if required.
To concatenate you'll need to:
Save as new workbook first to avoid changing your original data
Insert a row between the headers and the first data
Put the formulas indicated into row 2 and copy down
Copy and PasteSpecial as values
Sort by column D
Delete all rows that are false
Now your sorting will be easy.
Edit: fixed my formulas to line up with true column.

Compare values from multiple columns

I'm trying to compare values from multiple columns and then highlight the row if it matches my criteria using conditional formatting. For example: in the table below, there are four columns, and I want to compare the values within the the 3 columns: A-C. If they all match, then I want to highlight the entire row. When I use conditional formatting, I'm only able to compare two of the three. I don't know the syntax to compare more than columns.
A B C
Name Has Dog Has Cat Has Bird
A Y Y Y
B Y N Y
C Y Y N
D N N Y
E Y Y N
Please try:
=AND($B1=$C1,$B1=$D1)
for Format values where this formula is true: and Applies to all the columns you have available.

Return value of last populated cell in variable range

Into column D, I'd like to copy the value from the last cell with data in columns E up until the column with the header "DETAIL". There might be anywhere from 2 to 15 columns from E until the column with that header, so that's where I'm stuck. So to be clear, an example:
A B C D E F G H DETAIL
1 x x x a b c d x
2 x x x x
3 x x x c b a x
3 x x x d c x
Should fill column D like so:
A B C D E F G H DETAIL
1 x x x d a b c d x
2 x x x x
3 x x x a c b a x
3 x x x c d c x
I don't mind handling this with a formula (which I couldn't come up with) or programmatically.
Create a dynamic named range by pressing CtrlF3 to bring up the Name Manager, click New, name the range something (I chose MyRange) and then use this formula to define it (Note you may need to change the Sheet name):
=Sheet1!E2:INDEX(Sheet1!2:2,MATCH("Detail",Sheet1!$1:$1,0)-1)
Then, in cell D2 and copied down, use this formula (I did not use IFERROR so that it would be backwards compatible):
=IF(COUNTA(MyRange),INDEX(MyRange,MATCH(REPT("z",255),MyRange)),"")
Here are the results (highlighted) using your provided sample data:
Please try:
=IFERROR(INDEX(F2:T2,,MATCH("zzzzzz",F2:T2)),"")
in D2 and copied down to suit.
Try using LOOKUP:
=IFERROR(LOOKUP(9^99,SEARCH("*",E1:H1),E1:H1),"")
SEARCH("*",E1:H1) returns a number when it matches any character and an error when the cell is blank. LOOKUP then returns the contents of the cells of the last number smaller than 9^99 in the array generated by SEARCH.
For example, in the first row, SEARCH("*",E1:H1) returns {1,1,1,1} so that LOOKUP returns the last 1, being d.
In the third row, SEARCH("*",E3:H3) returns {1, 1, 1, #VALUE!} and LOOKUP returns the last 1, which is a here.
This formula will work with numbers and text alike. The downside is that it is considered slower than INDEX/MATCH. On the other hand, you can modify the INDEX/MATCH to work with numbers, or modify it to work for both but becomes an array formula:
=IFERROR(INDEX(E1:H1,,MATCH(1,SEARCH("*",E1:H1))),"")
[Works with Ctrl+Shift+Enter, otherwise returns an empty cell with Enter alone]

Excel get average of a result of index+match function, see details

So I have:
A B C down here i want to get an average
like this:
v 1 a (*1) filter col "C" for what i have in row for col C, in this case "a", then filter col A for what I have in my row for col A, then all those rows must be counted, then sum them and then: sum/count
v 2 a
y 3 a
y 7 a
y 3 a
v 2 b
y 4 b
v 2 b
y 7 b
thanks
You want COUNTIFS and SUMIFS (check Excel help for the params)
Assuming your first row starts on A1:
=SUMIFS($B$1:$B$9,$C$1:$C$9,C1,$A$1:$A$9,A1) / COUNTIFS($C$1:$C$9,C1,$A$1:$A$9,A1)

Resources