Google Sheets Query While Removing Duplicates - google-sheets

I have an issue with google sheets, and I'm a bit new to the query functions so I'm not positive on how to correct this issue. Assume I have a list of data with arcade game high-scores. So the data will look something like this, but much longer and with multiple games:
Player Name
Arcade Game
Date
Score
Player A
Pac Man
1/5/20
1000
Player B
Pac Man
4/6/20
800
Player C
Pac Man
3/15/20
900
Player A
Pac Man
12/10/20
1100
Now I'm trying to write a query that will pull by game, the top 5 high scores. However, I want to exclude duplicates player entries from the title. So if player A is at the arcade every day, and consistently gets high scores they could occupy all 5 of the top scores. However, I want my query request to only include them once, so their top score is included, but then the other players are listed, even though player A technically has multiple higher scores.
This means instead of my query returning "Player A, Player A, Player A" into each row, it returns "Player A, Player C, Player B"
Currently my query (with no duplicate removal) looks like this:
=QUERY('Data'!$A:$D, "Select A,D,C where "B='Pac Man' Order by D Desc Limit 5")
This returns a list of the top 5 high scores for the selected game, while also listing the date and player. However, I am unsure how to edit my query to remove all scores from each player except their top score.
I have tried using the "group by" query language, but was unsuccessful and only ended up with errors. I could also take the original data, and run it through a second function to clean up the duplicates, and then run my query on the updated data, although that seems like a lot of effort for something query should be able to do.
Thanks!

Try
=QUERY(Data!A:D, "Select A, max(D), max(C) where B='Pac Man' Group by A Order by max(D) Desc Limit 5 label max(D) 'Date', max(C) 'Score'", 1)
and see if that helps?

Related

Google Sheets: how to refer to a row with specific text

-I'm trying to create a google sheet that tracks progress of players in a team.
-Each season has its own tab.
-A tab that combines data from all sheets is needed.
-The players in the seasonal tabs are going to be in different order each season based on their performance, there are also going to be players coming and going so I can't know which row is going to include which player's data.
-The combined table needs to be able to refer to rows in other tabs where the player name is present, and count up total points for them.
Picture 1 is individual season table. Picture 2 is where I was stuck. Picture 3 is the desired output, which was achieved using the answer provided.
Example of desired output:
Player
Season 17
Season 18
Total
Player1
1800
880
1680
Player4
100
100
200
Player12
50
21
71
Player2
33
11
44
Player3
2
5
7
Player33
1
2
3
You can merge all the data in a new sheet by using the following formula:
={FILTER(Sheet1!$B$3:$P, len(Sheet1!$B$3:$P)),
FILTER(Sheet2!$B$3:$P, len(Sheet1!$B$3:$P)),
FILTER(SheetN!$B$3:$P, len(Sheet1!$B$3:$P))}`
You have to repeat the FILTER(...) part for each sheet.
In the new sheet, get the list of unique user names with =UNIQUE($A:$A), where A is the column with the player names. You can also use a list you already have instead.
You can then use =SUMIF($A:$A;P1;$B:$B) to compute the grand total for each player, where A is the column containing all the names, B the column containing all the total scores, and P the column containing the UNIQUE player names.
Alternatively, you can use =VLOOKUP(P1, SheetN!$B$3:$N$100, 13, FALSE) in the new sheet to read the total score of the player with the name in the cell P1.
I think that with more advanced magic you may be able to automatically gather the data from all the sheets, but in this case you have to manually type each heet name.

combining STDEV & VLOOKUP

I am trying to find the STDEV of a specific teams score based on the seasons completed games.
I want to accomplish this by using vlookup. I came up with this formula but it shoots a DIV/0 error.
=STDEV(vlookup(B19,'2021 Game Log'!A2:B,2,false))
basically now I have the STDEV of ALL AWAY GAMES.... I'd like to refine that and get the STDEV of ONLY the AWAY team that's listed in that games "B cell". The scores are listed in 2021 Game Log. (that make sense?)
https://docs.google.com/spreadsheets/d/1F2t8RDp1qDDoGEMCdYOOxGDlDQHyZNaDQ8nRr7qP3v4/edit?usp=sharing
Here is a screenshot that might help.
https://i.stack.imgur.com/AK1l0.png
the output of your:
=VLOOKUP(B19, '2021 Game Log'!A2:B, 2, 0)
is:
3
eg. it's a single value so it's same as if you would run:
=STDEV(3)
and that translates to error because there is only one value you trying to STDEV
... I believe this is what you need:
=STDEV(FILTER('2021 Game Log'!B2:B, '2021 Game Log'!A2:A=B19))

How to calculate average based on more factors in google sheets

I have a spreadsheet and I would like to calculate average for each team for 1st half. So, for California, if it's under Home team column, then I should use Home 1st half score column, if it's in Away team column, then Away 1st half score should be used. Currently I have a formula =AVERAGE(AVERAGEIF(C9:C165,C166,E9:E165),AVERAGEIF(D9:D165,C166,F9:F165)) but the problem is if a team has played only away games, then formula throws an error that it can't be divided by 0 because there are no home score results. I would like to calculate average for every team like this.
You can use IFERROR:
=IFERROR(AVERAGE(AVERAGEIF(C9:C165,C166,E9:E165),AVERAGEIF(D9:D165,C166,F9:F165)), AVERAGEIF(D9:D165,C166,F9:F165))
In toher words: If you cannot make and avarage between column C and D because column C si empty - only the average of column D will be returned.
You can nest the formula into a second IFERROR to catch the case when column D is empty.

Formula to create multiple possible results

The spreadsheet I am devising is to help me with the scoring of a football (or soccer depending where you're from) forum game I run. The idea is that each player picks 10 football teams and they get a point for each goal scored. However, they also pick one team which they think will not score any goals. If their team doesn't score they get 3 points but if the team does score they lose a point for every goal the team scores.
For example - Example A) The player picks Man Utd to not score a goal but they score 3. This means that the player would score -3 points. Example B) The player picks Man Utd to not score a goal and they don't. This means that the player would score 3 points.
Is there a way to create a formula for this specific selection to go into cells F13 and J13 which would match the team in the list in Column A to what I have entered in Column D and H and if the score next to this team (in Column B) is "0" it allocates 3 points to the cell F13 and J13 but if the score in Column B is above 0 (eg 3), the value in cell F13 and J13 reads as minus the value shown in Column B (eg -3).
Template spreadsheet can be found here - https://docs.google.com/spreadsheets/d/1DNOVUGPAJF-nR9XtQ1fc-lqm4fYHNBJgz7-rr6SzJaU/edit?usp=sharing (not sure if I have set it correctly to allow editing but if I have then feel free to edit away)
Hope this makes sense!
Please use the following formula on your F13 cell (and all the corresponding ones for the rest of the players)
=IF(-VLOOKUP( D13,$A$2:$B,2,0)=0,3,-VLOOKUP( D13,$A$2:$B,2,0))
You could probably use a single formula on your F1 cell.
=ArrayFormula(IF(C1:C11=TRUE,C1:C11*E1:E11,1))
Functions used:
ArrayFormula
IF
VLOOKUP

Query for SUM values on multiple columns, then substract and compare results

I have the following scenario:
A Google Sheet to collect daily Cash Flow on two shifts (Morning and Afternoon), starting each shift with money on hand (cash) and money on bank account (to pay bills and make transfers as necessary).
The circuit works by recording money IN or money OUT and using the direction of the flow as a basic selector, in order to determine by adding and substracting, how much money came in, and how much came out.
I've been testing with long QUERY formulae to try to come out with results, but so far, I managed to only filter by means of SUM(X). However, I been trying after reading all documentation about Query Formula, to select and sum every income for every shift within the day, do the math, compare with the starting cash, and determine how much money by means of payment, date and shift came in or out.
This is the Query formula for the collected items:
=QUERY(A1:Q,"SELECT A,B, SUM(G), SUM(H), SUM(I), SUM(J), SUM(K) WHERE E='Collected' AND L='Cash' GROUP BY A,B LABEL SUM(G)'Rentals Collected' ",2)
And this is the Query formula for the paid items:
=QUERY(A1:Q,"SELECT A,B, SUM(G), SUM(H), SUM(I), SUM(J), SUM(K) WHERE E='Paid' AND L='Cash' GROUP BY A,B LABEL SUM(G)'Rentals Paid' ",2)
I've also used this Query formula for displaying money available on hand at the start of each shift, for each day.
=QUERY(A:Q, "SELECT A,B,C,D WHERE C IS NOT NULL", 2)
Any ideas?
Here's a Dummy Sheet that recreates the scenario.

Resources