I have the following formula...
=ARRAYFORMULA( VLOOKUP( QUERY(results_sheet_1:range, query_string_1), lookups_sheet:range, 11, FALSE))
... which returns a single column of values.
I need to call this formula on multiple sheets (results_sheet_1, _2, _3 etc) and combine the output in a single column. The query string is different for each sheet, though in all cases only a single column is returned.
How can this be done?
Replace this:
...QUERY(results_sheet_1:range, query_string_1)...
with this:
{QUERY(results_sheet_1:range, query_string_1);QUERY(results_sheet_2:range, query_string_2);QUERY(results_sheet_3:range, query_string_3)}
Being sure to include the curly braces and semicolons between the ranges.
Related
I was able to format a column with zipcode in my query, the problem is that I want to display several other columns, but I don't know how to reference at this point.
I could only display 1 columns, but I want many more
=QUERY(ARRAYFORMULA(REGEXREPLACE(P43:P44;"-";""));"Select Col1")
I also tried with the substitute:
=ARRAYFORMULA(QUERY(A43:AD44;SUBSTITUTE(E43:E44;"-";"");"Select *"))
Given the following example table:
In case you would want to query after removing the - characters in the ZIPCODE column, you could do it as follows:
=QUERY({A:A, ARRAYFORMULA(REGEXREPLACE(B:B, "-", "")), C:D},"Select * WHERE Col4>23")
The idea is that using the curly bracket notation you join the multiple ranges you want to query from. Using it, you can apply the REGEXREPLACE to the whole B Column, and afterwards query from the resulting range.
This is the obtained result with the previous query:
I am trying to use substitute function inside a query function but not able to find the correct syntax to do that. My use case is as follows.
I have two columns Name and Salary. Values in these columns have comas ',' in them. I want to import these two columns to a new spreadsheet but replace comas in "Salary" column with empty string and retain comas in "Name" column. I also want to apply value function to "Salary" column after removing comas to do number formatting.
I tried with the following code but it is replacing comas in both the columns. I want a code which can apply the substitute function only to a subset of columns.
Code:
=arrayformula(SUBSTITUTE(QUERY(IMPORTRANGE(Address,"Sheet1!A2:B5"),"Select *"),",",""))
Result:
Converted v/s Expected Result
Note :
I have almost 10 columns to import and comas should be removed from 3 of them.
Based on your suggestions, I was able to achieve the objective by treating columns separately. Below is the code.
=QUERY({IMPORTRANGE(Address,"Sheet1!A3:A5"),arrayformula(VALUE(SUBSTITUTE(IMPORTRANGE(Address,"Sheet1!B3:B5"),",","")))},"Select * where Col2 is not null")
Basically, two IMPORTRANGE functions side by side for each column.
The same query on the actual data with 10 columns will look like this.
=QUERY({IMPORTRANGE(Address,"Sheet1!A3:C"),arrayformula(VALUE(SUBSTITUTE(IMPORTRANGE(Address,"Sheet1!D3:H"),",",""))),IMPORTRANGE(Address,"Sheet1!I3:J")},"Select * where Col2 is not null")
I used 3 IMPORTRANGE functions so that I can format the columns D to H by removing comas and changing them to number.
My suggestion is to use 2 formulas and more space in your sheets.
Formula #1: get the data and replace commas:
=arrayformula(SUBSTITUTE(IMPORTRANGE(Address,"Sheet1!A2:B5"),",",""))
Formula #2: to convert text into numbers:
=arrayformula (range_of_text_to_convert * 1)
Notes:
using 2 formulas will need extra space, but will speed up formulas (importrange is slow)
the second formula uses math operation (*1) which is the same as value formula.
Try this. I treats the columns separately.
=arrayformula(QUERY({Sheet1!A2:A5,SUBSTITUTE(Sheet1!B2:B5,",","")},"Select *"))
Thanks to Ed Nelson, I was able to figure out this:
=arrayformula(QUERY({'Accepted Connections'!A:R,SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE('Accepted Connections'!A:R,"AIF®",""),"APA",""),"APMA®",""),"ASA",""),"C(k)P®",""),"C(k)PS",""),"CAIA",""),"CBA",""),"CBI",""),"CCIM",""),"","")},"Select *"))
That removed all the text I didn't need in specific columns.
My spreadsheet looks like this:
I have two lists of dates, I want to get all unique dates between Dates1 and Dates2 and put them in column C.
I can get unique dates in column A with UNIQUE(A2:A4), but I want all unique dates between both columnms. When I try to do =UNIQUE(A2:A4,B2:B5) I get the error:
Wrong number of arguments to UNIQUE. Expected 1 arguments, but got 2 arguments.
How can I get all unique dates between both? I've also tried concatenate, but that just gives me a huge number, not a row of dates.
Thanks!
unique formula can only work with single column. Try this formula:
=UNIQUE({A2:A4;B2:B5})
{ } will convert 2 columns into one: {A2:A4;B2:B5}
See more info here:
https://support.google.com/docs/answer/6208276?hl=en
Put all cells on the argument ie UNIQUE(A2:B5)
For seperate columns, create a dummy column next to the one you are comparing to, set its contents to the actual column, then use Unique
Use iferror to pass processing to a second version of a 'unique list' formula with different columns.
=IFERROR(INDEX(A$2:INDEX(A:A, MATCH(1E+99, A:A)), MATCH(0, COUNTIF(D$1:D1, A$2:INDEX(A:A, MATCH(1E+99, A:A))), 0)),
IFERROR(INDEX(B$2:INDEX(B:B, MATCH(1E+99, B:B)), MATCH(0, COUNTIF(D$1:D1, B$2:INDEX(B:B, MATCH(1E+99, B:B))), 0)), TEXT(,)))
Turns out (thanks to Keatinge) that UNIQUE takes an array of ranges separated by a semi-colon and wrapped in braces. Putting the range limiters from my own solution in achieves:
=unique({A$2:INDEX(A:A, MATCH(1E+99, A:A));C$2:INDEX(C:C, MATCH(1E+99, C:C))})
That sample google-sheets is here.
Is there any way to make the below formula as a dynamic array formula:
=query(
{IMPORTRANGE(B2,"Filter!B:C");
importrange(B3,"Filter!B:C");
importrange(B4,"Filter!B:C")},"Where Col2 <>''")
If my input will be three spreadsheet keys then IMPORTRANGE should execute three times, if my input is five spreadsheet keys then IMPORTRANGE should execute five times.
The answer to this Q is no, you can't.
importrange is already an arrayformula in some way because it returns array, so it can't take an array of keys\ranges as input.
Workaround
You may combine the the formula as string, get string like this:
"=query({importrange(...);importrange(...)...},"select...")"
and then use script to convert the string into formula.
for example, make ini sheet, in col A make list of importranges:
="importrange("&B1&",""Filter!B:C"")"
="importrange("&B2&",""Filter!B:C"")"
="importrange("&B3&",""Filter!B:C"")"
and so on
Put keys in col B.
then make filter formula to join them with semicolon:
= join(";", filter (A:A, A:A <> "")
so you get the part of future formula:
"importrange(B2,"Filter!B:C");importrange(B3,"Filter!B:C");..."
and then concatenate another parts of the formula.
Final step is to use script to convert this text formula and paste it as actual formula to the target sheet. Script may work dinamically if you use onEdit trigger to check any changes in ini sheet.
In my Google spreadsheet, i'm using the query function to get data from one sheet onto another. The query looks something like this:
=QUERY('mySheet'!$A$1:100,"select F where "&C$3&"='myValue'")
This works fine until cell C3 has value "BY" (because the word "by" has significance in the query language). I've tried using single quotes, but then the query uses header "BY" instead of column BY and it returns an empty result.
Any ideas on how to work around this?
Put it in backticks.
=sum(QUERY(select `BY` where `BY` is not null limit 7))
This will sum the first 7 values in column BY.
(This was fun to debug. The formula worked in every other column...)
"BY" is a special word. It is present in clause group by
You may use this:
=QUERY({'mySheet'!$A$1:100},"select Col5 where Col"&C$3&"='myValue'", 0)
and paste the column number into C$3
see more info here
BTW you may use function column() to know BY is column 77 or find the right number by header name: =match("column name", 'mySheet'!1:1, 0)