I use cell values on a sheet to change what values a query will be looking for. Is there a way to change what sheet the query is using as a source depending on the value of a cell?
This is the query I currently use. For example, if I type something in the cell C4, the query will only return values that contain whatever I typed in C4.
=Query(Input!A:AD,"select * where C contains """&C4&""" AND D contains """&D4&""" AND E contains """&E4&""" AND F contains """&F4&""" AND G contains """&G4&""" AND H contains """&H4&""" ORDER BY A desc",2)
I now want to have this same concept, but change Input!A:AD to whatever I type in cell A4. A4 could contain "Input", but if I change A4 to "Archive", I would like it to "read"
=Query(Archive!A:AD,"select * where C contains """&C4&""" AND D contains """&D4&""" AND E contains """&E4&""" AND F contains """&F4&""" AND G contains """&G4&""" AND H contains """&H4&""" ORDER BY A desc",2)
I've tried similar wildcards like &A4& and """&A4&""" in place of the sheet name, but this returns errors. What am I missing?
You can try with the following formula, adapting it to their needs:
=QUERY(INDIRECT(C2); "SELECT *")
Here's an example:
Related
Refer the worksheet here - https://docs.google.com/spreadsheets/d/1g3mthqijmB7lySfKUvt2NjYT-zVA5oyXr1hJKcJZkdc - Feel fee to edit.
I'm currently trying to get data from a specific column each time the data validation is changed.. It should pull the Names corresponding to FALSE values.. Currently I'm achieving this using multiple IF functions.. If there is a way to directly match the validation input to the row header and then get the values, it would be super great.
See my duplicate sheet ("Erik Help"):
=FILTER(E2:E,FILTER(F2:J,F1:J1=B2)=FALSE)
In plain English, this reads as follows: "Return any names in Column E where the header in in Columns F to J matches the value in cell B2 and where the corresponding value for the name is FALSE."
This formula is written flexibly, assuming that you will have more than two names in Column E within your real sheet. If there are more columns, just extend both instances of J to match the new rightmost column.
I am using googlesheets, and needs help with a formula for the below usecase.
if a number from column B matches the part of the number from column A then populate specific value in column C
for example: of value from column B = 0000 matches partly in column A (its always last 4 to matches in column A) then populate APPLE in column C
Putting
=if(REGEXMATCH(A1,B1), "APPLE", "")
into cell C1 will work, just make sure to change "APPLE" for whatever your text source is.
To have it go down the whole column automatically put this in C1 instead:
=ARRAYFORMULA(if(REGEXMATCH(A1:A,B1:B), F1:F, ""))
Assuming that column F has your strings you want to check:
I am trying to do a partial match of Products (Column B) to DB (Column H). Column B however has many partial names within the cell. The entirety of Column H needs to be searched for a partial match of Column B, if a match is found then the cell name from column H needs to be input into column C.
Link to sample Google sheet: https://docs.google.com/spreadsheets/d/1ZvIbZQ9zsLd6w1uGgSbQ3v-QFebMYrlQfvdsLCfEwAg/edit?usp=sharing
Any advice on how to do this would be appreciated.
In order to look for a substring that would correspond to all the cell values from H2:H70 in B2 (and the subsequent values of the column B) you will be wanting to use the function REGEXMATCH that compares a text (in the case below B2) with a regular expressing (each of the values from H2:H70). If it finds a match then it returns the value of column H by using the IF function and if it doesnt it returns empty.
As we are comparing the range H2:H70 to B2 this will return an array of possible matches or not matches (emtpy after the IF) and therefore this array must be handled with ARRAYFORMULA.
Then we are using QUERY to only return the array values that are not empty. This will leave us with an array of values of just the actual matches found (in case there are more than one). As I imagined that you want all the matches in a single cell I am taking all the matches array values and joining them in a single array separated by a space using TEXTJOIN.
Finally, I am using IFERROR to return empty in case no matches were found.
=IFERROR(TEXTJOIN(" ",TRUE,QUERY(ARRAYFORMULA(IF(REGEXMATCH(B2, $H$1:$H$70),$H$1:$H$70,"")),"where Col1 is not null")))
I have a query formula in Google sheets that updates based on additional columns of data in my Google Sheet seen here =QUERY('Deals List - URL Split'!A:DZ, "select A, C where C contains 'http'",)
So it may add QUERY('Deals List - URL Split'!A:DZ, "select A, E where E contains 'http'",)and then it will end up becoming the below and so on for each additional.
=QUERY('Deals List - URL Split'!A:DZ, "select A, C where C contains 'http'",);QUERY('Deals List - URL Split'!A:DZ, "select A, E where E contains 'http'",)
What I am trying to do is have the resultant query formula which is in cell 'List'!A1 as QUERY('Deals List - URL Split'!A:DZ, "select A, C where C contains 'http'",);QUERY('Deals List - URL Split'!A:DZ, "select A, E where E contains 'http'",) be used in an array formula as a reference so I don't have to update the formula each time a new query formula is added.
The static query formula is
=SORT(ARRAYFORMULA({QUERY('Deals List - URL Split'!A:DZ, "select A, C where C contains 'http'",);QUERY('Deals List - URL Split'!A:DZ, "select A, E where E contains 'http'",)}),1,TRUE,2,TRUE)
and indeally the one that gets the dynamic formula would be like below but I always get an error and get just the literal static formula above.
=SORT(ARRAYFORMULA({'List'!A1}),1,TRUE,2,TRUE)
I think I have an answer (or two) for you. After looking at your sheet, I have to say that I am sure that a simpler design is possible for your sheets, that would simplify everything. Anyway, I've built one formula, using only your data on sheet '2 URL SPLIT'!, and the desired columns from '4 URL FILTER'!A1:1. See my sample tab, GK-6 ITEMS AND URLS, added to your sheet.
The formula, reduced to its basic form, is:
={
IFERROR({'2 URL SPLIT'!$A$2:$A, INDIRECT(INDEX(
{ARRAYFORMULA(IFERROR("'2 URL SPLIT'!"
& TRANSPOSE('4 URL FILTER'!1:1)
& TRANSPOSE(SPLIT(
{"2:"
& TEXTJOIN("~2:",1,TRANSPOSE('4 URL FILTER'!1:1))},"~",0,0))
& ROWS('2 URL SPLIT'!A:A)))},1,0))},{"",""})
}
The formula is not truly dynamic, but it ignores blank columns. So the cheat I've used is to expand the capacity of the formula to include extra blank columns, and if they get filled with data, the data will be used. I've set it to include 50 columns of data, where you are currently using 39, but you could expand it to handle about 200 columns, before it reaches the 50,000 character limit of a cell.
The formula as shown above handles one column. For the one that handles fifty columns, as in my sample sheet, I simply duplicate the inner formula, everything inside the outer braces "{....}" and increment the number in it. You only need to do this once, or copy mine from my sheet. You do not need to update if/when your data columns expand.
I'm happy to add much more explanation if you decide that this formula works for you. But the basis of the formula is dynamically building the ranges of cells to query. The result of this inner part of the formula is shown below. Note that the 2 in each range is hard-coded, and can be changed if your structure changes, but the limit of the range is calculated from your data.
The rest of the formula uses an index into this "table", incrementing by one to select each successive data range, which adds a new column of data to be queried. These data ranges from '2 URL SPLIT!' include column A and one subsequent data column, as specified in '4 URL FILTER'!A1:A, and are stacked one above the other, by using a ";" separator.
The query is then run against this vertical, two column stack, selecting all rows where column 2 contains "http".
The final result is shown below:
I have a bit of code that inserts a blank row to the top of a sheet and copies data into it.
I also have a defined range on that sheet.
Every time a row is inserted, the defined range moves down a row.
The defined range is helping power a query on another sheet and therefore is always missing the inserted rows.
If i delete the query and use importrange, it works no issue.
However the query doesn't work with importrange.
The easiest fix I'm assuming would be to 'hard-code' the range, but how would i call that in my query?
Here is the query, followed by the same query using importrange.
=IFERROR(QUERY(STOCK_IN_DATA,"SELECT *" & IF((LEFT(D4,1))="*","WHERE D STARTS WITH '"&RIGHT(D4,LEN(D4)-1)&"' AND C CONTAINS '"&$C4&"' AND E CONTAINS '"&$E4&"' AND F CONTAINS '"&$F4&"' AND G CONTAINS '"&$G4&"' AND H CONTAINS '"&$H4&"'","WHERE C CONTAINS '"&$C4&"' AND D CONTAINS '"&$D4&"' AND E CONTAINS '"&$E4&"' AND F CONTAINS '"&$F4&"' AND G CONTAINS '"&$G4&"' AND H CONTAINS '"&$H4&"'")),)
=IFERROR(QUERY(IMPORTRANGE("SHEETNAME","MASTER_IN!$B$1:M"),"SELECT *" & IF((LEFT(D4,1))="*","WHERE D STARTS WITH '"&RIGHT(D4,LEN(D4)-1)&"' AND C CONTAINS '"&$C4&"' AND E CONTAINS '"&$E4&"' AND F CONTAINS '"&$F4&"' AND G CONTAINS '"&$G4&"' AND H CONTAINS '"&$H4&"'","WHERE C CONTAINS '"&$C4&"' AND D CONTAINS '"&$D4&"' AND E CONTAINS '"&$E4&"' AND F CONTAINS '"&$F4&"' AND G CONTAINS '"&$G4&"' AND H CONTAINS '"&$H4&"'")),)
What the query does is create a nice little search filter in the cells shown on row 4.
QUERY can use A, B, C columns names only when a reference is used as the first argument. When an array is used as the first argument, as in this case IMPORTRANGE, you should use Col1, Col2, Col3 as column names instead of A, B, C respectively.