Google Sheets: how to refer to a row with specific text - google-sheets

-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.

Related

Google Sheet: formula to loop through a range

It's not hard to do this with custom function, but I'm wondering if there is a way to do it using a formula. Because datas won't automatically update when using custom function.
So I have a course list sheet, each with a price. And I'm using google form to let users choose what courses they will take. Users are allowed to take multiple courses, so how many they will take is unknown.
Now in the response sheet, I have datas like
Order ID
User ID
Courses
Total
1001
38
courseA, courseC
What formula to put here?
1002
44
courseB, courseC, courseD
What formula to put here?
1003
55
courseE
What formula to put here?
and the course sheet is like
course
Price
A
23
B
33
C
44
D
23
E
55
I want to output the total for each order and am looking at using FILTER to do this. Firstly I can get a range of unknown length for the chosen courses
=SPLIT(courses, ",") // having named the Courses column as "courses"
Now I need to filter this range against the course sheet? not quite sure how to do it or even if it is possible. Any hint is appreicated.
try:
=ARRAYFORMULA(IF(A2:A="",,MMULT(IFERROR(
VLOOKUP(SPLIT(C2:C, ", "), {F1&F2:F, G2:G}, 2, 0))*1,
ROW(INDIRECT("1:"&COLUMNS(SPLIT(C2:C, ", "))))^0)))
demo spreadsheet
As I need time to digest #player0's answer, I am doing this in a more intuitive way.
I create 2 sheets to store intermediate values.
The first one is named "chosen_courses"
Order ID
User ID
1001
=IFERROR(ARRAYFORMULA(TRIM(SPLIT(index(courses,Row(),1),","))),"")
1002
=IFERROR(ARRAYFORMULA(TRIM(SPLIT(index(courses,Row(),1),","))),"")
1003
=IFERROR(ARRAYFORMULA(TRIM(SPLIT(index(courses,Row(),1),","))),"")
In this sheet every row is a horizontal list of the chosen courses, and I created another sheet
total
course price
=IF(isblank(order_id),"",SUM(B2:2))
=IFERROR(VLOOKUP('chosen_courses'!B2,{course_Names,course_price},2,false),"")
=IF(isblank(order_id),"",SUM(C2:2))
=IFERROR(VLOOKUP('chosen_courses'!B2,{course_Names,course_price},2,false),"")
=IF(isblank(order_id),"",SUM(D2:2))
=IFERROR(VLOOKUP('chosen_courses'!B2,{course_Names,course_price},2,false),"")
course_Names,order_id and course_price are named ranges.
This works well, at least for now.
But there is a problem:
I have 20 courses, so in the 2nd sheed, there are 21 columns. And I copy the formulas to 1000 rows because that is the maximum rows you can get to using ctrl+shift+↓ and ctrl+D. Now sometimes when I open the sheet, there will be a progress bar calculating formulas in this sheet, which could take around 2 mins, even though I have only like 5 testing orders in the sheet. I am afraid this will get worse when I have more datas or when it is open by old computers.
Is it because I use some resource consuming functions? Can it be improved?

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

Match 3 cells pair with other 3 cells pair. Google Sheets

I'm using Google Sheets for our production price calculation and we are getting new orders with different data every week.
I have all the price calculations sorted out but sometimes there are the same data in orders that already been in the past and I have to manually search for it and use the same price if it exists.
As you can see in the example above, when I enter in the selected cell data "100", I have to check if it already exists in cells above (all three cell in the same row) and if it does enter its price on the cell on the right("=" sign), if it doesn't it could say "new" or be left empty.
I looked at the INDEX and MATCH functions but they don't seem to do the trick.
Do you have any suggestions? Of course the formula should be easily copied to every next cell down when new data and orders come in.
Approach
In this case it's useful to have an index for your table. I created a simple one that concatenates the 3 values you have with the & operator. You can see in the table below for the complete formula. Just drag it down to the whole table to make it automatic.
For the price calculation then I am using a VLOOKUP. It will search for the index generated by the three values in the new row and get the corresponding Price if ti exists. If not, it will print NEW. That's just a placeholder of course, you can edit it as you want. I put the first cell of your table as absolute reference in the VLOOKUP formula so you can drag it down and it will always get its upper (already filled) portion.
Table
INDEX X Y Z Price
11010030 110 100 30 1
500300100 500 300 100 2.3
12030010 120 300 10 1.2
500300100 500 300 100 2.3
12030010 120 300 10 1.2
11010030 110 100 30 1
3004510 300 45 10 NEW
11010030 110 100 30 1
=B10&C10&D10 =IFERROR(VLOOKUP(A10, $A$2:I9,5,0), "NEW")
Based on the correct initial thought by Alessandro, please use the following single arrayformula in cell E2
=ArrayFormula(IF(LEN(A2:A)>0,
IF(LEN(D2:D)>0,
VLOOKUP(A2:A&B2:B&C2:C, {A2:A&B2:B&C2:C,D2:D},2,0),"new"),""))
The formula works as a helper column, only showing you what price to use in column D (if it previously exists) or lets you know that you need to calculate a new one.
Functions used:
VLOOKUP
ArrayFormula
LEN
IF

Google Sheets Query Group By / First-N-Per-Group

I'm trying to find a simple solution for first-n-per-group.
I have a table of data, first column dates and rest data. I want to group based around the date, as multiple entries per date are allowed. For the second column some numbers, but want the FIRST record.
Currently the aggregate function I could possibly use is MIN() but that will return the lowest value and not the first.
A B
01/01/2018 10
01/01/2018 15
02/01/2018 10
02/01/2018 2
02/01/2018 100
02/01/2018 20
03/01/2018 5
03/01/2018 2
Desired output
A B
01/01/2018 10
02/01/2018 10
03/01/2018 5
Current results using MIN() - undesired
A B
01/01/2018 10
02/01/2018 2
03/01/2018 2
It's a shame there isn't a FIRST() aggregate function in Google Sheets, which would make this a lot easier.
I saw a couple of examples of using the Row Number and ArrayQuery, but that doesn't seem to work for me. There are about 5000 rows of data so trying to keep this as efficient as possible, and not have to recalculate the entire sheet on any change, each taking a few seconds.
Currently I have this, which appends a third column with the Row Number:
=query({A1:B, arrayformula(row(A1:B))}, "select min(Col1),min(Col2) group by Col1")
Thanks
EDIT 1
A suggested solution was =SORTN(A:B,2^99,2,1,1), which is a clean simple one. However, this requires a large range of "free space" to display the returned dataset. Imagine 3000+ rows.
I was hoping for a QUERY() -based solution, as I wanted to do further operations with the results. Specifically, count the occurrences of distinct values.
For example: I wanted a returned dataset of
A B
01/01/2018 10
02/01/2018 10
03/01/2018 5
Yet I want to count the occurrences of those values (and then ignoring the dates). For example:
B C
10 2
5 1
Perhaps I've confused the situation by using numbers? the "data" in ColB is TEXT (short 3 letter codes), however I used numbers to show I couldn't use MIN() function as that returns the numerically lowest value.
So in brief:
Go through all rows (3000+ rows) and group by the FIRST row of a particular date
return the FIRST value of that row
COUNT() all unique occurrences of those FIRST values, disregarding the date. Just a list with the unique values and their count (again, only the first one of any particular day)
=SORTN(A:B,2^99,2,1,1)
If your data is sorted as in the sample, You can easily remove duplicates with SORTN()

How to do a sum of a column if a particular cell of each row matches a particular value?

I'm trying to make a budget sheet for a trip.
I have 2 sheets in a Google Spreadsheet. One contains the steps of the trip. The other contains a dashboard with the sum for each of these 5 groups of steps: "food", "activities", "shopping", "hotels" and "vehicle".
My first sheet is like that (with 4 columns - the 3rd is the price):
1. Go to museum 45 Activity
2. Playing cards 5 Activity
3. Sleeping at Bohaha Hotel 123 Hotel
4. Take breakfast 10 Food
In the other sheet, I want to make different sums conditioned by the value of the 4th column, and using the values of the 3rd column.
The result of the second sheet in this example would be:
Food 10
Activities 50
Shopping 0
Hotels 123
Vehicle 0
How can I do that?
I can use a function if necessary.
Simple SUMIFS:
=SUMIFS(Sheet1!C1:C99, Sheet1!D1:D99, A1)
Assuming description in second sheet matches description in 4th column (the formula is not going to do the stemming for you to convert Activity to Activities - you can use 1 column for exact match string and 1 column as reporting label...)
I found the perfect formula :)
=SUM(FILTER('Sheet 1'!H5:H; 'Sheet 1'!G5:G="Food"))

Resources