Excel: running maximum of two rows, or just return value in one row - excel

I have an Excel spreadsheet:
Name
Grade
Name1
82
Name1
90
Name2
65
Name3
90
Name3
60
I would like an Excel command that will do the following in a new column (TrueGrade, column C):
If a string occurs twice in column A (Name)
then get the maximum of the two values from column B (Grade)
else get the value from column B in the same row as the name (which only occurs once).
This is what the result should look like:
Name
Grade
TrueGrade
Name1
82
90
Name1
90
Name2
65
65
Name3
90
90
Name3
60
Unfortunately, vlookup does not return multiple values.
So far, I have tried this in cell C2:
=INDEX($A$2:$B$5, SMALL(IF($A$2:$A$5=B2, ROW($A$2:$A$5)), ROW(1:1))-1,COLUMNS($A$2:$B$5))
which gave me 82, but this is just the first instance of a grade for Name1.

Using your test data as an example, putting this formula in C2 and copying down gave me your expected results:
=IF(COUNTIF(A$2:A2,A2)>1,"",MAXIFS(B$2:B$6,A$2:A$6,A2))
Obviously extend the ranges to suit your situation. Also note that the CountIF formula range is slightly different than the Maxifs formula. This also assumes you have the MaxIfS formula. If you don't you can do the same thing with an array formula:
=IF(COUNTIF(A$2:A2,A2)>1,"",MAX(IF(A2=A2:A6,B2:B6)))
Just remember to confirm the array formula with Ctrl+Shift+Enter.

I like to use SUMPRODUCT in these cases (because I always forget to properly enter array formulas).
So in cell C2, you can use:
=SUMPRODUCT(MAX(($A$2:$A$6=A2)*($B$2:$B$6)))
EDIT: late with the updated answer based on my earlier work but it's the same as #sous2817:
=IF(COUNTIFS(OFFSET($A$2,0,0,ROW()-ROW($A$2)+1,1),$A2)=1,SUMPRODUCT(MAX(($A$2:$A$6=A2)*($B$2:$B$6))),"")
This still works without an array formula.

Related

Is it possible to have IF formula delete a row?

I have a formula that right now pulls and outputs on another sheet whether the B1 Cell is equal to “YES” then print A1 in the new sheets Cell I have the formula entered in, if it is not then it leaves the cell blank and this goes on for as many cells as needed.
Here is my formula
=IF((Sheet1!B1)=“YES”,Sheet!1A1,””)
I am wondering if there is a way to change the formula to where if it is not equal to “YES” then instead of leaving the Cell blank it deletes the entire row instead.
I know the final ,””) part of the formula is what I used to state the Cell will be blank. I’m just unaware if there is a function or anything I can input instead to state if not “YES” then delete the Row.
Example of what is happening:
If I have these entries in Sheet 1
A
B
1
85
YES
2
47
NO
3
74
YES
The output on Sheet 2 using my formula will be:
A
B
1
85
2
3
74
I am looking for it to look like this:
A
B
1
85
2
74
3
Thanks!

Excel - Match cell values in 2 separate columns and paste a different value if match

=INDEX(C:C,MATCH(A1,B:B,0))
The above formula is being pasted in D1.
I need it to return the C cell that on the same row as the matching A and B fields:
A B C D
77 22 MO91117
88 88 MO91337
99 99 MO12347
22 77 MO91837
Ideally, if I ran the formula in D1, it would return M091837.
Any help would be greatly appreciated!
Answering for completeness. Credit to A.S.H for the answer (in the comments of the question).
Ensure that both columns that you are trying to match are formatted similarly. It looks like the error in this question was that one column was formatted as text, and one column was formatted as a number. As an example the number 4 and the character 4 are represented differently in software, thus not returning expected values when trying to match text and numbers.

Sumproduct matching values in excel

I have two excel tables:
A B C D E
1 John 10 Mark 2
2 Tommy 20 Tommy 3
3 Jane 15 John 4
4 Kate 2
5 Jane 1
Is there a function to sumproduct values in colum B with those values in column E which match by name, i.e. 10*4 + 20*3 + 15*1 ?
You can use sumif for this and just sum up the results when you are done:
=B1 * sumif(D:D, A1, E:E)
Copy that down your sheet, and then add up the totals.
If you don't want a ton of formulas hanging out on your sheet, you could convert this to a CSE/Array formula:
=SUM($B$1:$B$3*SUMIF(D:D, $A$1:$A$3,E:E ))
Just enter that in and hit Ctrl+Shift+Enter to enter it. It will get curly braces around it, which means it's an Array formula.
Since you asked about sumproduct, we could use SUMPRODUCT
=SUMPRODUCT(($A$1:$A$5=A1)*$B$1:$B$5)*SUMPRODUCT(($D$1:$D$5=A1)*$E$1:$E$5)
Now that is assuming there are no repeats (all names are unique). In the event that names are not unique you will have those numbers added together then multiplied.
After you apply that to a column and copied down appropriately, lets say F1 to F3, in F5 you could get your final answer using:
=SUM(F1:F3)

Counting unique list of items from range based on criteria from other ranges

I have a file with data in the following format:
text value1 value2
Given value 1 and value 2 meet some criteria, find all the unique text values.
The exact data looks like this:
john 10 20
john 15 35
mark 20 10
mark 25 15
tom 25 40
lee 16 50
If val 1 <=25 and value 2 <=35 the number of unique text = 2 (john and mark)
I have to do this using formulas not filters.
I've been trying combinations of frequency, countifs, sumproducts and a whole range of other methods and can't seem to hit what I'm looking for.
Assuming that text, value1, and value2 are in columns A, B, and C respectively ...
In D1, enter the formula =IF(AND(B1<=25,C1<=35),A1,"") and copy it down the column
Use the formula =SUMPRODUCT((D:D<>"")/COUNTIF(D:D,D:D&"")) for your answer
If you want to list the unique values rather than count them, something like this:-
=IFERROR(INDEX(A$2:A$7,MATCH(0,IF((B$2:B$7>25)+(C$2:C$7>35),1,COUNTIF(E$1:E2,A$2:A$7)),0)),"")
entered as an array formula starting in E2 ( and assuming that you are using columns A,B and C for your data.
See this reference for explanation.
The following formula will do what you are asking:
=SUM(IF(FREQUENCY(IF(B2:B7<=25,IF(C2:C7<=35,MATCH(A2:A7,A2:A7,0),""),""),IF(B2:B7<=25,IF(C2:C7<=35,MATCH(A2:A7,A2:A7,0),""),""))>0,1))
This is an array formula so confirm it with Ctrl-Shift-Enter.
I referred to this webpage.
Also found a shorter one:
=SUM(--(FREQUENCY(IF(B2:B7<=25,IF(C2:C7<=35,COUNTIF(A2:A7,"<"&A2:A7),""),""),COUNTIF(A2:A7,"<"&A2:A7))>0))
Found and modified from hre.

Assigning the same value to different cells according to the rank of a matching cell's group

I have an Excel sheet that has values repeating in different rows of the same column (Obtain Marks). In RANKS column I want a grade assigned.
My problem is assigning the same rank to cells having the same Obtain Marks values.
How do I assign the same rank to the same Obtained Marks using an Excel formula?
Obtain Marks RANKS
212 1
212 1
212 1
211 2
210 3
209 4
209 4
Assuming Obtain Marks is in A1 and is sorted in order, if you want grouped by rank then I suggest in B2 and copied down to suit:
=RANK(A2,A$2:A$7,)
If you post includes under RANK the desired output then I suggest instead 1 in B2 and in B3 and copied down to suit:
=IF(A2=A3,B2,B2+1)
Either way each group should have a distinct value.
You can derive a pseudo-RANK.UNIQUE formula by modifying an old standard method of a SUMPRODUCT-style COUNT.UNIQUE formula.
        
The formula in B2 is,
=SUMPRODUCT((A$2:A$8>=A2)/COUNTIF(A$2:A$8, A$2:A$8&""))
Fill down as necessary.

Resources