How to sum values for each day in google sheets - google-sheets

I want to make two columns one that has date and the other that has sum for the number of violations occurred on that day. Have a look at the data below.

use:
=QUERY({B:C}; "select Col1,sum(Col2) where Col1 is not null group by Col1 label sum(Col1)''")

Related

How to split sum by month? in googlesheets?

Hello, please help me
How to split sum by month? in googlesheets ?
Try:
Formula in J3:
=INDEX(QUERY({TEXT(B3:B,"YYYY-MM"),H3:H},"Select Col1, sum(Col2) where Col2>0 group by Col1 label Col1 'month'"))
Use this formula
= ArrayFormula(
{ TEXT(DATE(YEAR(TODAY());UNIQUE(MONTH(A3:A));DAY(TODAY())); "mmmm yyyy")\ IF(SUMIF(MONTH(A3:A); UNIQUE(MONTH(A3:A));H3:H)=0;;TEXT(SUMIF(MONTH(A3:A); UNIQUE(MONTH(A3:A)); H3:H); "Rp#,###"))})
Formula:
=ARRAYFORMULA(SUMIF(MONTH(A3:A); UNIQUE(MONTH(A3:A)); H3:H))
Explanation:
MONTH(A3:A) extracts the month from the dates in column A
UNIQUE(MONTH(A3:A)) finds the unique months from this list
SUMIF() takes the month of each row as the range for the summation, the list of unique months as the criteria, and then the total values H3:H as the range to sum.
ARRAYFORMULA() expands it to all rows below
Use QUERY() function with date columns so that we can sort if needed. Use EOMONTH() to make group by month.
=QUERY({INDEX(IF(B2:B="",,EOMONTH(B2:B,0))),E2:E},"select Col1,sum(Col2)
where Col1 is not null
group by Col1
label Col1 'Month', sum(Col2) 'Total'
format Col1 'MMM-YYYY'")

Google Sheets - Trying to use IMPORTRANGE to get student enrollments by school by date

I made columns that simply lists all the schools for each student under a date column header. I only need to count the schools - I don't want to see any student data. I have a form that needs to be submitted to the state and there is a cell with the date we are submitting. I want to use an IMPORTRANGE to go to the other spreadsheet and find the column where the date matches the form date and pull back the count of schools in that column. I tried using INDEX/MATCH, etc., and while I have those working on the form for other data already on my spreadsheet - I can't seem to get them to work on the 'outside' spreadsheet. Any help is appreciated! I'm attaching an example spreadsheet with more explanation. I hope it's clear. Thank you.
Example Document
ztiaa has provided a good solution. I will suggest another which pivots the data differently. I feel that having the dates go across columns is going to quickly become unwieldy. So this approach leaves the dates running down the right side with the schools running as column headers. My solution also includes exceptions such as snow days, as those will likely be important to see at a glance as well. Just be careful to use the same notation for such exceptions. For instance, always use "snowday" (not, eg., "snow day") or "prep day" (not, e.g., "prep").
In Sheet1, use IMPORTRANGE to bring in the data exactly as you have it listed in your sample sheet (i.e., dates at top, school names or exceptions under each date header).
Then, in a new sheet, place the following formula in cell A1:
=ArrayFormula({QUERY(SPLIT(FLATTEN(FILTER(Sheet1!1:1&"~"&INDIRECT("Sheet1!2:"&ROWS(Sheet1!A:A)),Sheet1!1:1<>"")),"~",1,0),"Select Col1, COUNT(Col1) WHERE Col2 Is Not Null GROUP BY Col1 PIVOT Col2 FORMAT Col1 'mmm dd'"),TRANSPOSE({"District Totals",MMULT(SEQUENCE(1,ROWS(Sheet1!A2:A),1,0),IF(FILTER(INDIRECT("Sheet1!2:"&ROWS(Sheet1!A:A)),Sheet1!1:1<>"")="",0,1))})})
This assumes that the first sheet is, in fact, named Sheet1. If it is not, you'll need to change every instance of that sheet name in the formula.
It will probably further aid visual ease if you freeze Row 1 and Column 1 (View > Freeze > 1 row / 1 column).
ADDENDUM (after seeing realistic copy of OP's sheet)
=ArrayFormula({TRANSPOSE(QUERY(SPLIT(FLATTEN(FILTER(Sheet1!1:1&"~"&INDIRECT("Sheet1!2:"&ROWS(Sheet1!A:A)),Sheet1!2:2<>"")),"~",1,0),"Select Col1, COUNT(Col1) WHERE Col2 Is Not Null GROUP BY Col1 PIVOT Col2 FORMAT Col1 'mmm dd'"));{"District Totals",MMULT(SEQUENCE(1,ROWS(Sheet1!A2:A),1,0),IF(FILTER(INDIRECT("Sheet1!2:"&ROWS(Sheet1!A:A)),Sheet1!2:2<>"")<>"",1,0))}})
If you prefer to see the name of the exception (e.g., "snowday") rather than the count of 1 for each exception in the "District totals" line:
=ArrayFormula({TRANSPOSE(QUERY(SPLIT(FLATTEN(FILTER(Sheet1!1:1&"~"&INDIRECT("Sheet1!2:"&ROWS(Sheet1!A:A)),Sheet1!2:2<>"")),"~",1,0),"Select Col1, COUNT(Col1) WHERE Col2 Is Not Null GROUP BY Col1 PIVOT Col2 FORMAT Col1 'mmm dd'"));{"District Totals",IF(MMULT(SEQUENCE(1,ROWS(Sheet1!A2:A),1,0),IF(FILTER(INDIRECT("Sheet1!2:"&ROWS(Sheet1!A:A)),Sheet1!2:2<>"")<>"",1,0))=1,FILTER(Sheet1!2:2,Sheet1!2:2<>""),MMULT(SEQUENCE(1,ROWS(Sheet1!A2:A),1,0),IF(FILTER(INDIRECT("Sheet1!2:"&ROWS(Sheet1!A:A)),Sheet1!2:2<>"")<>"",1,0)))}})
If you want exceptions (e.g., "snowday") to always appear at the bottom instead of in alphabetical order within the school-name list:
=ArrayFormula({TRANSPOSE(QUERY(SPLIT(FLATTEN(FILTER(Sheet1!1:1&"~"&IF(REGEXMATCH(UPPER(INDIRECT("Sheet1!2:"&ROWS(Sheet1!A:A))),INDIRECT("Sheet1!2:"&ROWS(Sheet1!A:A))),,"‡")&INDIRECT("Sheet1!2:"&ROWS(Sheet1!A:A)),Sheet1!2:2<>"")),"~",1,0),"Select Col1, COUNT(Col1) WHERE Col2 Is Not Null AND Col2 <> '‡' GROUP BY Col1 PIVOT Col2 FORMAT Col1 'mmm dd'"));{"District Totals",IF(MMULT(SEQUENCE(1,ROWS(Sheet1!A2:A),1,0),IF(FILTER(INDIRECT("Sheet1!2:"&ROWS(Sheet1!A:A)),Sheet1!2:2<>"")<>"",1,0))=1,FILTER(Sheet1!2:2,Sheet1!2:2<>""),MMULT(SEQUENCE(1,ROWS(Sheet1!A2:A),1,0),IF(FILTER(INDIRECT("Sheet1!2:"&ROWS(Sheet1!A:A)),Sheet1!2:2<>"")<>"",1,0)))}})
Try this out
=ArrayFormula({query(split(flatten(text(A1:E1,"mmm/d")&"❄️"&A2:E),"❄️"),"select Col2, count(Col2) where not Col2 matches '|Snowday' group by Col2 pivot Col1");{"District Total",transpose(MMult(transpose(N(filter(A2:E,not(RegexMatch(A2:E2,"Snowday")))<>"")),sequence(rows(A2:E))^0))}})

How to Get the Sum Total of a Category if Data is Split Between Multiple Adjacent Tables

I have attached a sample of the format the data I am working with is in. The actual data set has many more columns. So I am looking for a single formula that will get the totals for a category from the whole table. As you can see in the photo we have "Test 2" in columns B and D with values of 1 and 9 respectively. That is a total of 10. Is there a singular formula that would return 10? Thank you.
try:
=QUERY({FLATTEN(FILTER(B2:G10, MOD(COLUMN(B:G), 2)=0)),
FLATTEN(FILTER(B2:G10, MOD(COLUMN(B:G)-1, 2)=0))},
"select Col1,sum(Col2)
where Col1 is not null
group by Col1
label Col1'Name',sum(Col2)'Totals'")
for unknown number of columns try:
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(
FILTER(B2:1000, MOD(COLUMN(B2:2), 2)=0)&"×"&
FILTER(B2:1000, MOD(COLUMN(B2:2)-1, 2)=0)), "×"),
"select Col1,sum(Col2)
where Col2 is not null
group by Col1
label Col1'Name',sum(Col2)'Totals'"))

How to find the most frequent text value in a whole spreadsheet on Google sheets?

I know the code to find the most frequent value in a single column, but I'm trying to figure out the code that lets me find the most frequent value in multiple specific columns.
For example:
=ARRAYFORMULA(INDEX(A2:A17,MATCH(MAX(COUNTIF(A2:A17,A2:A17)),COUNTIF(A2:A17,A2:A17),0)))
^^this formula only allows me to have two arguments for COUNTIF
=INDEX(A2:A6,MODE(MATCH(A2:A6,A2:A6,0)))
^^this one only allows 4 arguments max in the index
I want an equation that'll allow me to find the most frequent text value for 16 specific columns.
Is that even possible?
BETTER FORMULA
You asked for formula when you have 2 top values with the same frequency
=SORTN(QUERY(FLATTEN(H2:K),
"select Col1, count(Col1)
where Col1 is not null group by Col1
order by count(Col1) desc label count(Col1) '' ",0),1,1,2,0)
First answer
Use only 1 QUERY formula
For top value
=QUERY(FLATTEN(A2:D),
"select Col1, count(Col1)
where Col1 is not null group by Col1
order by count(Col1) desc limit 1",0)
For all values
=QUERY(FLATTEN(A2:D),
"select Col1, count(Col1)
where Col1 is not null group by Col1
order by count(Col1) desc limit 1",0)
I show it in 2 steps then combine steps together in one formula:
First you flatten table and remove duplicates to get a column of values you check frequency for:
unique(flatten(B2:I25))
Then for each one you check number of occurences:
ArrayFormula(countif($B$2:$I$25,unique(flatten(B2:I25))))
Then you have to filter new table and get only rows with highest values:
=filter({first , second column};second column = max(second column)
Using earlier values:
=filter({unique(flatten(B2:I25)),ArrayFormula(countif($B$2:$I$25,unique(flatten(B2:I25))))},ArrayFormula(countif($B$2:$I$25,unique(flatten(B2:I25))))=max(ArrayFormula(countif($B$2:$I$25,unique(flatten(B2:I25))))))
My solution is available here:
https://docs.google.com/spreadsheets/d/1gMZDFWOY8qbA1Bhp8rZ_por3Skb0i_qQtlaSlCTKXgM/copy
If your columns are scattered around your sheet, you should use { } and make a table of them.

Can I get month-year & total amount for a row with Multiple column?

I have a sheet with
Date|Amount Date|Amount Date|Amount ...
columns and from that I would like to get Month-Year:Total amount if it can be done with some Google spreadsheet functions/script.
I already have tried with many functions including ArrayFormula, Query, Text, etc. But They might require a range of data while I have broken range and didn't find any functions helpful.
This is how I would like to have:
Can it be done?
=ARRAYFORMULA(QUERY({TEXT({A:A;C:C;E:E;G:G}, "mmm - yyyy"), {B:B;D:D;F:F;H:H}},
"select Col1,sum(Col2) where Col2 is not null group by Col1 label sum(Col2)''", 0))

Resources