How to iterate through a function in google sheets? - google-sheets

On one sheet I have a table of statistics similar to this:
A B C D
1 Teams MP GF GA
2 Team A 3 3 2
3 Team B 2 1 3
4 Team C 3 5 2
5 Team D 2 2 1
I then have some formulas that calculate an expected score between two teams set up like this:
A B C D E
7 Teams GF/G GA/G Avg Exp Score
8 Team 1 =VLOOKUP(A8,$A$1:$D$5,3)/VLOOKUP(A8,$A$1:$D$5,2) =VLOOKUP(...) =AVERAGE(...) =B8-C9+D8
9 Team 2 =VLOOKUP(...) =VLOOKUP(...) =AVERAGE(...) =B9-C8+D9
I then have a separate sheet that has the matchups between teams like this:
A B C
1 Date Matchup Exp Score
2 11/15 Team D =FORMULA(
3 11/15 Team B =FORMULA(
4 11/16 Team C =FORMULA(
5 11/16 Team A =FORMULA(
6 11/17 Team B =FORMULA(
7 11/17 Team C =FORMULA(
8 11/17 Team D =FORMULA(
9 11/17 Team A =FORMULA(
My question is if there is some kind of formula that can take the teams in the matchup, copy and paste them behind the scenes into cells A8 and A9, and spit out the Exp Score that would generate in E8 and E9. Is this something that is possible to do in Google Sheets or does it have to be manually copied and pasted into the cells and then copy and paste the results to where I want them?

I've put your formulas together, and come up with the following result, but I think possibly your logic for the average is a little bit off.
Should it not be:
=SUM(C2:C5) / SUM(B2:B5) /2
So the sum of all the goals scored divided by the total number of matches (number of times any team played divided by 2)? This gives the averages goals per game, and then your other formulas add a positive delta to the team with the stronger GF/G, and a negative delta to the team with the weaker GF/G.
Also, your data may not be valid. Shouldn't the total number of goals scored BY all teams, also equal the total number of goals scored AGAINST all teams? So the sum of column C must equal the sum of column D? I therefore changed the numbers in column D slightly.
The result then for your data looks like this:
where the formula in E1 is:
=ArrayFormula({"GF/G";C2:C5/$B2:$B5})
and in G1 is:
=ArrayFormula({"Avg Goals/G";SUM($C$2:$C$5) / (SUM(B2:B5)/2) })
Adding in your matchups and projected scores, I get this:
where the projected scores for all the teams in column I are given by this formula, in K2:
=ArrayFormula(vlookup(I2:I7,$A$2:$G$5,5)
- vlookup(J2:J7,$A$2:$G$5,5)
+ $G$2/2)
Note that I've duplicated columns K:M in columns N:P, but shown with a decimal place to show the average goals per game still equals 2.2, but with rounding adjustments (no fractions of a goal) it doesn't always work out right.
Here is my sample sheet.

Related

Query Select Row and Column together one statement

I work on a google sheet, where I should see the number of holidays per day for each team.
The table looks like this:
[table]
A
B
C
D
E
1
Employee Name
Team Name
01/03/2022
02/03/2022
03/03/2022
2
Employee 1
Team A
hol
hol
hol
3
Employee 2
Team B
early
early
early
4
Employee 3
Team A
hol
late
late
5
6
Team A
7
01/03/2022
8
RESULT HERE
I want to have a result that tells me that Team A had on 01/03/2022 2 holidays.
=countif(query(A1:E4,"select C where B contains '"&A6&"'" ),"hol")
A6 contains the team I am looking for.
A7 contains the date I am looking for.
A8 should show me the number of hol.
Currently, I have a fixed column to look inside which is "C". I want to replace that with the date from A7 - How do I do that?
I tried to play around with transpose and filter but had success.
try:
=COUNTIF(FILTER(FILTER(C2:E4, C1:E1=A7), B2:B4=A6), "hol")
Use XMATCH to get the Col number for QUERY and count inside query instead of COUNTIF:
=QUERY(
{B1:E4},
"Select count(Col1)
where Col"&XMATCH(A7,B1:E1)&"='hol'
and Col1='"&A6&"'
label count(Col1) ''",
1
)

In Google Sheets, I want to get all data from a specific column where the first column matches my SKU. There are multiple rows with that SKU

I have data that looks like this:
sku
price
level
ab1
1.01
1
ab2
2.06
1
ab2
1.45
25
ab3
2.00
1
ab3
1.40
10
ab3
0.89
25
ac2
0.74
1
ac2
0.50
100
As you can see, I have products that have quantity discounts in one sheet. I need to get these levels and prices out of this sheet and into another sheet.
I need to get all prices and levels for all skus, not just the first match. So if my lookup is for sku AB3 I would expect to find 2.00 / 1, 1.40 / 10 and 0.89 / 25
I have not got an extensive Google Sheets knowledge so I am afraid I have hit a brick wall in what to search for.
What do I need to do in order to get this data from sheet a into sheet b.
I have not yet decided how this data is going to look in sheet b, so I don't know if I want the price and level to go into the same cell like "1.01 per 25" or in separate cells.
You can use FILTER() function.
=FILTER(B2:C,A2:A=F1)
Or QUERY() function like-
=QUERY(A2:C,"select B, C where A='" & F1 & "'")

Getting column data and re-arranging it in rows, with a pattern, using formulas

In a worksheet of multiple sheets, I have Sheet1, e.g. with the following: (these rows will be less or more and are manually entered)
Sheet1
A B C
1 APPLE ORANGE LEMON
2 bravo chair mars
3 charlie table jupiter
4 alpha box venus
5 delta saturn
6 foxtrot
I would like some help in constructing Sheet2 via formulas so that it rearranges data from Sheet1 as follows
Sheet2 (Desired result)
A B
1 APPLE
2 bravo
3 charlie
4 alpha
5 delta
6 foxtrot
7
8 ORANGE
9 chair
10 table
11 box
12
13 LEMON
14 mars
15 jupiter
16 venus
17 saturn
It probably needs some combination of QUERY() ARRAYFORMULA(), TRANSPOSE() and/or INDEX() but I need some help with getting started and having them into lesser columns (and more rows.) as shown. Please note that Sheet1's data will keep changing in number of rows (or columns) so Sheet2 needs to adapt to that.
Thank you.
You can try following formula:
=ArrayFormula(
{FILTER(
FLATTEN(TRANSPOSE(IF(ROW(A:F)=1;A:F;"")));
FLATTEN(TRANSPOSE(A:F))<>"")
\FILTER(
FLATTEN(TRANSPOSE(IF(ROW(A:F)<>1;A:F;"")));
FLATTEN(TRANSPOSE(A:F))<>"")}
)
if you use semicolon as function argument separator.
If you use comma, change to
=ArrayFormula(
{FILTER(
FLATTEN(TRANSPOSE(IF(ROW(A:F)=1,A:F,""))),
FLATTEN(TRANSPOSE(A:F))<>"")
,FILTER(
FLATTEN(TRANSPOSE(IF(ROW(A:F)<>1,A:F,""))),
FLATTEN(TRANSPOSE(A:F))<>"")}
)
The formula will run faster if you specify a row constraint.

Google Spreadsheet - compare cells on same row and get number of matches?

I have values in column A, B and C for Google Spreadsheet:
A contains the results of each match (1X2)
B is what person B guessed that match
C is what person C guessed
Players can for each match guess 1 (home win), x (equal), 2 (away win) or a combination of them, like x2.
How can I compare the player's guesses (column B and C) with the match result (column A) and get the number of correct answers/matches?
Example:
Person B scores three points, because he guessed three matches correctly (not the second match though).
A B C
1 1x x2
x 1 x
2 2 1x
x 1x 2
CORRECT: 3 1
Add 2 columns D and E, than represent either a 0 or 1, then sum columns D & E. You would then put:
D2=IF(A2=B2,1,0)
E2=IF(A2=C2,1,0)
Then just copy paste formulas - since you aren't using absolute $ syntax for rows 3,4,5 etc.
Then just have D1=SUM(D2:D99) E1=SUM(E2:E99) - or something to that effect depending on number of rows.

Google sheets compare 2 fields on a different sheet and return one based on criteria

I have 2 different Google Sheets. Master Sales & Projections. On Master Sales I have 2 columns, Expected & Billed which has data broken down by billing weeks.
I need Sheet 2 to grab the data from the cell that not 0 since we are trying to track total sales for the month (expected & actual) and then at the end of the month we would have the real billed numbers.
Potato example below
Sheet 1
A B
1 Expect Billed
2 $123 $145
3 $145 $155
4 $156 $0
5 $132 $0
What Sheet 2 should look like
A B
1 Week1 $145
2 Week2 $155
3 Week3 $156
4 Week4 $132
Assuming you will arrange for the week numbers, in B1 please try:
={query(Sheet1!A2:B5,"select B where B<>0",0);query(Sheet1!A2:B5,"select A where B=0",0)}

Resources