How to write a QUERY where the Column values in the "Select" section are dependent on the value of another cell within that dataset - google-sheets-query

Collecting responses from a Google Form, I have two categories for the name of the person responding and the title of the play they are to assess. In one category, "Board Members" have a dropdown list of their names and the titles of plays available for them to evaluate, whereas the second category is for "Guest Readers" to choose their name from a dropdown list and the more limited play titles for them to choose from. I have the form working fine, but the results in the Google Sheet are as shown on the tab "Form Responses 3" tab of this example sheet: https://docs.google.com/spreadsheets/d/1c9AK-Df-rgnNDKfeXRo0msoUHmVCIxs0EFD_HPDxWA4/edit?usp=sharing
I am trying to build a QUERY statement that produces the outcome on the "Assessments" tab of the same sheet.
My thinking thus far is that the values of the Columns to choose from in the "Select " section of the QUERY are dependent on an embedded IF statement something like:
=query('Form Responses 3'!$A$2:$G, "Select '" & if('Form Responses 3'!$C2<>'',"D, C, G Where not E <>''", "F, E, G Where not C <>''") &"'")
I'm not sure of many things here -- I am confident I am getting lost in the ' and " frames -- but most specifically, can I even make the dynamic callback to a cell within the dataset in the IF formula that will manifest in each row of the QUERY result? Am I making any sense at all?

Related

Google Apps Script - When new row containing data with specific keywords is added to Sheet 1, move that to a new row in a new corresponding sheet

I am using Google Sheets to evaluate data from a Zoho Form. I would like to sort the raw data from spreadsheet 1 ('Raw Data') into 3 new spreadsheets depending on 2 specific keywords found in 2 different columns in 'Raw Data'.
For context - the keywords for the first column (column 'G') are:
Ordered
Stock
Preordered
the keywords for the second column (column 'F') are:
B2B
B2C
There are a total of 6 possibilites that need to be accounted for: ordered & B2B, ordered & B2C, stock & B2B, stock & B2C, preordered & B2B, preordered & B2C.
If for instance a form is submitted for 'Ordered' and 'B2B', then a specific succession of rows must be transferred to the corresponding 'Ordered' spreadsheet because of Zoho Forms' nature of staggering the submitted information horizontally in the 'Raw Data' sheet. These rows will change depending on which one of the 6 combinations is chosen in the Form.
The 3 new spreadsheets will be named according to the keywords found in column 'G'.
So far I have been working with a Query in the new sheets to pull the needed information from the 'Raw Data' spreadsheet, however this hasn't proven to work as intended as Zoho Forms creates a new row rather than filling an existing one, causing the query to skip the newly created row and therefore not pulling any data.
Here is the Query, maybe it'll help identify what I am looking for:
=IF('Raw Data'!G6="Ordered", IF('Raw Data'!F6="B2B",QUERY('Raw Data'!A6:DN6,"SELECT A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T ORDER BY C desc LIMIT 1"), QUERY('Raw Data'!A6:DN6,"SELECT A,B,C,D,E,F,G,U,V,W,X,Y,Z,AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK,AL,AM,AN,AO,AP,AQ,AR,AS,AT,AU ORDER BY C desc LIMIT 1")))
I have found someone who posted a Script similar to what I am looking for, however it is missing that conditional aspect to it. Here is the script, maybe it can serve as a good starting point. (all credit for this code goes to Mike Steelson):
function moveData() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var rng = ss.getSheetByName('Sheet1').getRange('A2:C2')
ss.getSheetByName('Sheet2').getRange(ss.getSheetByName('Sheet2').getLastRow()+1,1,1,3).setValues(rng.getValues())
rng.clearContent()
}
I am quite new to building these sort of things so please forgive me if the Query and my overall explanation isn't the best, if you have any questions I'll try my best to elaborate!
Cheers,
Rupert.

Check for unique keywords in cell data in google sheet

I have a list of email subject lines with job roles on the left side, need to filter out roles like Assistant Manager, Manager, Civil Engineer, Project Manager to get the result.
Certain cells don't have the job role mentioned so to be left blank
The rows on the sheet need to remain intact so data can be analysed.
i tried using REGEXMATCH but it will not work for row5
is there a way to have a single formula, which includes all keywords for the whole list.
REGEXMATCH(B3, "assistant|manager")
I'm doing this on Google sheet and have shared the screenshot and the GoogleSheet file Link for reference.
I have made a copy of your sample data on this Support Sheet, that will exist in perpetuity.
On a tab called MK.Lookups, I built a table to use for your lookup words and returns. Then on the tab called MK.Idea, I placed this formula in cell B3 and dragged it down.
=IFERROR(INDEX(SPLIT(TEXTJOIN("|",TRUE,IF(REGEXMATCH(UPPER(B3),SUBSTITUTE(UPPER(MK.Lookups!C$2:C$20),", ","|")),MK.Lookups!B$2:B$20,)),"|"),1))
I also placed this formula in cell C1, which is an arrayformula that will populate for every row and doesn't need to be copied down the column.
={"Result";ARRAYFORMULA(IFERROR(INDEX(SPLIT(TRANSPOSE(TRIM(QUERY(IF(REGEXMATCH(TRANSPOSE(UPPER(A2:A)),SUBSTITUTE(UPPER(MK.Lookups!C$2:C$20),", ","|")),MK.Lookups!B$2:B$20&CHAR(10),),,9^9))),CHAR(10)),,1)))}

Google docs query when contains value in a range

In google sheets, I want to return a row when a cell in column C contains any value in a range on a different sheet.
The query below does not work. What am I missing?
=QUERY(
'Form Responses 1'!$1:$1000,
" select A:G where C contains 'Sheet2'!$A1:$A26"
)
If you are trying to match a string value in a range on a different sheet:
=query('Form Responses 1'!$1:$1000, "SELECT A,B,C,D,E,F,G WHERE A MATCHES '"&JOIN("|",'Sheet2'!$A1:$A26)&"'",1)
Hopefully syntax highlighting in the image below makes the above string concatenation operators a little clearer:
GoogleSheets: Select partial row if target column in data set contains value within range declared in another sheet
I suggest flagging the rows of interest in Form Responses 1, say with in H1:
=ArrayFormula(countif(Sheet2!A:A,C1:C))
and then selection based on the flags, say with:
=QUERY('Form Responses 1'!$1:$1000,"select * where H=1")
or if you don't want the flags to appear:
=QUERY('Form Responses 1'!$1:$1000,"select A,B,C,D,E,F,G where H=1")

Arranging Google Form Responses into an already existing Spreadsheet Database

Background
I am making a Database of organiser names, which i want to update with a Google Form.
I already made a Form which feeds a Spreadsheet "Form Responses" sheet with the organiser details: Continent, Country and Chapter/City. The Database is already existing with current organisers, split into continent specific sheets, so i need to add new organisers from the form to this database. If a new organiser is from a new country/chapter, that needs to be added to the database as well.
Question
What formula can I use to feed the "Form Responses" sheet rows into the "Database" sheets, without having multiple rows of the same Country and Chapter? That is, add the "Organiser" column to an existing "Country" + "Chapter", or add the new "Country" + "Chapter" + "Organiser" to the bottom of the correct "Continent_Database".
Maybe the only way to do this might be to add all new rows from the "Form Responses" sheet to the bottom of the correct "Continent_Database", and merge the rows in the case of already existing Country + Chapter, in an additional sheet.
Example
Spreadsheet example with some test Form Responses and a "Africa_Database" example sheet:
https://docs.google.com/spreadsheets/d/1QaDNQp-HrbueQchmlXGSr7cFZ9r2x7ml148vSJL4Q0w/edit?usp=sharing
You could be looking to use a query here. In the case below 'A2' points a cell containing a country name. Transpose will convert a downward list to a horizontal and the query will get all names from column G where column C contains that the country in cell 'A2'
=transpose(QUERY('Form Respones'!B:G,"SELECT G WHERE C ='"&A2&"'",0))
Here is an example

Is it possible choose from contacts when entering email address into a spreadsheet

I would like to recreate the gmail to: type field but for entering in data to a spreadsheet. So if a person starts typing in an email address it will look at their contacts (and domain contacts) and show a filtered set of emails.
No you cant because there is no event to detect the user typing.
What you can do is add a menu item that looks at the active cell and attempt to do the autocomplete on the cell.
I wound up using Data Validation.
Get a CSV of the contacts.
Import those contacts into a sheet on the spreadsheet
use a formula similar to (= A1 & " " & B1) to create a filed that you want to search on. In my case I combined First Name and Last Name
Open a new sheet and right -click cell A1. Use data validation to pull from the column you created in the previous sheet.
just start typing in the box and it opens up like the to: field in an email box.
I did this with 400 names and saw no performance issue.