Using Google Sheets I want, within the same document, to import data from one sheet to another using IMPORTRANGE with conditions.
I have tried unsuccessfully:
=IF(IMPORTRANGE("https:URL","Inc Database!B2:B300")="permanent",IMPORTRANGE("htps://URL","Inc Database!A2:A300"),"")
and
=QUERY(IMPORTRANGE("https:/URL", "Inc Database!A2:A300"),"SELECT Col1 WHERE Col1 <> 'permanent'")
and
=FILTER(IMPORTRANGE("URL","Inc Database!A1:A250"),IMPORTRANGE("URL","Inc Database!B1:B250"="venture permanent"))
I want the function to say: Import any values from range A that meet criterion "permanent" in range B.
A | B
_________|_________
Name |type
---------|-------
Henry |Permanent
William |Intern
John |Permanent
I have put a few examples in the following spreadsheet:
e.g. =QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1LX7JfbGvgBTfmXsYZz0u5J7K0O6oHJSnBowKQJGa9lY/edit#gid=0", "Inc Database!A2:B300"),"SELECT Col1 WHERE not(Col2 = 'Permanent') ")
You need a single quote around the reference to the sheet/tab since there is a space in the name. Using your example:
IMPORTRANGE("https:/URL", "'Inc Database'!A2:A300")
But this will only import column A, so you cannot check against column B
Then use the Query. If you want everything where B is 'Permanent' then you want (untested):
=QUERY(IMPORTRANGE("https:/URL", "'Inc Database'!A2:B"),"SELECT Col1 WHERE Col1 = 'Permanent'")
This will:
Import all of the rows, starting at A2 from the main data sheet to use in the Query().
Via Query, return only those where Col2 (B) contains 'Permanent'
Related
I want to do an IMPORTRANGE with a filter, where it only pulls through data if a cell in column C contains a term that is listed in another column G.
I need columns A:E to import from another sheet, if the column C data appears in column G somewhere, on the current sheet.
This is what I have done which isn't correct but can't work it out:
=QUERY(IMPORTRANGE("URL","Sheet1!A2:E"),"select * where $C='$G:$G'")
Please see the image below:
use:
=QUERY(IMPORTRANGE("URL", "Sheet1!A2:E"),
"where Col3 matches '"&TEXTJOIN("|", 1, G:G)&"'")
I'm pretty new with ArrayFormula, have been trying but sometime the formula works, sometimes does not. What I'm trying to do is the combination of ArrayFormula, Countif for searching partial text.
As shown in the worksheet below, there are 10 subjects (column A), each subject has at least one of 4 samples (A,B,C,D) summarized as a string (column B). What I'm trying to do is to find which subject has sample A or B or C or D.
I have tried single formula for each sample, eg cell D3
=IF(COUNTIF($B3,"*"&$D$2&"*")>0,$A3,"")
it returns the correct results. However, when I try arrayformula in cell I3,
=arrayformula(IF(COUNTIF($B3:B,"*"&$D$2&"*")>0,$A3:A,""))
The answers are weird. For example: Subjects (Gamma, Zeta, Eta, Theta) who don't have the sample "A" are shown to have sample "A". And this applies to sample B,C,D too
Not sure what went wrong in here. Here is the link to the worksheet
I wouldn't use Countifs or an array formula. Use filter instead. Put this formula in cell i3.
=Filter(if(REGEXMATCH(B3:B,$D$2),A3:A,""),B3:B<>"")
try:
=INDEX(QUERY(IFERROR(TRIM(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B3:B, ","))="",,
SPLIT(B3:B, ",")&"×"&A3:A)), "×"))),
"select max(Col2) where Col2 is not null group by Col2 pivot Col1"))
or use in row 2 if you want to sort it as in your example:
=INDEX(IFNA(VLOOKUP(A2:A, QUERY(IFERROR(TRIM(SPLIT(FLATTEN(
IF(IFERROR(SPLIT(B3:B, ","))="",,SPLIT(B3:B, ",")&"×"&A3:A)), "×"))),
"select Col2,max(Col2) where Col2 is not null group by Col2
pivot Col1 label Col2'Subjects'"), {2,3,4,5}, 0)))
You can accomplish all four columns of results with a single formula.
Delete all formulas from I3:L3.
Place the following formula into I3:
=ArrayFormula(IF(REGEXMATCH(B3:B,I2:L2),A3:A,))
In plain speech, this read "If anything in B3:B matches a value found in I2:L2, return A3:A in the matching columns(s) at the matching row(s); if not, return null."
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
Below is my query function in its original form:
=ArrayFormula(query({importrange("1yqTUmJcL6YxgOpfHS5Pt9nYnmpiqN3tUPQP7-Rp8xis","CPG!A2:L20");importrange("1yqTUmJcL6YxgOpfHS5Pt9nYnmpiqN3tUPQP7-Rp8xis","PUB!A2:L20")},"Select Col5, Sum (Col4) where Col6='' group by Col5 pivot Col7"))
Which I am trying to shorten the formula by using indirect to refer to concatenated import ranges by the following attempt
=ArrayFormula(query(indirect("JOIN!J3"),"Select Col5, Sum (Col4) where Col6='' group by Col5 pivot Col7"))
but come up with this error:
Error
Unable to parse query string for
Function QUERY parameter 2:
NO COLUMN: Col5
The Join!J3 cell contains the value below:
{importrange("1yqTUmJcL6YxgOpfHS5Pt9nYnmpiqN3tUPQP7-Rp8xis","CPG!A2:L20");importrange("1yqTUmJcL6YxgOpfHS5Pt9nYnmpiqN3tUPQP7-Rp8xis","PUB!A2:L20")}
I research various similar question in forums but their answers comes to no solution. Usually it is to use "Select Col1" instead of "Select A" but my formulas are all using Col1, Col2 already. Am doing anything wrong?
I have included some images for further clarification.
The original formula:
The shortening attempt:
The cell value in sheetname: JOIN cell: J3:
The cell value in J3 is actually a pasted value from cell A1:
If I understand correctly, because your formula is now referring to a specific range in the sheet instead of an array of ranges, you will need to use A, B instead of Col1, Col2, etc.
I assume the data produced by cell J3 in the sheet JOIN displays data in J3:U21 (based on the range A2:J20). You need to query all of this, not just the cell containing the formula.
Try the formula below.
(I have made assumptions about what columns the data sits in--please amend where necessary).
=ArrayFormula(query(indirect("JOIN!J3:U21"),"Select N, Sum (M) where O='' group by N pivot P")
EDIT: You seem to be using the same range and ID. You can refer to them using just two cells.
={IMPORTRANGE(D6,"SheetName1"&E6);IMPORTRANGE(D6,"SheetName2"&E6)}
I'm in the need of collecting unique values from a specific range in several sheets. Is it possible to combine functions in order to do this?
All sheets look the same regarding column structure.
As of now, my function collects from one sheet and it looks like this:
=unique(filter('Sheet1'!C4:C1000,'Sheet1'!C4:C1000<>""))
This collects unique values from Sheet1 from C4 to C1000 and excludes empty cells. This works awesomely, but I have more sheets that I'd like to merge values from. Any idea?
Basic idea is to combine data, first with help of {}:
= {sheet1C4:C1000;sheet2C4:C1000;sheet3C4:C1000}
The next step is to get rid of empty cells. To do it only once, use query:
= query({sheet1C4:C1000;sheet2C4:C1000;sheet3C4:C1000},
"select Col1 where Col1 <> ''")
And then grab uniques/ The final formula will look like:
= unique (query({sheet1C4:C1000;sheet2C4:C1000;sheet3C4:C1000},
"select Col1 where Col1 <> ''"))
By the way, query string may be shortened to this "where Col1 <> ''" will also work