Average over a column if text in another column maches - excel

I want to compute the average over one column if the text in another column matches a certain text.
eg:
A B C
aa 6 =AVERAGEIF(B1:B6;EXACT(A1:A6;"aa"))
bb 15
aa 8
bb 17
cc 1
aa 5
But the value in C gets 1. Why? How can I do what I want?

I would suggest using the AVERAGEIFS() function instead of AVERAGEIF(). See below:
=AVERAGEIFS(B1:B6,A1:A6,"aa")
This will yield as result of 6.3333.
Cheers.

Related

Formula reference holds for n cells in a row, then switches to new reference

I wonder if there's a quick solution to the following:
My goal is to divide a cell value by three, using the same value for three cells in a row, then switch to the next value in the series for another three cells in a row, and so on.
So my starting data would look like:
A B C D E
1 9 12 6 21 27
2 30 9 3 0 3
3 ...
I want the new cells to look like:
AA AB AC AD AE ...
1 3 3 3 4 4
2 10 10 10 3 3
...
Where the cell AA1 = A1/3, AB1 = A1/3, AC1 = A1/3, but AD1 = B1/3 and so on.
I need to do this for many observations, preferably using an excel formula.
Does anyone have any ideas on quick solutions?
Really appreciate your help.
Best,
Henry
Use INDEX:
=INDEX(1:1,0,ROUNDUP(COLUMN(A1)/3,0))/3

How to remove duplicate values using pandas and keep any one [duplicate]

This question already has answers here:
Drop all duplicate rows across multiple columns in Python Pandas
(8 answers)
Closed 2 years ago.
I have a data-frame which looks like:
A B C D E
a aa 1 2 3
b aa 4 5 6
c cc 7 8 9
d cc 11 10 3
e dd 71 81 91
As rows (1,2) and rows (3,4) has duplicate values of column B. I want to keep only one of them.
The Final output should be:
A B C D E
a aa 1 2 3
c cc 7 8 9
e dd 71 81 91
How can I use pandas to accomplish this?
DataFrame.drop_duplicates(subset="B", keep='first')
keep: keep is to control how to consider duplicate value.
It has only three distinct values and the default is ‘first’.
If ‘first’, it considers the first value as unique and the rest of the same values as duplicate.
If ‘last’, it considers the last value as unique and the rest of the same values as duplicate.
If False, it considers all of the same values as duplicates
Try drop_duplicates
df = df.drop_duplicates('B')
A B C D E
0 a aa 1 2 3
2 c cc 7 8 9
4 e dd 71 81 91
In the general case,
We need to drop across multiple columns. In that case, you need to use as follow
df.drop_duplicates(subset=['A', 'C'], keep=First)
We specify the column names in the subset argument and we use the keep argument to say what we need to keep
first : Drop duplicates except for the first occurrence.
last : Drop duplicates except for the last occurrence.
False : Drop all duplicates.

array based on max and less than?

I'm not sure if I'm over complicating this...
basically I'd like to have a formula which is
if the c column is less than 6, then look up the max value in B but display the value of C
so far I have this but I'd like it to show 2, not 437
{=MAX(IF(C2:C12<6,B2:B12, 0))}
any advice is appreciated. i'm shy, be nice..thanks
A B C
cat 110 3
dog 148 4
rooster 36 7
duck 32 8
pig 437 2
horse 44 6
eagle 215 5
dolphin 21 1
panda 2 9
iguana 257 10
fish 199 11
edit:
maybe something like
{=INDEX(C2:C12,MATCH(MAX(IF(C2:C12<6,C2:C12)),C2:C12,0))}
but I don't see where to put b2:b12
You really need two conditions
1) Column B is equal to =MAX(IF(C2:C12<6,B2:B12))
2) Column C is <6
so you can INDEX column C when those two are met, i.e.
=INDEX(C2:C12,MATCH(1,(B2:B12=MAX(IF(C2:C12<6,B2:B12)))*(C2:C12<6),0))
confirmed with CTRL+SHIFT+ENTER
{=IF(C2<6,INDEX($C$2:$C$12,MATCH(MAX($B$2:$B$12),$B$2:$B$12,0)),0)}
You were almost there..
Basically if C<6 , find max of B , lookup it in B:C and display corresponding C
{=IFERROR(VLOOKUP(MAX(IF(C2:C12<6,B2:B12, 0)),B2:C12,2,FALSE),0)}
Since your question doesn't clarify what if c>=6 I assume you don't want value.
Can answer more precisely if you clarify.
Mark this as answer if that's correct.
Hope this helps!
As I could see you requested a single INDEX formula:
{=INDEX($C$2:$C$12,MATCH(MAX(IF($C$2:$C$12<6,$B$2:$B$12,0),0),IF($C$2:$C$12<6,$B$2:$B$12,0),0))}
This is an array formula, hit Ctrl+Shift+Enter while still in the formula bar.
Lets break this down.
=INDEX(C:C, - Index column C as these are the values you want returned
MATCH(IF(C:C<6,B:B,0), - Find the largest value from the following array in the array and return it's relative position for INDEX()
IF(C:C<6,B:B,0),0)) - If the value in column c is less than 6 then add the column B value to the array, otherwise add 0

Combine duplicate column values EXCEL

Good afternoon.
I have an Excel Question
How to get from this to this.
A DFG
A ASD
C DD
A 144
C XX
B $%
------------
A DFG ASD 144
B $%
C XX DD
I tried with Index but I am not able to get the desired results.
Any idea>
Thanks
If your data is in columns A and B, then try:
F7: =IFERROR(INDEX($B:$B,AGGREGATE(15,6,1/1/($A:$A=$E7)*ROW($A:$A),COLUMNS($A:A))),"")
Fill down and to the right as needed (until you see blanks)
where G7 contains the item in column A you are looking for

Extracting unique values from a list and sorting by occurrence in Excel

Is there a formula to extract all unique terms in a list in Excel, then sort them by the number of times they occurred in the list?
List Extracted Data
1 AA AA
2 BB CC
3 CC BB
4 AA EE
5 DD DD
6 EE
7 AA
8 CC
9 CC
10 EE
11 BB
12 AA
AA occurs 4 times, so it is placed at the top of the extracted list, followed by CC which occurred 3 times, and so on.
I think that the faster way is by using pivot tables:
Select the table (make sure there's a header; insert one if there aren't any) and go to "Insert" > "Pivot Table". You should get something like this:
Click 'OK' then drag the header from the right pane once into "Row labels" and a second time into "Values":
Now select column B and insert a filter through "Home" > "Sort&Filter":
Now, just sort by descending:
First use Advanced Filter to extract the unique records to column B.
Then in C1 enter:
=COUNTIF(A$1:A$12,B1) and copy down
Finally sort cols B & C by C Descending

Resources