I want to write a query that returns the sum of two multiplied cells, where the name is equal to a person's name. Let's say I say I have:
| Name | score | days|
|---------|------|------|
| Suzie | 5.0 | 3
| Jonny | 5.0 | 1
| Suzie | 4.0 | 1
| Suzie | 5.0 | 7
| Jonny | 4.0 | 1
basically, I want to know Suzie's average score. Some rows represent multiple days though. The arithmetic would be
(5.0 * 3)
+ (4.0 * 1)
+ (5.0 * 7)
I want to write a query:
=(index(query({a1:c3}, "Select Sum(Col2 * Col3) where Col1 = '" & D22 & "'"),2))
However, it doesn't like the part that says "Sum(Col2 * Col3)"
Is it possible to do the sum of two columns multiplied?
Thank you in advance!
Please see this sample file.
Data
Col1 Col2 Col3
a 10 20
a 30 40
b 10 30
Result
a 1400
b 300
Formula
=QUERY({A2:A,ARRAYFORMULA(B2:B*C2:C)},
"select Col1, sum(Col2) where Col1 <> '' group by Col1")
You don't need a query.
sum of two multiplied cells, where the name is equal to a person's name
Use SUMPRODUCT(array1, [array2, ...]):
=SUMPRODUCT(B1:B5,C1:C5,A1:A5=D22)
Notice that A1:A5=D22 is a criterion.
average score
Use SUMIF(range, criterion, [sum_range]):
=SUMPRODUCT(B1:B5,C1:C5,A1:A5=D22)/SUMIF(A1:A5,D22,C1:C5)
Related
I need to count how many times ids repeats, without having to specify each id. In my case I need it for know how many customers come 3 times or more in a month. Here is an example of where Im getting the data from:
customers| id
------------------
person 1 | 2433340
person 2 | 3457548
person 3 | 3457584
person 4 | 4343218
person 4 | 4343218
person 4 | 4343218
person 3 | 3457584
And this one is the one that I need to fill:
Times that customers come
--------------------------
1 time | 2
2 times | 1
3 times | 1
I have used:
Formula in D2:
=QUERY(QUERY(B2:B,"Select Count(B) where B is not null group by B label Count(B) 'Times'"),"Select Col1, count(Col1) group by Col1 label count(Col1) 'Count'")
I would work with a helper column (D) to count visits per person. Then it is pretty easy to count the "x times".
Values in column F are numbers formatted as "0 "time""
I've got data like:
06/16/2021 14:35:06 | 10
06/16/2021 15:42:57 | 2
06/16/2021 18:00:48 | 3
06/16/2021 19:11:28 | 7
06/16/2021 20:33:57 | 15
06/17/2021 8:10:40 | 15
06/17/2021 9:17:06 | 14
06/17/2021 10:25:47 | 14
06/17/2021 11:35:05 | 14
And want to display a chart that has totals for each day. To collect the days I've got
=UNIQUE(ARRAYFORMULA(TO_DATE(INT(FILTER(A1:A, A1:A<>"")))))
and I've been able to build up a couple SUMIFs with a single hard-coded value:
=SUMIF(ARRAYFORMULA(EQ(TO_DATE(INT(A1:A)),$K$2)),TRUE(),B1:B)
=SUMIF(ARRAYFORMULA(EQ(TO_DATE(INT(A1:A)),$K$3)),TRUE(),B1:B)
(where K2:K will be the unique dates from the formula above)
I'm just missing the final component - removing the hardcoded K column values and auto-populating it (with an ARRAYFORMULA or QUERY). Any tips?
I believe this should be possible with a single query. See if something like this helps?
=ArrayFormula(query({int(A:A), B:B}, "Select Col1, sum(Col2) where Col1 > 0 group by Col1 label sum(Col2)'' format Col1 'mm/dd/yyyy'", 0))
I am trying to get a value of an intersection of 2 named ranges.
Been searching for a solution for a while now, but can't seem to find any.
So lets say I have a table like this:
# Col1 Col2 Col3 Col4
Row1 | 1 | 6 | 3 | 4 |
Row2 | 6 | 7 | 4 | 2 |
Row3 | 4 | 13 | 9 | 12 |
Row4 | 12 | 3 | 18 | 14 |
These rows and columns are named ranges so Col1 = Sheet!B:B and Row1 = Sheet!2:2 etc.
Now how do I get the value from Col2 Row3 for example?
I have tried =Col2 Row3 and vice versa but it doesn't seem to work that way.
Edit: Here's an example of what I'm trying to do
Thanks in advance,
Dave
the baseline would be:
=INDIRECT(ADDRESS(3, 2))
where row and column can be easily substituted with formulas
Use INDEX/MATCH :
=INDEX(A:E,MATCH(B11,A:A,0),MATCH(B10,1:1,0))
I have an array with states/regions in the UK. Some regions occur more than once in this list, so I have performed a COUNTIF to determine the number of times that each one occur.
Now I need to run a QUERY to list top 5 regions.
Generally, most occurrences are for the London area.
The issue is that in the regions there are 2 states that refer to the Greater London area - London and Greater London.
These two I need to merge and sum their values.
There needs to be only one region - Greater London, and its value needs to hold the sum of London and Greater London.
This is the dataset I have:
+----------------+-------+
| State/Province | count |
+----------------+-------+
| Hampshire | 1 |
+----------------+-------+
| Kent | 2 |
+----------------+-------+
| West Lothian | 3 |
+----------------+-------+
| London | 4 |
+----------------+-------+
| Greater London | 5 |
+----------------+-------+
| Cheshire | 6 |
+----------------+-------+
I have managed to put together this QUERY so far:
=QUERY(A1:B,"select A, max(B) group by A order by max(B) desc limit 5 label max(B) 'Number of occurrences'",1)
That gives me this output:
+----------------+-----------------------+
| State/Province | Number of occurrences |
+----------------+-----------------------+
| Cheshire | 6 |
+----------------+-----------------------+
| Greater London | 5 |
+----------------+-----------------------+
| London | 4 |
+----------------+-----------------------+
| West Lothian | 3 |
+----------------+-----------------------+
| Kent | 2 |
+----------------+-----------------------+
What I need is the Greater London and London entries to be merged under the name Greater London and their numbers of occurrences to be summed, providing this result:
+----------------+-----------------------+
| State/Province | Number of occurrences |
+----------------+-----------------------+
| Greater London | 9 |
+----------------+-----------------------+
| Cheshire | 6 |
+----------------+-----------------------+
| West Lothian | 3 |
+----------------+-----------------------+
| Kent | 2 |
+----------------+-----------------------+
| Hampshire | 1 |
+----------------+-----------------------+
Apologies for not sharing a sheet, but I have security restrictions that are not allowing me to share any link to sheet outside the firm.
=QUERY(QUERY(ARRAYFORMULA(
{SUBSTITUTE(IF(A1:A="London","♥",A1:A),"♥","Greater London"),B1:B}),
"select Col1, sum(Col2)
where Col1 is not null
group by Col1"),
"select Col1, max(Col2)
group by Col1
order by max(Col2) desc
limit 5
label max(Col2)'Number of occurrences'",1)
=QUERY(ARRAYFORMULA(SUBSTITUTE(
IF((A1:A="London")+(A1:A="London2")+(A1:A="London3"),
"♥",A1:A),"♥","Greater London")),
"select Col1, count(Col1)
where Col1 is not null and not Col1 = '#N/A'
group by Col1
order by count(Col1) desc
limit 5
label count(Col1) 'Number of occurrences'", 1)
=QUERY(ARRAYFORMULA(SUBSTITUTE(
IF((QUERY(A1:B,"where B=1")="London")+
(QUERY(A1:B,"where B=1")="London2")+
(QUERY(A1:B,"where B=1")="London3"),
"♥",QUERY(A1:B,"where B=1")),"♥","Greater London")),
"select Col1, count(Col1)
where Col1 is not NULL and not Col1 = '#N/A'
group by Col1
order by count(Col1) desc
limit 5
label count(Col1) 'Number of occurrences'", 1)
Please, need your help !!!
I tried
=query(A1:E6, "select * where D = 'Yes'", 0)
it will select the rows which in column D that has value 'Yes'.
My question is: how to select the columns which in row 2 that has value 'Yes'. I tried:
=query(A1:E6, "select * where 2 = 'Yes'", 0)
but it does not work :(
To do this with QUERY, you would need to do a double TRANSPOSE, or use an alternative like FILTER.
=TRANSPOSE(QUERY(TRANSPOSE(A1:E6),"select * where Col2 = 'Yes'",0))
or
=FILTER(A1:E6,A2:E2="Yes")
Well it can be so simple, and we can use google query SQL features too:
Excel Table:
A B
1 Qty | 200
2 Stock | QUESS
3 Start | 8/24/2019
4 End | 8/23/2020
5 Today | 8/23/2021
Formula:
=query(Transpose(Sheet6!A1:B5),"select *" )
Output :
Qty | Stock | Start | End | Today
200 | QUESS | 8/24/2019 | 8/23/2020 | 8/23/2021
Note : A similar discussion here : [https://stackoverflow.com/questions/63044551/google-sheets-transpose-query/68901704#68901704]