ARRAYFORMULA to SUMIF on datestamps - google-sheets

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

Related

Count unique comma-separated values in column B based on criteria in column A

How do I list and count unique comma-separated values (column B in the example below) if the number in column A is larger (or smaller) than X? In other words, how do I turn the below table...
Day | Fruits
+--------|--------------------------+
|
20 | Apple, Banana, Pearl
|
24 | Apple, Pearl
|
32 | Banana, Pearl
+
...into this 👇, with criteria: Day < 28.
Fruit | Frequency
+----------|---------------+
|
Apple | 2
|
Pearl | 2
|
Banana | 1
+
A solution proposed by #AdamL in this question is really close to what I want to achieve, but I can't figure out how to list values based on criteria from another column. Here's what Adam came up with:
=ArrayFormula(QUERY(TRANSPOSE(SPLIT(JOIN(",",A:A),",")&{"";""}),"select Col1, count(Col2) group by Col1 label count(Col2) ''",0))
use:
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(
IF(IFERROR(SPLIT(B2:B, ","))="",,A2:A&"♦"&TRIM(SPLIT(B2:B, ",")))), "♦"),
"select Col2,count(Col2)
where Col1 < 28
and Col1 is not null
group by Col2
label count(Col2)''"))
I think it's a bit easier to filter on column A first then split:
=ArrayFormula(query(flatten(split(filter(B2:B,A2:A<28,A2:A<>""),",")),"select Col1,count(Col1) where Col1 is not null group by Col1 label Col1 'Fruit',Count(Col1) 'Count'"))
Considering Column 'A' as days and Column 'B' as fruits with row 1 as headers, AdamL's formula works for you with a little tweak as below:
=ArrayFormula(QUERY(TRANSPOSE(SPLIT(JOIN(",",B2:B),", ",True)&{"";""}),"select Col1, count(Col2) group by Col1 label count(Col2) ''",0))
Hope this solves your problem.

How to get the cell value of an intersection between 2 named ranges in Google Spreadsheet

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

In Google Sheets How do I get a sum of comma separated values in rows against an ID

I have a table which has a list of id's against names
Sheet 1
A | B
1 | Joe
12 | Dave
23 | Pete
I then have a table of rows which shows when a person was present at an event (through their ID)
Sheet 2
A | B
boston | 1
florida | 1,12
nyc | 12,23
In the 3rd sheet for appearances, I am then looking to achieve the following
Sheet 3
A | B (Appearances)
Joe | 2
Dave | 2
Pete | 1
I can get this to work when just one person makes an appearance with something like =COUNTIF(appearances!A:A, INDEX(name_db!$A$2:$A$1000, MATCH ($A11, name_db!$B$2:$B$1000, 0)))
But as soon as I add a comma value it all goes wrong.
I've tried looking into vLOOKUPS and things like that but can't seem to quite figure it out
Any help on where to look would be much appreciated
=ARRAYFORMULA(IFERROR(VLOOKUP(G:G, QUERY(VLOOKUP(TRANSPOSE(SPLIT(CONCATENATE(
IF(IFERROR(SPLIT(E:E, ","))<>"", "♦"&SPLIT(E:E, ","), )), "♦")), A:B, 2, 0),
"select Col1,count(Col1) group by Col1 label count(Col1)''", 0), 2, 0)))
This works for me:
=ARRAYFORMULA(IFERROR(SUM(SPLIT(D2;","))))

COUNTIF(FILTER(range;condition);criteria) issue in Google Speadsheet

I've a strange result which I cannot explain.
The spreadsheet looks like this (I simplify the data as it's a part of larger sheet):
A | B
-----+---
1 X | Y
2 |
3 |
4 1 |
5 1 |
6 1 |
7 1 |
8 1 |
9 1 |
10 1 |
11 1 |
12 1 |
13 1 |
14 |
...and so empty rows till the end of the sheet.
Cell B2 contains formula:
=COUNTIF(filter(B4:B;$A4:$A = B4:B);"<>0")
Cell B3 contains formula:
=COUNTIF(filter(B4:B13;$A4:$A13 = B4:B13);"<>0")
What I expected to get is 0 in both B2 and B3 cells. Instead of that I receive 0 in B2 and 1 in B3.
The formulas suppose to count number of same non-empty values in column (B2) or part of the column (B3).
Do you have any ideas?
For the same reason that this gives 1:
=countif(na(),"<>0")
The filter in B3 gives no results, so you get "#N/A". When you feed this into COUNTIF, you get 1.
The filter in B2 does give some results (because it succeeds for all the blank cells in cols A & B). But the results are all blanks so you get a count of 0.
Similar approach that I had is this one.
Basically it uses the following formula:
=ArrayFormula({"Count [Erik]";IF(B2:B="","",IFERROR(VLOOKUP(B2:B&"",QUERY({MyTable!B2:B&"",MyTable!C2:C},"Select Col1, COUNT(Col2) Where Col1 Is Not Null And Col2 = 'CriteriaA' Group By Col1"),2,FALSE)))})
(credits to Erik Tyler)

Query the sum of a product

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)

Resources