Return row label for largest & 2nd largest value in criteria range - excel

I have the following table
Name
Point
Bonus
Total
Pos
1st
Name
2nd
Name
Bob
10
8
6
Point
11
10
Sue
9
5
3
Bonus
12
9
Joe
11
2
4
Total
10
7
Susan
7
9
10
Tim
1
12
4
Ellie
9
8
7
In G2 I have the following formula
{=LARGE(IF($B$1:$D$1 =$F2, $B:$D),1)}
Which returns the largest Point value, as 11.
In H2 I want to return the name where the Point value is 11. so the value for H2 should be Joe
Then in J2 want to do the same for the 2nd largest value. So the value of J2 should be Bob

I have used following formulas as per attached scheenshot.
G2=LARGE(INDEX($B$2:$D$7,,MATCH(F2,$B$1:$D$1,0)),1)
H2=INDEX($A$2:$A$7,MATCH(G2,INDEX($B$2:$D$7,,MATCH(F2,$B$1:$D$1,0)),0))
I2=LARGE(INDEX($B$2:$D$7,,MATCH(F2,$B$1:$D$1,0)),2)
J2=INDEX($A$2:$A$7,MATCH(I2,INDEX($B$2:$D$7,,MATCH(F2,$B$1:$D$1,0)),0))
And if you have Microsoft-365 then could try below formula to get names directly.
=LET(x,FILTER($B$2:$D$7,$B$1:$D$1=F2),FILTER($A$2:$A$7,x=LARGE(x,1)))

Related

Allocate class based on school ranking

In Excel I am trying to allocate classes to pupils based on their ranking in school. The set of data I have looks like this:
S/N Name LevelPosition
1 Andrea 10
2 Bryan 25
3 Catty 5
4 Debbie 26
5 Ellie 30
6 Freddie 28
I would like to have a formula that could sort the pupils based on the LevelPosition and allocate the class in order of this sequence - A,B,C,C,B,A. Hence the result would be:
S/N Name LevelPosition AllocatedClass
3 Catty 5 A
1 Andrea 10 B
2 Bryan 25 C
4 Debbie 26 C
6 Freddie 28 B
5 Ellie 30 A
This was the sort of thing I had in mind.
Column D is just a ranking from bottom to top:-
=RANK(C2,C$2:C$7,1)
Colum D is adjusted for any ties:-
=D2+COUNTIF(D$1:D1,D2)
Column E is based on the #pnuts formula:-
=CHOOSE(MOD(E2-1,6)+1,"A","B","C","C","B","A")
I've put some ties in to show what would happen. The last two students' allocations are reversed because the second to last has the higher mark.

excel/vba - find fist and last occurrence of a particular value in a column

So if I have a column such as:
A1
1 Apple
2 Apple
3 Apple
4 Oj
5 Oj
6 Oj
7 Oj
8 Pear
9 Pear
How could I return the values 1 & 3 for Apple, 4 & 7 for OJ, etc?
Formula-wise you can use MATCH functions, e.g. for first Apple position
=MATCH("Apple",A1:A9,0)
for last
=MATCH(2,INDEX(1/(A1:A9="Apple"),0))
or if the fruit are sorted as per your example (or merely grouped) you can get the last by adding the number of apples to the first -1
so with first MATCH function in C1 that would be
=COUNTIF(A1:A9,"Apple")+C1-1

Excel Finding What Place a Value Comes In

I am trying to find a way to get which place a certain value comes in in a range of other values. Or another way to look at it is I want to turn the SMALL function inside out. The SMALL function looks like this, "=SMALL(array, k)" where it looks for the k place in an array. I need the find what the k is. I hope that makes sense, but if not here is one more example.
A B C D
1 Kate 12.25 =PLACE($B$1:$B$13,B1) 4
2 Cindy 15.80 =PLACE($B$1:$B$13,B2) 10
3 Mark 11.85 =PLACE($B$1:$B$13,B3) 3
4 Thomas 12.98 =PLACE($B$1:$B$13,B4) 5
5 George 13.58 =PLACE($B$1:$B$13,B5) 7
6 Kim 14.52 =PLACE($B$1:$B$13,B6) 9
7 Tim 11.54 =PLACE($B$1:$B$13,B7) 2
8 Frank 12.99 =PLACE($B$1:$B$13,B8) 6
9 Fran 17.85 =PLACE($B$1:$B$13,B9) 11
10 Caroline 14.25 =PLACE($B$1:$B$13,B10) 8
11 Alex 19.20 =PLACE($B$1:$B$13,B11) 12
12 Lilly 25.20 =PLACE($B$1:$B$13,B12) 13
13 Peter 11.22 =PLACE($B$1:$B$13,B13) 1
Also I can easily do it with VBA, but I do not want to. I want to do it in cell and I do not want to have to sort them first.
RANK function does this, i.e. in your case this formula in row 1 copied down
=RANK(B1,B$1:B$13,1)
The 1 at the end indicates the order of ranking (ascending here). Leave that out and you get descending ranking

Sum number according to date and name in excel

To sum the third column (numbers o companies) I've used this
=SUM(1/COUNTIF(Names;Names))
Names is name of array in C column and CTRL+SHIFT+ENTER and it works perfectly.
Now I'd like to sum earnings but only for each company once and with the latest data. For example, the result shoud be like this
=C4+C6+C7+C8+C9+C10
(93)
Thanks
A B C D
1 # company earnings date
2 1 ISB 12 10/11/2011
3 2 DTN 15 11/11/2011
4 3 ABC 13 12/11/2011
5 4 ISB 17 13/11/2011
6 5 RTV 18 14/11/2011
7 6 DTN 22 15/11/2011
8 7 PVS 11 16/11/2011
9 8 ISB 19 17/11/2011
10 9 ANH 10 18/11/2011
Sum 6 93
Assuming ascending dates, you could try with CTRL+SHIFT+ENTER in C11:
=SUM((MAX(A2:A10)-MATCH(B2:B10,LOOKUP(MAX(A2:A10)-A2:A10,A2:A10-1,B2:B10),0)=A2:A10-1)*C2:C10)
I'd suggest using a helper column as the easiest approach. In E2 use this formula
=IF(COUNTIF(B2:B$1000,B2)=1,C2,"")
and copy down the column. Now sum column D for the required answer.
Note that the above formula assumes 1000 rows of data maximum, increase if required.

Giving duplicates in Excel a unique identifier

I have a large excel spreadsheet containing multiple address lines. Many of these adress lines contain duplicate postcodes, with differing steet adrresses.
I need to seperate out each of these duplicates onto different spreadhseets, so that no one spreadhseet contains the same postcode. I'm currently using an =if() statement to identify the duplicates, then cutting and poasting, and repeating almost ad infinitum to speperate them all out
as an example:
address 1 postcode 1
address 2 postcode 1
address 3 postcode 1
address 4 postcode 2
address 5 postcode 2
address 6 postcode 3
address 7 postcode 3
address 8 postcode 3
address 9 postcode 3
would give 4 spreadsheets:
1)
address 1 postcode 1
address 4 postcode 2
address 6 postcode 3
2)
address 2 postcode 1
address 5 postcode 2
address 7 postcode 3
etc
Any hints on a vb script?
Many thanks
Nick
If this is a one-off thing, then I'd consider doing it in the worksheet and bulk cut-pasting. I'd try something like this:
Sort my data on the post code column
In a new column, add a function to count the number of post codes below the current row that are duplicates of the code on that row (see below)
Save (copy/paste-special-values) the values obtained
Sort by duplicate number
Cut and paste blocks by duplicate number to new sheets
Say I have 20 values between 1 and 5 in column G. I put the following formula in H1:
=SUM(IF(G1:$G$20=G1,1,0))
... and (important bit) enter it as an array formula using Control+Shift+Enter. Now I copy that formula down (for speed, double-click the "fill handle" on the bottom right-hand corner of the cell). Here's my result:
1 2
1 1
2 2
2 1
3 8
3 7
3 6
3 5
3 4
3 3
3 2
3 1
4 2
4 1
5 6
5 5
5 4
5 3
5 2
5 1
Now I can copy column H and Edit...Paste Special...Values to fix the values. Sort by H to get this:
1 1
2 1
3 1
4 1
5 1
1 2
2 2
3 2
4 2
5 2
3 3
5 3
3 4
5 4
3 5
5 5
3 6
5 6
3 7
3 8
Now I have sets of records to copy to each of the 8 sheets that I now know are needed.
Of course, if you're going to be doing this a lot, then a macro would be useful. It needn't be much more complex than automating the above.

Resources