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))}})
I have been struggling with the Google Sheets query for several hours and maybe getting confused how to combine HLookup and VLookup (or any other function) in a way that can find the first and last occurrence of a value in a sheet based on the date header above it.
Here is an example sheet for reference which is very clear, but I will try explain verbally as well ... https://docs.google.com/spreadsheets/d/1rBVM7EtW3IREundWs_f2ftic-h4fEB97u4k4sZyIFNY/edit#gid=0
Given that I have a 2d range of cafeteria locations serving food on certain day (so the Y-axis headers of the table are cateteria locations and the X-axis headers are dates and the value is the name of the food served that day such as "Pizza") ... I want to have another table below that has a lookup for the first and last date that the food was offered. In my reference sheet I denoted that by Yellow highlight.
It seems like something that should be doable in a spreadsheet tool; unless it is impossible and I am not realizing it. Is such an operation possible?
delete range B10:C and use:
=INDEX(IFNA(VLOOKUP(A10:A, QUERY(SPLIT(FLATTEN(B1:E1&"×"&B2:E8), "×"),
"select Col2,min(Col1),max(Col1) group by Col2", ), {2,3}, 0)))
See if this helps
=query(ArrayFormula(split(flatten(text(B1:E1, "yyyy-mm-dd")&"~"&B2:E5), "~")), "Select Col2, min(Col1), max(Col1) where Col2 <> '' group by Col2 label Col2 'Food', min(Col1) 'First Offered', max(Col1) 'Last Offered' format min(Col1) 'yyyy-mm-dd', max(Col1) 'yyyy-mm-dd'", 0)
Change range to suit.
I have this table:
I need to create a timeframe model of it, in a day by day view but with one line for each Client, so it gets to look like this:
Number of clients may change with time, so it should somehow dynamically check the unique items in the Client column (UNIQUE(A2:A) would solve that) and use the number of unique clients to create the date repetitions and client repetitions per date.
Sample sheet here.
Is there a way out of that?
I think your data can be converted using this formula
=ArrayFormula(query(split(split(FLATTEN(A:A&"😎"&SUBSTITUTE(C1:D1;"Date of ";"")&"😎"&C:D&"*");"*");"😎");"select Col3, Col1, count(Col1) where Col3 is not null group by Col3, Col1 pivot Col2 order by Col3 label Col1'Client', Col3'Date'"))
I need to average the values that share the same ID and have been published in the same or previous months. I have to use ARRAYFORMULA due to the volume of rows.
This is an iteration of a question I asked last week: How to use AVERAGEIFS within ARRAYFORMULA, which I've tried to adapt for this, unsuccessfully.
As it can be a little confusing, I have created this file with dummy data. Although year and month were included in the ID at the beginning, I have split them into columns to make filtering easier.
Note that February average includes January values with the same ID, March includes January, February and March, etc. When the year changes, the average restarts. I suppose it could be done by comparing the values of the year (equals) and month (equals or lower), but I don't know how to insert the comparator into the last-day formula.
Thank you all for your time and effort.
try:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A&B2:B&C2:C; QUERY({A2:A&B2:B&C2:C\D2:D};
"select Col1,avg(Col2)
where Col2 is not null
group by Col1
label avg(Col2)''"; 0); 2; 0)))
or if months does not matter use:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A&B2:B; QUERY({A2:A&B2:B\D2:D};
"select Col1,avg(Col2)
where Col2 is not null
group by Col1
label avg(Col2)''"; 0); 2; 0)))
I have a google sheet where every month I copy from my bank website the movements and paste them in a sheet, then according to a list of words (which I write in a column on the sheet) I have a formula that will recognize the movements and categorize them.
I made an example sheet here
The Formula I have at this moment is working more or less correctly (it misses some movements and only consider one word to search), and but is very slow. Every month I have quite a movements, and the sheet has all 12 months of the year, every time I paste the movements of a month it takes a while for it to process it all
So, is it possible to have a better/faster more accurate formula than the one I have in column E?
And, would it be possible to have a formula that will search/recognize the movements according to 2 words (and not just 1 word like my actual formula)?
In some real cases, 2 words to recognize would be much better
Thanks in advance for any help/advice.
cell E1:
=IFERROR(QUERY({FILTER(I2:I;I2:I<>"")\FILTER(K2:K; K2:K<>"")};
"select Col1, sum(Col2) group by Col1 label sum(Col2) ''"; 0);
"add allias")
cell J1:
=ARRAYFORMULA(QUERY(QUERY({PROPER(A2:A)\B2:B};
"select * where Col1 is not null"; 0);
"select Col1, sum(Col2) group by Col1 label sum(Col2)''"; 0))