I have 2 google sheets I'm working off. The master and a copy to create a 'dashboard' for analytics.
Master Sheet
name
quantity
price/quantity
RozMo
10
1.75
Tam
3
3.65
Gurba
36
12
Tam
30
0.55
RozMo
25
0.75
RozMo
5
0.50
RozMo
2
0.35
Gurba
150
8.75
Dashboard Sheet - Desired Output
name
quantity
price/quantity
RozMo
42
0.939
Tam
33
0.831
Gurba
186
9.379
Dashboard Sheet - This is how far I've got
name
quantity
price/quantity
RozMo
42
Tam
33
Gurba
186
Formulae used
To get the unique names
=UNIQUE('Master Sheet'!$A$2:$A)
To get quantity
=SUMIFS('Master Sheet'!$B$2:$B,'Master Sheet'!$A$2:$A,A2)
How do I populate the third column?
See how this works for you (I cannot test it, since you did not provide access to the spreadsheet):
=ArrayFormula(QUERY({'Master Sheet'!A2:C,'Master Sheet'!B2:B*'Master Sheet'!C2:C},"Select Col1, SUM(Col2), SUM(Col4)/SUM(Col2) WHERE Col1 Is Not Null GROUP BY Col1 LABEL Col1 'name', SUM(Col2) 'quantity', SUM(Col4)/SUM(Col2) 'price/qty' FORMAT SUM(Col4)/SUM(Col2) '0.000'"))
This one formula should produce all headers and results, formatted according to your full "desired result." If not, share a link to your spreadsheet (or a copy of it).
Related
I need column D summed wherever column A-C are identical. Column E is what I want the output to look like. I am only using google sheet functions right now and have not learned how to write script. This formula is the closest I've gotten.
=SUM(filter(D:D;COUNTIF(A2:A&B:B&C:C;A2:A&B:B&C:C)>1))
However, it does not distinguish between different text strings only sums any duplicate.
Thanks for any help!
A
B
C
D
E
papaya
10/10/2022
500
42
42
papaya
15/12/2022
550
30
59
papaya
15/12/2022
550
29
59
Pineapple
16/11/2022
400
55
55
Pineapple
09/11/2022
400
63
78
Pineapple
09/11/2022
400
15
78
use:
=QUERY(A:E; "select A,B,C,sum(D) where D is not null group by A,B,C label sum(D)''")
update
use in M2:
=INDEX(LAMBDA(bc; g; i; IFERROR(g/VLOOKUP(bc; QUERY({bc\i*1};
"select Col1,sum(Col2) where Col2 > 0 group by Col1 label sum(Col2)''"); 2; )))
(B2:B&C2:C; G2:G; I2:I))
I have a table in Google Sheets with a structure similar to this:
Player
Hometown
Points
Amy
Mapleton
25
Amy
Mapleton
50
Amy
Mapleton
150
Bret
Jersey
10
Colin
Hocksfield
5
Colin
Hocksfield
15
David
Mapleton
200
Ella
Benning
70
Fred
Hocksfield
20
George
Jersey
50
Harold
Dover
30
Except there's about 330 unique hometown values.
I'm trying to get a count of the hometowns that have the most number of players, which would look something like this based on the data above:
Hometown
Players
Mapleton
2
Hocksfield
2
Jersey
2
Benning
1
Dover
1
(There are only 2 players from Mapleton, even though there are 4 "point records" for Mapleton.)
Can somebody help me with a query that would return how many players there are in each hometown, that I can use in a Google Sheet?
You may use QUERY() function like-
=QUERY(UNIQUE(A2:B),
"select Col2, count(Col1)
where Col2 is not null
group by Col2
order by count(Col1) DESC
label Col2 'Hometown', count(Col1) 'Playes'")
Use this
=ArrayFormula({
$B$1,$A$1; UNIQUE(B2:B), IF(UNIQUE(B2:B)="",,
COUNTIF(QUERY(UNIQUE($A$2:$B)," Select Col2"),"="&UNIQUE(B2:B)))})
I've searched everywhere for an answer but haven't been able to find my same problem.
I have a Google Sheet containing two sheets.
Sheet #1:
Site
hour
number
site1
0
333
site1
1
123
site2
0
253
site3
1
124
Sheet #2:
Site
hour
number
site1
0
100
site1
1
124
site1
2
363
site1
3
568
site1
4
876
I would like to match the site and hour from Sheet 1 in Sheet 2, and sum the numbers in the third column.
In this example site1 would equal 224, I hope that makes sense.
Thanks in advance.
Try using vlookup with the first two columns in the two sheets joined together:
=ArrayFormula(query({A2:A,vlookup(A2:A&"|"&B2:B,{Sheet2!A2:A&"|"&B2:B,Sheet2!C2:C},2,false)},
"select Col1,sum(Col2) where Col1 is not null group by Col1"))
A B C
1 Timestamp Hours Worked Total Hours
2 1/2/2022 17:33:41 6
3 1/3/2022 19:59:41 2 January =
4 1/7/2022 13:20:51 1
5 1/9/2022 12:49:02 3 February =
6 1/15/2022 12:04:21 3
7 2/16/2022 15:58:10 9 March =
8 2/22/2022 11:57:31 3
9 2/24/2022 5:45:12 5
10 2/2/2022 17:33:41 4
11 2/3/2022 19:59:41 2
12 2/7/2022 13:20:51 1
13 3/9/2022 12:49:02 3
14 3/15/2022 12:04:28 3
15 3/16/2022 15:58:10 7
16 3/22/2022 11:57:31 3
17 3/24/2022 5:45:12 5
I would like to sum the hours by date/month. I can sum the hours by
column, =sum(b2:b). But how do I sum the hours in Column B by
date/month of column A?
In another post, a member referenced the 'Google Sheets function list'.
I have found that to be very helpful on other things I have been doing.
But I am still at a lose for this problem.
John
You could use the query function with SQL:
=QUERY({(data)}, "select sum(Col2) group by Col1 label Col1 'Date', Col2 'Sum'")
That would return a new table, and you can adjust it by changing the second parameter, representing the SQL string. You can view Google's docs for the query function here. In addition you can find their docs for the query language here.
The simplest solution, without any formula, is to build a pivot table.
use:
=ARRAYFORMULA(REGEXREPLACE(TO_TEXT(QUERY({TEXT(A2:A, "yyymm\×mmmm"), B2:B},
"select Col1,sum(Col2) where Col2 is not null group by Col1 label sum(Col2)''")), "(.*×)", ))
I have 3 sheets that have the exact same format
Sheet1
A B C D
George 10 2 8
Nick 15 89 0
Mike 13 1 50
Lucas 9 -5 12
Sheet2
A B C D
Nick 1 9 5
Mike 1 10 6
George 11 22 5
Lucas 10 5 2
Panos 55 0 1
Sheet3
A B C D
Panos 0 9 1
George 1 2 5
Nick 7 2 1
Lucas 1 5 1
I want to query the range {'Sheet1'!A1:D5; 'Sheet2'!A1:D5; 'Sheet3'!A1:D5}
And get something like MAX(Col2:Col4) Group By Col1
Which would return something like:
George 22
Nick 89
Mike 50
Lucas 12
Panos 55
I tried:
=sort(query({'Sheet1'!A1:D5; 'Sheet2'!A1:D5;'Sheet3'!A1:D5}, "select Col1, MAX(Col2:Col4) Group by Col1 Label MAX(Col2:Col4) '' " ),2, FALSE)
and
=sort(query({'Sheet1'!A1:D5; 'Sheet2'!A1:D5;'Sheet3'!A1:D5}, "select Col1, MAX(MAX(Col2),MAX(Col3), MAX(Col4)) Group by Col1 " ),2, FALSE)
Both didn't work. Any ideas?
Please try:
=query(sort(transpose(query({Sheet1!A1:D5;Sheet2!A1:D5;Sheet3!A1:D5},"select max(Col2), max(Col3), max(Col4) pivot Col1"))),"select Col1, max(Col2) group by Col1 label(Col1) ''")
To sum up your question, It requires finding the MAX across the columns to the right as well as down. As such, QUERY does NOT have such 2D function.
So, Use a Helper column E&F in each sheet:
Max of B&C:
E2:
=ARRAYFORMULA(IF(B2:B>C2:C,B2:B,C2:C))
Max of B,C&D:
F2:
=ARRAYFORMULA(IF(D2:D>E2:E,D2:D,E2:E))
Now, Use Query:
Query:
=ARRAYFORMULA(QUERY({Sheet1!A2:F;Sheet2!A2:F;Sheet3!A2:F}, "Select Col1,max(Col5) where Col1 is not null group by Col1 order by max(Col5) desc"))
Notes:
Change ranges to suit
You could also simply use MAX for each row without the ARRAYFORMULA
Theoretically, For a single cell solution, You could enter this formula to find the max of 3 real numbers
Another approach perhaps a bit simpler but needing two queries
=sort(unique(({Sheet1!A1:A5;Sheet2!A1:A5;Sheet3!A1:A5})))
to get the names starting in (say) F2
Then this to get the maximum values for each name in (say) G2 and pulled down
max(query({Sheet1!A$1:D$5;Sheet2!A$1:D$5;Sheet3!A$1:D$5},"select max(Col2),max(Col3),max(Col4) where Col1='"&F2&"'"))