Setting up Google sheets formula - google-sheets

I have a sheet that has 2 columns - id and comment. In a new sheet I need a formula that is set up like the following: First column is the id, the second column is the frequency of the id and the third column is a list of all the comments associated with that id.
Currently I got the first two columns working with the following formula but don't know how to add the third column (list of comments):
=ArrayFormula(QUERY(IF({1,1},TRANSPOSE(SPLIT(CONCATENATE('Oct. 2017'!C:C&CHAR(9)),CHAR(9))))&"","select Col1, count(Col2) group by Col1 order by count(Col2) desc label Col1 'ID', count(Col2) 'Frequency'",0))

Assuming your formula populates A1 onwards and your sheet with two columns is called Oct. 2017 please try in C1 and copied down to suit:
=join(", ",filter('Oct. 2017'!D:D,'Oct. 2017'!C:C=A1))

Related

TextJoin the rows based on the Id's dates and sequence

I have been trying to concatinating the Specific column based on the ID's, dates and the sequence which are avaialble in the separate columns.
I have used 3 steps to get the result and the result is accurate but i want to use a single formula or Google sheets Query to achieve the final result.
I have added a google sheets for your reference and i would really appreciate your help in this regards.
1st step In this step i just Sorted out the data
=QUERY({'Raw Data'!A:F}, "SELECT Col2, Col3, Col4, Col5 Where Col2 is not null ORDER BY Col2 ASC, Col4 ASC, Col3 ASC")
2nd step From Sorted out data i have taken 2 column and make them unique then used textjoin function to concatenate the notes with before and after brackets.
=UNIQUE(QUERY(A2:D, "SELECT A,C"))
=TEXT(G3,"MM-DD-YYYY")&": ("&TEXTJOIN(" ",TRUE,FILTER(D:D,A:A=F3,C:C=G3))&")"
3rd step after all above steps i pulled the only unique id's then based on unique id's textjoin the notes
=UNIQUE(F2:F)
=TEXTJOIN(" ",TRUE,FILTER(H:H,F:F=L3))
Added formula to your sheet to test:
=index(let(a,sort({B2:E},1,1,3,1,2,1),b,unique(filter({index(a,,1),index(a,,3)},index(a,,1)<>"")),c,map(index(b,,1),index(b,,2),lambda(d,e,"("&join(" ",filter(index(a,,4),index(a,,1)=d,index(a,,3)=e))&")")),byrow(unique(tocol(index(b,,1),1)),lambda(z,{z,join(" ",unique(filter(TEXT(index(b,,2),"mm-dd-yyyy")&": "&c,index(b,,1)=z)))}))))

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 append 3 tables with different number of columns in google sheet?

Hi everyone,
I have 3 tables with different number of columns where some columns are actually repeated in these 3 tables (as shown in the screenshot above).
Table 1: Col A to Col D
Table 2: Col F to Col H
Table 3: Col J to Col L
I want to merge these 3 tables together to reduce the number of columns in my google sheet. The screenshot below is how I process these 3 tables before merging.
I'm using QUERY to create extra columns for each table so that the number of columns and the position are aligned between 3 tables. After that, I use QUERY again to append the 3 processed tables as shown in the screenshot below:
However, this method is very tedious when I have 10 tables or more. Is there any other easier ways or tricks to use so that I can achieve the same expected output as shown in the 3rd screenshot?
This is my sheet:
https://docs.google.com/spreadsheets/d/1H1gJAhp1RVax2fy8D-uEtFxdjb-zAHutkPFv5WZT_TY/edit#gid=0
Any help will be greatly appreciated!
You would need a really complicated formula to get the desired output which is a combination of multiple formula's
I added a new tab in you Google Sheet called "Solution" with this formula included
=QUERY(ARRAYFORMULA({
IFERROR( ArrayFormula(SPLIT(FLATTEN(Sheet1!B3:D3&"~"&Sheet1!A4:A&"~"&Sheet1!B4:D),"~")),"");
IFERROR( ArrayFormula(SPLIT(FLATTEN(Sheet1!G3:H3&"~"&Sheet1!F4:F&"~"&Sheet1!G4:H),"~")),"");
IFERROR( ArrayFormula(SPLIT(FLATTEN(Sheet1!K3:L3&"~"&Sheet1!J4:J&"~"&Sheet1!K4:L),"~")),"")}),
"SELECT Col2, SUM(Col3) WHERE Col2 is not null GROUP BY Col2 PIVOT Col1 LABEL Col2 'Student Name' ")
Steps:
Unpivot each table =IFERROR( ArrayFormula(SPLIT(FLATTEN(Sheet1!B3:D3&"~"&Sheet1!A4:A6&"~"&Sheet1!B4:D6),"~")),"")
Combine all tables into one table: =ARRAYFORMULA({__Unpivot1__; __Unpivot2__, __Unpivot3__})
Pivot above data in Step2: =Query(__Step2__, "SELECT Col2, SUM(Col3) GROUP BY Col2 PIVOT Col1 LABEL Col2 'Student Name' ")
Add WHERE Col2 is not null in the query to remove any possible blank rows

Repeat rows in Google Sheets based in the number of unique column values

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

Combine first column of n sheets to one colume

So in one spreadsheet file we have n sheets.
Sheet1
Names
a
b
Sheet2
Names
b
c
d
and so on.. assume n sheets with n values in the first column
Then there's one super sheet.
Super sheet
Supersheet
Supersheet
Supersheet
Supersheet
Sheet1
Sheet2
Sheet3
...
Names
Count
a
1
b
2
c
1
d
1
Assume A1:1 is a list of all of the names of the sheets we want to fetch names from. We want the names pasted into A3:A.
My first thought was to do
=unique(filter({INDIRECT(A1&"!A3:A");INDIRECT(B1&"!A3:A");INDIRECT(C1&"!A3:A")},{INDIRECT(A1&"!A3:A");INDIRECT(B1&"!A3:A");INDIRECT(C1&"!A3:A")}<>""))
and expand, but that doesn't take care of N sheets.
So what I thought I could do was
=ARRAYFORMULA(INDIRECT(A2:C2&"!A2:A3"))
but that only takes care of sheet1. INDIRECT doesn't work with arrayformula
So what can I do?
you can either use some script or put your sheets in array {} and pre-program it:
=QUERY({INDIRECT(Sheet1!A1&"!A3:A");
INDIRECT(Sheet2!A1&"!A3:A")},
"select Col1,count(Col1)
where Col1 is not null
group by Col1
label count(Col1)''")
since this is one column future sheets can be added this way:
=QUERY({INDIRECT(Sheet1!A1&"!A3:A");
INDIRECT(Sheet2!A1&"!A3:A");
IFERROR(INDIRECT(Sheet3!A1&"!A3:A"));
IFERROR(INDIRECT(Sheet4!A1&"!A3:A"))},
"select Col1,count(Col1)
where Col1 is not null
group by Col1
label count(Col1)''")
IMPORTRANGE would be:
=QUERY({IMPORTRANGE("id", Sheet1!A1&"!A3:A");
IMPORTRANGE("id", Sheet2!A1&"!A3:A");
IFERROR(IMPORTRANGE("id", Sheet3!A1&"!A3:A"));
IFERROR(IMPORTRANGE("id", Sheet4!A1&"!A3:A"))},
"select Col1,count(Col1)
where Col1 is not null
group by Col1
label count(Col1)''")
ofc, every importrange formula needs to be authorized separately

Resources