Google sheets formula to get the Top 5 List With Duplicates - excel

I'm trying to compile a best 5 and worst 5 list. I have two rows, column B with the number score and column C with the name. I only want the list to include the name.
In my previous attempts the formula would get the top/bottom 5 but as soon as a duplicate score appeared the first known name with that value would just repeat.
Here is my data
26 Cal
55 John
55 Mike
100 Steve
26 Thomas
100 Jaden
100 Jack
95 Josh
87 Cole
75 Brett
I've managed to get the bottom 5 list formula correct. This formula works perfectly and includes all names of duplicate scores.
Example of what I get:
Cal
Thomas
John
Mike
Brett
=INDEX($C$56:$E$70,SMALL(IF($B$56:$B$70=SMALL($B$56:$B$70,ROWS(E$2:E2)),ROW($B$56:$B$70)-ROW($B$56)+1),SUM(IF($B$56:$B$70=SMALL($B$56:$B$70,
ROWS(E$2:E2)),1,0))-SUM(IF($B$56:$B$70<=SMALL($B$56:$B$70,ROWS(E$2:E2)),1,0))+ROWS(E$2:E2)))
Here is the formula I've tried to get the top 5 - however I keep getting an error.
=INDEX($C$56:$E$70,LARGE(IF($B$56:$B$70=LARGE($B$56:$B$70,ROWS(E$2:E2)),ROW($B$56:$B$70)-ROW($B$56)+1),SUM(IF($B$56:$B$70=LARGE($B$56:$B$70,
ROWS(E$2:E2)),1,0))-SUM(IF($B$56:$B$70<=LARGE($B$56:$B$70,ROWS(E$2:E2)),1,0))+ROWS(E$2:E2)))
Example of what I'm looking for
Steve
Jaden
Jack
Josh
Cole

You can set two queries like this for both cases:
=QUERY(B56:C70,"Select C order by B desc limit 5")
=QUERY(B56:C70,"Select C order by B limit 5")

Use SORTN() function like-
=SORTN(A1:B10,5,,1,1)
To keep only one column, wrap the SORTN() function with INDEX() and specify column number. Try-
=INDEX(SORTN(A1:B10,5,,1,1),,2)

Related

Returning Column Index/Value Based on Max value of Specific row

Sorry if I have completely butchered the terminology in the title. Relatively new to Excel.
I have the following table.
Name
Score A
Score B
Score C
Bob
10
8
6
Sue
9
12
10
Joe
11
2
4
Susan
7
9
10
Tim
10
12
4
Ellie
9
8
7
What I am trying to achieve is that for each person, to return the score type for that person's best score. I'm referencing the person's name on another sheet.
For example. For Susan;
Their best score is 10 and that is under Score C.
So I want the final value in the Score Type column in my other sheet for Susan to be Score C
Like so
Name
Best Score
Score Type
Ellie
9
Score A
Bob
10
Score A
Susan
10
Score C
I know to get the index of each persons row by
=MATCH(A2,$A$2:$A, 0)
I can get the max value for that person via
{=MAX(IF($A$2:A = A2,($B$2:$D)))}
I'm just not sure how to use that information to return the column label corresponding to the person and their max score.
Any help would be greatly appreciated
I think it is pretty easier. Try-
=INDEX($B$1:$D$1,MATCH(MAX(B2:D2),B2:D2,0))
For dynamic spill array-
=BYROW(B2:D7,LAMBDA(x,FILTER(B1:D1,x=MAX(x))))
EDIT: Then try below formula-
=INDEX($B$1:$D$1,1,MAX(($A$2:$A$7=$I3)*($B$2:$D$7=$J3)*(COLUMN($B$2:$D$7)))-COLUMN($A$2))
For Larger Data you could use this one

Updating spreadsheet after altering the original one

I have the following data in spreadsheet A.
name trait1 trait2 nice
0 Adam 29 81 0
1 Barry 17 75 1
2 Chris 62 0 1
I wish to create a spreadsheet B that will be a filtered copy of this data. Namely, let's assume for a moment that I want to filter nice = 1 and am interested only in column name. The copy in spreadsheet B would be as shown below. In spreadsheet B I wish to be adding some extra columns, e.g. education.
name nice education
1 Barry 1 primary
2 Chris 1 university
What I want to achieve is a spreadsheet B that will get updated if anything changes in spreadsheet A. So for example, if I were to change the name Barry to Ben. The spreadsheet B would become the following.
name nice education
1 Ben 1 primary
2 Chris 1 university
Similarly (and what I find to be the hardest), if a row is added in spreadsheet A, e.g.
name trait1 trait2 nice
0 Adam 29 81 0
1 Barry 17 75 1
2 Matt 69 11 1
3 Chris 62 0 1
The updated spreadsheet B would be as follows:
name nice education
1 Barry 1 primary
2 Matt 1
3 Chris 1 university
So I want the education column to remain the same.
My approach of using a combination of =IF() and =VLOOKUP() functions ultimately did not work. Guess I am really curious about how to connect rows of education to names. So that when a row is added in spreadsheet A, then spreadsheet B gets updated but the education field connected to the new row is empty and will be filled by hand later on.
Since you are looking for a finished product to be in Google Sheets, I'd advise to use QUERY():
Formula in I1:
=QUERY(INDEX({A:D,VLOOKUP(A:A,F:G,2,0)}),"Select Col1,Col4,Col5 where Col4=1")
Note: I made the assumption you pull the education in through a VLOOKUP() (since you mentioned that in the body of the question).

EXCEL Get top 3 largest numbers in repetitive array

enter image description hereI have an array of people with scores in other column. I need to find top 3 people with highest score and print their names.
Example:
Maria 1
Thomas 4
John 3
Jack 2
Ray 2
Laura 4
Kate 3
Result should be:
Thomas
Laura
John
What I get:
Thomas
Thomas
John
What I get:
Thomas
John
num
I have tried using LARGE, MATCH, MIN, MAX but nothings works.
My first failure code:
=INDEX($A$2:$A$8; MATCH(LARGE(($B$2:$B$8);{1;2;3}); $B$2:$B$8;0))
My second failure code:
{=INDEX($A$2:$A$14;SMALL(IF($B$2:$B$14=MAX($B$2:$B$14);ROW($B$2:$B$14)-1);ROW(B4)-1))}
Put this in the second row of the column you want:
=INDEX(A:A,AGGREGATE(15,7,ROW($B$1:$B$7)/((COUNTIF($D$1:D1,$A$1:$A$7)=0)*($B$1:$B$7=LARGE(B:B,ROW(1:1)))),1))
And drag down three rows:

List the next couple occuring birthdays in excel

Given the following data
A B
Steven 01/05/1958
Mike 05/12/1923
Bob 05/11/2001
Richard 10/22/1985
Maverick 12/25/1991
Ed 01/07/1954
I'd like to get a list in, let's just say the column D, containing the next couple birthdays that will occur.
So if today was 05/05/2016, I'd like to see
D E
Bob 05/11/2001
Mike 05/12/1923
My current approach (yet not working properly) is to create another column and have the days until the birthday calculated there, using this formula:
=DATE(YEAR(B2)+DATEDIF(B2+1;TODAY();"y")+1;MONTH(B2);DAY(B2))-TODAY()
Then I list the birthdays that come up in the next 5 days using:
=IF(ISERROR(INDEX($A$2:$C$5,SMALL(IF($A$2:$C$5<5,ROW($A$2:$A$5)),ROW(1:1)),2)),"",INDEX($A$2:$C$5,SMALL(IF($A$2:$A$5<5,ROW($A$2:$A$5)),ROW(1:1)),2))
I'd rather have the next 5 upcoming birthdays, no matter how far away from today they are.
Any Ideas how to achieve this without using makros?
Help is much appreciated!
To get the birthday difference from today in days :
=(DATEDIF($D$1,DATE(IF((DATE(YEAR($D$1),MONTH(B2),DAY(B2))>$D$1),YEAR($D$1),YEAR($D$1)+1),MONTH(B2),DAY(B2)),"D"))+0
The first BD from current date :
=VLOOKUP(SMALL(A2:A8,1)+0,A2:B8,2,FALSE)
Please see the img for more details :
Another approach would be to use the Advanced Filter. And you could automate it using VBA.
For the Criteria:
A2: =DATE(YEAR(TODAY()),MONTH(B6),DAY(B6))>=TODAY()
B2: =(TODAY()+$C$2)>=DATE(YEAR(TODAY()),MONTH(B6),DAY(B6))
Range is the number of days after today to show birthdays.
OK slightly different approach
Instead of counting days in a helper column, change the date in a helper column. Then sort that helper column for only the first 5 entries. This will show upcoming birthDAYS instead of birthDATES.
So assuming Names in column A, Dates in Column B, Column C is created with:
=DATE(YEAR(TODAY())+IF(TODAY()>DATE(YEAR(TODAY()),MONTH(B2),DAY(B2)),1,0),MONTH(B2),DAY(B2))
Now I was assuming no header rows and A1 was the first entry so to display the next 5 entries in column D I used:
=IF(ROW()<=5,SMALL($C$1:$C$6,ROW()),"")
Now this will not pull names but just the upcoming birthDAYS not birthDATES. The year being the difference between the two.
If you want to pull the names as well you can use the following:
=IF(D2<>"",INDEX($A$1:$A$6,MATCH(D2,$C$1:$C$6,0)),"")
Right now it will not return names of multiple people with the same date but there are ways around that. If you need that too let us know.
(A) (B) (C) (D) (E)
Steven 58/01/05 17/01/05 16/05/11 Bob
Mike 23/05/12 16/05/12 16/05/12 Mike
Bob 01/05/11 16/05/11 16/10/22 Richard
Richard 85/10/22 16/10/22 16/12/25 Maverick
Maverick 91/12/25 16/12/25 17/01/05 Steven
Ed 54/01/07 17/01/07
UPDATE
In order to deal with duplicate birthdays... try the following:
=IF(E5<>"",INDEX($A$1:$A$6,MATCH(E5,$C$1:$C$6,0)+COUNTIF($E$1:E5,E5)-1),"")
That was the entry for row 5. I tested it with the same birthdate, but I forgot to check for same birthday (different years).
UPDATE 2
NEW TABLE
The table below matches to formula from the last update
(A) (B) (C) (D) (E) (F) (G)
Steven 58/01/05 17/01/05 59 16/05/11 Bob 15
Mike 23/05/12 16/05/12 93 16/05/12 Mike 93
Bob 01/05/11 16/05/11 15 16/10/22 Richard 31
Richard 85/10/22 16/10/22 31 16/12/25 Maverick 25
Maverick 91/12/25 16/12/25 25 16/12/25 Ed 21
Ed 95/12/25 16/12/25 21
I inserted a column in D which shifted things right. The following was placed in D1.
=year(C1)-Year(B1)
In column G I had it lookup the age
=IF(E1<>"",INDEX($D$1:$D$6,MATCH(E1,$C$1:$C$6,0)+COUNTIF($E$1:E1,E1)-1),"")

Tableau - lookup letter grade from range

I have two Excel spreadsheets. One contains average numerical grade for a student and the other a list of letter grades for numeric grades between a min and max
Spreadsheet 1
Student Avg Letter Grade
Mike 91
Joe 76
Mary 84
Sally 78
Spreadsheet 2
Min Max LetterGrade
90 100 A
81 89 B
71 80 C
61 70 D
0 60 F
How do I return the proper grade for each student in Tableau? It seems trivial but I can't figure out the calculation. Thank you for your help!!!
There is an easier way to do this by using Groups.
Import Spreadsheet 1 as a data source
Right Click on "Avg" and select Create Group
From there use Shift Click to group your ranges using Spreadsheet 2 as your reference, using labels "A, B, C"
On the top of the Create Group dialog box, make sure you rename your Field Name as "Letter Grade"
The weakness of this approach is that you have to check/redefine your groups if you are updating your data source. Using IF-ELSEIF statements may be more flexible as Inox suggested in the comments. But this is a relatively easy trick, without any programming involved. :-)
For more info, visit: http://kb.tableau.com/articles/knowledgebase/use-ad-hoc-groups-categorize
Hope this helps!

Resources