Averageifs with Or - excel

I have read that this may not be possible/ I am just doing it wrong so I was wondering if anyone knew a workaround (non - VBA) or could correct me? Thanks!
Col A has the price of apples and oranges
Col D has apples and Oranges
Col E has the type of fruit (Red, Yellow, Green, Purple)
I'm trying to get the average of Col A where Col D is Apples and Col E is either Red or Yellow.
I tried:
=SUM(AVERAGEIFS(A:A,D:D,"Apples",E:E,"Red"),AVERAGEIFS(A:A,D:D,"Apples",E:E,"Yellow"))/2
But it did not work - anyone have any ideas?

Yes you can do this:
=SUM(SUMIFS(A:A,D:D,"Apples",E:E,{"Red","Yellow"}))/SUM(COUNTIFS(D:D,"Apples",E:E,{"Red","Yellow"}))
Confirm with Enter
Edit Comparison of formulas
1) In this first screenshot all results appear similar:
2) In this second screenshot I changed cell E8 to purple. Results start to differ:
3) In this third screenshot it becomes clear there is no result using AVERAGE while there is using SUM/COUNTIFS:

I don't think you can add OR operations in AVERAGEIFS but you can use this (it's an array formula so you'll have to enter it with ctrl + shift + enter):
=AVERAGE(IF((D:D="Apples")*((E:E="Yellow")+ (E:E="Red")),A:A))
If you don't want to use array formula then (as an alternative to #JvdV's answer), you can use:
=SUMPRODUCT(A:A,--(D:D="Apples"), --((E:E="Red")+(E:E="Yellow")))/SUMPRODUCT(--(D:D="Apples"), --((E:E="Red")+(E:E="Yellow")))

Similar to the response from JvdV, you can use AVERAGEIFS directly.
=AVERAGE(AVERAGEIFS(A:A, B:B, {"a","c"}))
'for your data
=AVERAGE(AVERAGEIFS(A:A,D:D, "Apples", E:E, {"Red","Yellow"}))
Addendum:
4.00 apples Red
2.70 oranges Purple
2.13 apples Purple
2.64 apples Yellow
3.11 apples Purple
2.96 apples Purple
9.44 apples Yellow
2.07 oranges Red
3.14 oranges Purple
3.58 oranges Yellow
2.44 oranges Red
2.82 apples Red
2.86 apples Yellow
2.23 oranges Yellow
1.95 apples Red
2.37 oranges Yellow
The above sample data produces identical results for the following:
=AVERAGE(A2,A5,A8,A13,A14,A16)
=AVERAGE(AVERAGEIFS(A:A,D:D,"apples",E:E,{"red","yellow"}))
=SUM(SUMIFS(A:A, D:D, "apples", E:E, {"red","yellow"}))/SUM(COUNTIFS(D:D, "apples", E:E, {"red","yellow"}))
However when there are a different number of matches in the { OR } criteria then there are bad results.
4.00 apples Red
2.70 oranges Purple
2.13 apples Purple
2.64 apples Yellow
3.11 apples Purple
2.96 apples Purple
9.44 apples Yellow
2.07 apples Red
3.14 oranges Purple
3.58 oranges Yellow
2.44 oranges Red
2.82 apples Red
2.86 apples Yellow
2.23 oranges Yellow
1.95 apples Red
2.37 oranges Yellow

Related

SUMIFS excluding two criteria

I'm trying to do SUMIFS with two criteria I want to exclude.
I want to count the amount of fruit sold by all, excluding cherries sold by James.
A
B
C
Qty
Product
Salesperson
5
Apples
James
10
Apples
Jack
15
Apples
Ben
20
Bananas
Ben
15
Bananas
Jack
10
Cherries
James
5
Grapes
Ben
10
Grapes
James
15
Cherries
Jack
20
Melons
Ben
I've tried
=SUMIFS(A:A,B:B,AND(B:B"<>Cherries",C:C"<> James"))
but got an error.
=SUMIFS(A:A,B:B,"<>Cherries",C:C,"<>James")
Also does not work as it doesn't count and Cherries or anything sold by James.
From the data above I would expect 115 as my answer.
subtract the part from the whole:
=SUM(A:A)-SUMIFS(A:A,B:B,"Cherries",C:C,"James")

counting unique row values in excel

I have product list like this. I have only product name list
Apple 1
Apple 1
Apple 1
Orange 2
Orange 2
Orange 2
Mango 3
Mango 3
Pineapple 4
Pineapple 4
Pineapple 4
Pineapple 4
Pineapple 4
Pineapple 4
Avocado 5
I want to count data in this way. please help.
In B1 insert 1 and in B2 insert:
=IF(A2=A1,B1,B1+1)
And from there just fill.
Put 1 in B1 then put this formula in B2,
=if(a2<>a1, max(b$1:b1)+1, b1)
... and fill down.
Alternately just put his formula into B1,
=SUMPRODUCT(1/(COUNTIF(A$1:A1,A$1:A1)))
... and fill down.

If formula comparing two columns

Need a formula that says if the combination of information in Column 3 & 4 in the same row match the combination of Column 1 & 2 in the same row then say YES, otherwise say No. Column 5 shows what I would like to see. There is a orange in column 1 that has 2222222 in column 2 so it would show as NO where as there is a Banana in Column I that has 2222222 in column 2.
FIRST SET OF VALUES SECOND SET OF VALUES
COLUMN 1 COLUMN 2 COLUMN 3 COLUMN 4 COLUMN 5
ORANGE 11111111 ORANGE 22222222 NO
BANANA 22222222 BANANA 22222222 YES
PEAR 33333333 PEAR 55555555 NO
PEAR 44444444 WATERMELON 55555555 YES
WATERMELON 11111111 GRAPES 66666666 YES
WATERMELON 55555555 PEACH 33333333 YES
GRAPES 66666666 PLUM 44444444 NO
GRAPES 77777777 PINEAPPLE 34343434 YES
GRAPES 22222222
PEACH 33333333
PLUM 88888888
PLUM 77777777
PINEAPPLE 99999999
PINEAPPLE 12121212
PINEAPPLE 34343434
PINEAPPLE 56565656
Use COUNTIFS():
=IF(COUNTIFS(I:I,M3,J:J,N3),"Yes","No")

Excel find string in string in range return data in corresponding column

The Excel thingy again. ;-)
I have columns like this:
A B C
UserID Name Org_Name
1 Brian Green Susan Red
2 Niels Red Susan Blue
3 Susan Yellow Brian Green
4 India Orange Serge Black
I am looking for a formula that can find ORG_Name(C) in Name(B) and return the UserID(A) and Name(B) found.
In this case it could look like this:
A B C D E
UserID Name Org_Name FoundID FoundName
1 Brian Green Susan Red N/A N/A
2 Niels Red Susan Blue N/A N/A
3 Susan Yellow Brian Green 1 Brian Green
4 India Orange Serge Black N/A N/A
Anyone?
Formula for FoundID column:
=INDEX($A$2:$A$5,MATCH(C2,$B$2:$B$5,0))
Formula for FoundName column:
=INDEX($B$2:$B$5,MATCH(C2,$B$2:$B$5,0))
Adjust the end row as required (the 5s in both formulas)

Get Top Performer by Subgroup Using Index and Match

I am trying to rank names in Column C from largest to smallest score.
Category Score Name Total Rank Apple Rank Orange Rank
Apple 10 Joe Rachel Rachel 0
Orange 15 Don Natalie 0 Natalie
Apple 20 James Tom Tom 0
Apple 1 Rob Nothing Nothing 0
Orange 3 Mary Gina 0 Gina
Orange 100 Rachel James 0 James
Orange 99 Natalie Don 0 Don
Orange 87 Tom Joe 0 Joe
Apple 27 Gina Mary Mary 0
Orange 30 Nothing Rob 0 Rob
This works in Column E for Apples AND Oranges, with formula in E2 that is
=INDEX($C$2:$C$25,MATCH(1,INDEX(($B$2:$B$25=LARGE($B$2:$B$25,ROWS(E$1:E1)))*(COUNTIF(E$1:E1,$C$2:$C$25)=0),),0))
However, the goal is to compare Apples to Apples and Oranges to Oranges.
Only, the formulas in Columns F and G show "0" values for those rows that aren't in the right Apple/Orange category.
For F2:
=IF($A:$A="Apple",INDEX($C:$C,MATCH(1,INDEX(($B:$B=LARGE($B:$B,ROWS(F$1:F1)))*(COUNTIF(F$1:F1,$C:$C)=0),),0)),0)
For G2:
=IF($A:$A="Orange",INDEX($C:$C,MATCH(1,INDEX(($B:$B=LARGE($B:$B,ROWS(G$1:G1)))*(COUNTIF(G$1:G1,$C:$C)=0),),0)),0)
How do I modify the codes so that 0 values won't show up?
Something like this would be great: (screenshot made by just copy pasting values...)
Apple Rank Orange Rank
Rachel Natalie
Tom Gina
Nothing James
Mary Don
Joe
Rob
Note: Unless the whole column ranges are required the steps below may seem to take an uncomfortably long time if these ranges are not restricted.
Assuming you have what below is in ColumnA:G and a corresponding layout:
then ColumnsI:J may be achieved quite simply by copying ColumnF:G and Paste Special..., Values into I1, then select ColumnsI:J, HOME > Editing - Find & Select, Replace..., Find what: 0, Replace with: , Replace All followed by Find & Select, Go To Special..., select Blanks (only), OK, right-click on one of the chosen cells and Delete..., Shift cells up, OK.
To remove the 0s from ColumnF:G only replacing the final 0 in each formula with "" is sufficient.

Resources