Can I pull out a single cell with query in google sheets? - google-sheets

I'm trying to find a way to (I think) get a single cell out as part of a query that also returns columns, I don't know if it's even possible. Brief explanation - every quarter we get v. detailed audit reports in via google sheets in 6 spreadsheets of between 20-45 case files each, each with their own separate tab/sheet within that. I've managed to use query to pull out and collate the major issues from all of them in a new sheet for analysis using
=QUERY({IMPORTRANGE(A3,"Case File 1!F18:M");IMPORTRANGE(A3,"Case File 2!F18:M");IMPORTRANGE(A3,"Case File 3!F18:M")},"Select Col1,Col4,Col7 where Col4 contains 'concern'")
This gives me a neat list of all the concern point narratives against the specific criteria they come under, to do funky things with, but what I haven't managed to do is actually get anything that says 'these concern points are from Case File 1' or similar. There could be 0, 1, 5 concern points, so I never know how many rows it's going to return. Is there an easy way to go 'select this one cell (with the organisation name on) as well as the concern bits and stick the name next to all of them? I doubt it, but any ideas welcome, I don't want to have to run the queries separately and collate them later. Can't attach a copy of the sheets unfortunately, it's all confidential info. I've tried adding Col3 to the mix, which is the one with the name on (and some other extraneous info that looks messy, but ah well) but this only returns the name bit for the first sheet on the top - I haven't got the hang of headers so that might be why?
Cheers, sorry for the length, first question and I'm not sure what you need to know.
Meg

Try:
=arrayformula(
query({
query({iferror(IMPORTRANGE(A3,"Case File 1!F18:F")/0,"Case File 1"),IMPORTRANGE(A3,"Case File 1!F18:M")},"where Col5 contains 'concern'",0);
query({iferror(IMPORTRANGE(A3,"Case File 1!F18:F")/0,"Case File 2"),IMPORTRANGE(A3,"Case File 2!F18:M")},"where Col5 contains 'concern'",0);
query({iferror(IMPORTRANGE(A3,"Case File 1!F18:F")/0,"Case File 3"),IMPORTRANGE(A3,"Case File 3!F18:M")},"where Col5 contains 'concern'",0)
},"select Col1,Col2,Col5,Col8",0)
)
This option places the text column at the end (and just one query):
=arrayformula(
query({
IMPORTRANGE(A3,"Case File 1!F18:M"),iferror(IMPORTRANGE(A3,"Case File 1!F18:F")/0,"Case File 1");
IMPORTRANGE(A3,"Case File 2!F18:M"),iferror(IMPORTRANGE(A3,"Case File 2!F18:F")/0,"Case File 2");
IMPORTRANGE(A3,"Case File 3!F18:M"),iferror(IMPORTRANGE(A3,"Case File 3!F18:F")/0,"Case File 3")
},"select Col1,Col4,Col7,Col9 where Col4 contains 'concern' ",0))

Related

Google Tables INDIRECT function doesn't work how I want

For geting data from another sheet I use function INDIRECT
=INDIRECT("s!$A1")
but I foud a BUG: this formuls locate on another sheet, and if sheet, from which data will be received, doesn't exist yet, then the formula does not work, throws an error that it refers to an invalid range or sheet. If the sheet was created in advance with the desired name, then everything works correctly. If you create a sheet, and then rename it, then return the previous name again, it also does not work.
s - this is the title of the sheet
I found a temporary solution, it works as it should, but it also has a issue
=IMPORTRANGE("link_to_this_file"; "s!$A1") Here is the hard link to the file. This option is not suitable, because when copying a file, the formulas must remain working, otherwise everything will break.
Please let me know what can be done in this case. Maybe there is an option to read the file name to insert into IMPORTRANGE ?
Or is there some other function with similar properties besides IMPORTRANGE, INDIRECT ?
I found one more solution
=query(s!A1;"select * limit 1")
, but....
I don't understand how add the name of sheet dynamically
I need to read name from cell,(the name s located in F25 cell), if I change it to another (for example g)
the formula must changed to
=query(g!A1;"select * limit 1")
Considering that INDIRECT works with strings, and you have in F25 the name of the street you could try:
=INDIRECT(F25&"!A1")
Or, if you have a name with more than one word:
=INDIRECT("'"&F25&"'!A1")

Importrange multiple files and query not pulling data

Im trying to import more than a 100 files into one masterfile.
The problem I'm having is that when I use query null to filter blank rows, some cells return as blank (probably because the entries to that cell's column may either be a text or number string)
Is there any way around this so that the query will just take the values/any string within the cell. I'd hate to see a lot of blank rows from the import of more than 100 files!
Appreciate any help. Thank you!
before using QUERY you can force the text format with TO_TEXT so:
=ARRAYFORMULA(QUERY(TO_TEXT({
IMPORTRANGE("id1"; "A1:A");
IMPORTRANGE("id2"; "A1:A");
IMPORTRANGE("id3"; "A1:A")}); "where Col1 is not null"; ))
keep in mind that every of your 100 importranges needs to be run as standalone fx prior to using the above formula to connect your sheets by allowing the access

Attempting to Merge data and sum up the similar items. After a Filter/Sort within Google Sheets

Currently working on a project where im trying to Filter out and Sort out data from one list based on a dropdown menu. When the data gets pulled from the other list into a better readable format, it brings along some duplicate item names due to being listed seperately based on SKUS, is there any way i can SUM the total qunatities together, and have just 1 name within that list via Functions?
my current function is
=SORT(FILTER('Month of Detailed Manifest Report'!B2:D, 'Month of Detailed Manifest Report'!A2:A = A3, 'Month of Detailed Manifest Report'!B2:B <> "SAMPLES"),1,True)
Brings my data up like this.
You can see how it adds Duplicate Data Here
Just trying to get it so it merges the similar names and adds the Qty's together so i can get a better accurate data pull of information.
See my comment to your original post. That said, just eyeing it here and without the ability to test it, you can try this formula:
=QUERY({'Month of Detailed Manifest Report'!A2:D},,"Select Col2, Col3, SUM(Col4) WHERE Col1 = '"&A3&"' AND Col2 <> 'SAMPLES' GROUP BY Col2, Col3 LABEL SUM(Col4) '' ORDER BY Col2")
In theory, that should work.
If not, as I invited in my previous comment, share a link to a copy of the spreadsheet.

How to handle data manipulation when using importrange() in Google Sheets?

I am working on speeding up a workbook in Google sheets that is using importrange(). The purpose of the entire workbook is to import data from a mastersheet and then allow us to manipulate it the way we want to outside of the mastersheet.
The problem: because importrange() doesn't allow you to directly manipulate cells we have Sheet1 acting as the import sheet; it doesn't get touched. Sheet2 is where we do the manipulating but, it was literally just taken as a copy of Sheet1, so it is also using importrange(). This bogs down the entire workbook and makes manipulations very slow.
I am thinking of using !Sheet1A1... and copying that to all the cells in the manipulation sheet, but my concern is that this will still bog down the workbook. There is potential that the import data could grow as large as 10k+ rows, and I'm only at about half that currently and running into this problem. Outside of that, I'm not sure what else there is to try.
The QUERY function can help here and there are some great resources online.
=importrange(spreadsheet_url, range_string)
a typical example is:
=importrange("https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxx","Sheet1!A:Z")
You can wrap a QUERY function around this to manipulate your data.
QUERY is like a version of SQL and very powerful. It's in the format:
=QUERY({},"",1)
Your data range importrange("https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxx","Sheet1!A:Z") would go within {}.
Then within the "" part of the query, you could write your parameters for manipulating the data.
Example:
select Col1,Col4,Col5 where Col1 is not null and Col6 contains 'hello' order by Col1,Col7 desc label Col1 'new name 1',Col4 'new name 4'
The select bit allows you to specify specific columns from your importrange. If you want the all, then you could use select *.
The where item is where you build up your criteria using various or or and parameters.
is not null is another way of saying you want rows that have data.
contains is useful. You can also have matches, starts with, ends with and like. like can use wildcards %, so where Col1 like '%the%' would find 'hello there'.
order by is ascending unless you add desc, ie. order by Col1,Col2,Col4,Col5 desc,Col3.
label allows you to rename the columns, so let's say input column 1 is called 'Name1' and input column 2 is 'Name2' and you want them to be 'First name' and 'Surname, you would use label Col1 'First name', Col2 'Surname'.
If you like QUERY there are other powerful clauses, and they run in this order within the QUERY(range,"clauses",0):
select
where
group by
pivot
order by
limit
offset
label
format
options
One small point which you may come across, when you use importrange to get your data you need to reference the columns as Col1,Col2,Col3 within the QUERY.
If, however, your range is already in the same sheet (same or different tab), then you would reference column letters instead, eg. select A,B,C where A is not null order by A desc.
To make it more consistent and use the Col1,Col2,Col3 notation, you would put your internal range in an array {}.
QUERY(Sheet1!B:F,"select B,C,D where F is not null order by B,C",0)
would become:
QUERY({Sheet1!B:F},"select Col1,Col2,Col3 where Col5 is not null order by Col1,Col2",0)
{Sheet1!B:F} is smart because you can add columns in front of this range without needing to change your clause. So adding one column in front of Sheet1, would result in:
QUERY({Sheet1!C:G},"select Col1,Col2,Col3 where Col5 is not null order by Col1,Col2",0)
The other method would need you to alter your clause from:
QUERY(Sheet1!B:F,"select B,C,D where F is not null order by B,C",0)
to:
QUERY(Sheet1!C:G,"select C,D,E where G is not null order by C,D",0)
It's a lot to take in, but definitely worth persuing!

Google sheets query searching multiple columns with space seperator within a cell

Now this following query runs great on one column and does use a space as a search separator however it only seaches one column.
=QUERY(Data!A1:O, "SELECT * WHERE LOWER(N) LIKE LOWER(""%" &JOIN("%"") AND LOWER(N) LIKE LOWER(""%", SPLIT(B1," "))&"%"")",1)
However then I found this snippet and that searches the entire sheet but cannot separate words within a cell.
=ARRAY_CONSTRAIN(IFERROR(QUERY({Data!A:O, TRANSPOSE(QUERY(TRANSPOSE(Data!A:O),,99^99))}, "where lower(Col16) contains '"&LOWER(B1)&"'", 1)), 99^99, COLUMNS(A:O))
The issue is I want to search multiple of my columns namely D,E,G,H,M,N where M contain multiple words that should be searched separated by a comma and space since the data comes from a form.
Is there a way that makes it possible to achieve this?
Link to a very obfuscated sheet upon request data is somewhat similar yet document is very simplified and shortened.
https://docs.google.com/spreadsheets/d/1PxdObZsn62rQ3QeYVdy9HjToIHZsmw1d0cXK2jOuiC4/edit?usp=sharing
Solution
In this case you should use the same approach you were using before, but now when searching in the built Col16:
=ARRAY_CONSTRAIN(IFERROR(QUERY({Data!A1:O, TRANSPOSE(QUERY(TRANSPOSE(Data!A1:O),,99^99))}, "where lower(Col16) LIKE LOWER(""%" &JOIN("%"") AND LOWER(Col16) LIKE LOWER(""%", SPLIT(B1," "))&"%"")", 1)), 99^99, COLUMNS(A:O))

Resources