Top N people with fastest times across all laps - google-sheets

Name1 Name2 Name3 NameN
Lap1 1:20 1:30 1:19 1:40
Lap2 1:40 1:40 1:20 1:40
Lap3 1:30 1:19 1:22 1:20
LapN 1:19 1:21 1:20 1:19
I need to pull some statistics from a similar data set.
For example person with the most fastest laps, person with most 2nd fastest laps, etc.
I can't use a helper column.
Output In the format "NameN - count"
In this case the person with fastest laps would be "Name3 - 2 laps", 2nd fastest laps "Name1 - 2 laps" etc.
I tried adapting this formula I found from Excel but I can't make it work.
=LET(range,B2:E4,
nrows,ROWS(range),
ncols,COLUMNS(range),
ncells,COUNT(range),
races,INT(SEQUENCE(ncells,1,0)/ncols+1),
names,MOD(SEQUENCE(ncells,1,0),4)+1,
headers,B1:E1,
winners,SEQUENCE(nrows,1,1,ncols),
times,INDEX(range,races,names),
INDEX(headers,(MODE(INDEX(SORTBY(CHOOSE({1,2,3},races,names,times),races,1,times,1),winners,2)))))

first we find the fastest time per lap:
=INDEX(QUERY(SPLIT(FLATTEN(ROW(A2:A10)&"♦"&B2:E10), "♦"),
"select min(Col2) where Col2 is not null group by Col1 label min(Col2)''"))
next, we substitute times for names:
=ARRAYFORMULA(IF((B2:E10<>"")*(B2:E10=F2:F10), B1:E1, ))
and now we can count top players:
=QUERY(FLATTEN(G2:J10),
"select Col1,count(Col1)
where Col1 is not null
group by Col1
order by count(Col1) desc
label count(Col1)''")
all in one:
=INDEX(QUERY(FLATTEN(IFERROR(IF((B2:E10<>"")*(B2:E10=
QUERY(SPLIT(FLATTEN(ROW(A2:A10)&"♦"&B2:E10), "♦"),
"select min(Col2)
where Col2 is not null
group by Col1
label min(Col2)''")), B1:E1, ))),
"select Col1,count(Col1)
where Col1 is not null
group by Col1
order by count(Col1) desc
label count(Col1)''"))
and if you want you can add limit like this:

Related

How to find most frequent value in two columns based on a condition in Google Sheets?

I'm not too savvy with programming, so bear with me. The data is of the players' names and fighters in a fighting game, with the table as below:
I'm making a leaderboard where it will show which fighter each player uses most. I found a formula that shows which fighter is used the most in general using the following formula:
=index(query({E2:E,G2:G},
"select Col1,count(Col1)
group by Col1
order by count(Col1) desc"), 2, 1)
The problem is, I don't understand how to make a formula that checks the player's name before returning the most used fighter from two columns. What I'm after is a result like so:
Thanks in advance!
Formula
=ArrayFormula(
{QUERY(QUERY({SPLIT("Wins"&"|"&UNIQUE({D2:D;F2:F}&"|"&"."),"|");SPLIT("Loss"&"|"&UNIQUE({D2:D;F2:F}&"|"&"."),"|");
SPLIT("Wins"&"|"&FILTER(D2:D&"|"&E2:E,D2:D<>""),"|");
SPLIT("Loss"&"|"&FILTER(F2:F&"|"&G2:G,F2:F<>""),"|")},
"select Col2,count(Col3)-1 where Col2!='.' group by Col2 pivot Col1"),"select Col1,Col3,Col2,Col3/Col2,Col3/(Col3+Col2) order by Col3 desc label Col1 'Name',Col2 'Loss',Col3 'Wins',Col3/Col2 'W/L',Col3/(Col3+Col2) 'Win Rate %' format Col3/Col2 '0.0',Col3/(Col3+Col2) '#.0%'"),
VLOOKUP(INDEX(QUERY({D2:D},"select Col1,count(Col1) where Col1!='' group by Col1 order by count(Col1) desc label Col1 'Name'"),0,1),QUERY({D2:E;F2:G},"select Col1,Col2,count(Col2) group by Col1,Col2 order by Count(Col2) desc label Col1 'Name',Col2 'Most Used Character'"),2,0)})
Note:
column Wins/Loss cannot be calculated when Loss=0 .
Hope you're okay with that

Max Sum of row within date range - Google Sheets

I am using Google Sheets.
I have names in first column, dates in first row, and numbers for each name/date.
I want to return the name and sum of numbers for the person who's sum of numbers is the largest (within date range.)
A cell formula for this would be better than a script.
It sounds straight forward but am going in circles and would appreciate help. Thanks Newman
Thank you.
try:
=INDEX(QUERY(SPLIT(FLATTEN(A3:A&"♦"&FILTER(B3:F, B2:F2>="2021-10-07"*1, B2:F2<="2021-10-13"*1)), "♦"),
"select Col1,sum(Col2) where Col2 is not null group by Col1 order by sum(Col2) desc label sum(Col2)''"))
and for just 1 record:
=INDEX(QUERY(QUERY(SPLIT(FLATTEN(A3:A&"♦"&FILTER(B3:F, B2:F2>="2021-10-07"*1, B2:F2<="2021-10-13"*1)), "♦"),
"select Col1,sum(Col2) where Col2 is not null group by Col1 order by sum(Col2) desc label sum(Col2)''"), "limit 1", 0)

Query Formula using Google Sheets - count data from multiple columns and return results in a single column

I am trying to calculate a count of how many times a course is listed in different columns and return the count in a list of all the courses found in those columns.
I have a spreadsheet that shows the start of my formula...
query(UNIQUE({C2:C21; F2:F21;I2:I21}),"select C,F,I, count(C), count(F), count(I) where B is not null group by C,F,I")
Clear cells A23, A24 and B23 and then try in A23
=query({C2:C21; F2:F21;I2:I21},"select Col1, count(Col1) where Col1 <> '' group by Col1 label Col1 'Fall Courses', Count(Col1) 'Count'")
and see if that helps?
If it does, you can repeat the same logic for 'winter' and 'spring'.
Alternatively, you can also try this single formula
=query(ArrayFormula(split(transpose(split(textjoin("~", true, regexreplace(C1:K1, "(Winter|Spring|Fall)", "_$1")&"_"&C2:K21), "~")), "_")), "Select Col3, Count(Col3) where Col3 <>'' group by Col3 pivot Col2", 0)

I want to sum value of of third column based on other two columns value in google sheets and col1 and col2 contains multiple duplicate values

https://docs.google.com/spreadsheets/d/1_MeiySJHI8OD84BPDOj_z57My-TXbs2ey4AOkQP3zug/edit?usp=sharing
I am sharing the link of sheet on which I want solution on that sheet also I have tried to explain you the question.
I have three columns I want sum of third col3 value based on first two column value
if col1 = 2 and col2 = 40; Then I should get the sum of all value in col3 in which col1 = 2 and col2 = 40
if the col1 contains value of 2 and col2 contains 40 than sum of col3 value only those col3 value in which col1=2 and col2=40
so if any of the column value changes than sum of col3 also sum according to that.
use:
={"result"; INDEX(IF(COUNTIFS(A2:A&" "&B2:B, A2:A&" "&B2:B, ROW(A2:A), "<="&ROW(A2:A))=1,
IFNA(VLOOKUP(A2:A&" "&B2:B,
QUERY({A2:A&" "&B2:B, C2:C},
"select Col1,sum(Col2) where Col1 is not null group by Col1 label sum(Col2)''"), 2, 0)), ))}
In cell K4 I entered
={"Result Col"; ArrayFormula(if(len(G5:G),if(match(G5:G&H5:H,G5:G&H5:H,0)+4=row(G5:G),sumif(G5:G&H5:H,G5:G&H5:H,I5:I),),))}
I used the same formula (with different range) in E1 (for what I assume to be your 'real' data).
See if that helps?
The simpliest solution is to use a pivot table, see inside your spreadsheet. If you want the total inside the original data, and take advantage of this simple solution, you can then recall the total by GETPIVOTDATA

Getting the count of a column from a set of comma separated values?

I have two columns and I want to get a list of unique Places with the a sum of the Count from the next column.
For example:
Current
Places (ColumnA) Count(ColumnB)
Italy, Greece, France 10
Italy, Greece 5
France 1
Desired outcome
Places (ColumnD) Count(ColumnE)
Italy 15
Greece 15
France 11
Assuming your data starts in row 2, try in D2:
=ArrayFormula({unique(trim(transpose(split(concatenate(A2:A&","),",")))),sumif(A2:A, "=*"&unique(trim(transpose(split(concatenate(A2:A&","),","))))&"*",B2:B)})
or, alternatively:
=query(ArrayFormula({transpose(split(query(substitute(A2:A,",",""),,50000)," ")),transpose(split(concatenate(rept(B2:B&char(9), len(A2:A)-len(substitute(A2:A, ",",""))+1 )),char(9)))}), "select Col1, sum(Col2) where Col1 <>'' group by Col1 label sum(Col2)'' ")
Yet another way (credits to AdamL for this one):
=ArrayFormula(QUERY(TRANSPOSE(SPLIT(QUERY(REPT(A2:A&", ",B2:B),,ROWS(A2:A)),", "))&{"",""},"select Col1, count(Col2) group by Col1 label count(Col2) ''",0))

Resources