Query Importrange Issue - google-sheets

I am not sure why this functionality stopped working, but I am sure it has to do with inconsistent back end data or how the query condition "CONTAINS" needs to be changed. The IMPORTRANGE portion works just fine, but will not always pull data into the front end sheet. The query portion looks like this
SELECT Col3, Col2, Col1 WHERE Col2 CONTAINS "&'Job Number'!A1&" ORDER BY Col3 ASC,1
Column 2 contains job numbers that are xxxxx with another 3 digit code appended to end of it. It will only populate temporarily if I manually go into the sheet and edit the IMPORTRANGE range values. If I close the spreadsheet and open it again it will not populate. Does the data in Column 2 need to be a consistent datatype throughout the column or it will break the query?

Unfortunately we do not have a test sheet, so we can not know what the expected results would be.
Nevertheless, your formula syntax is not correct.
The correct syntax would be:
SELECT Col3, Col2, Col1 WHERE Col2 CONTAINS '"&"JOB"&A1&"' ORDER BY Col3 ASC,1
Please notice the syntax '"&"JOB"&A1&"'
(If you still have issues please share a test sheet and let us know.)

Related

Extract Value from Cell on Another Sheet Based on List

I have a list of data on one sheet. A second sheet is used to display who's done what, like a dashboard. I've been given an array formula to generate the data that looks up the employee's name, and displays it if they are present on the list for a course completed. If so, a "yes" is listed on the dashboard under the corresponding course number. I cannot figure out what I need to change the REGEXREPLACE with to present the date column from the data list instead of "yes". I'm aware REGEXREPLACE only works for text values, and dates aren't - even changing the date column to text seems to matter not.
Here is a working example of the current array formula:
https://docs.google.com/spreadsheets/d/1jkG515zyl4UxRHxhtFTjgWsjG0aBE4vsOxbpvqgjogU/edit#gid=536376041
Here is the formula used:
=ARRAYFORMULA(IF(A5:A="",,REGEXREPLACE(IFNA(VLOOKUP(A5:A,
QUERY({TRIM('Form Responses 1'!B2:G)}, "select Col1,count(Col1) group by Col1 pivot Col6"), MATCH(F2:P2,
QUERY(QUERY({TRIM('Form Responses 1'!B2:G)}, "select Col1,count(Col1) group by Col1 pivot Col6"), "limit 0", 1), 0), 0))&"", "\d+", "yes")))
In the above example, I need the Date Completed from col D on the Form Responses sheet.
Here is a first attempt that might help you.
This is a straightforward query, that pulls the dates, and pivots to have the employee names on the left, and the course names on the top.
But it doesn't try to match up data with an existing list of employees - it just lists all of the employees that have submitted a form. So if you want to see all employees, with blank rows for those who haven't submitted a form, this won't work for you.
The formula, in A2,is:
=ARRAYFORMULA(QUERY({'Form Responses 1'!B2:G}, "select Col1,max(Col3) where Col1<>'' group by Col1 pivot Col6 order by Col1"))
See tab Sheet1-GK, added to your sample sheet.
Let me know if this helps, or if you need something different.
UPDATE:
To limit the result to a specific list of courses, use the following modification:
=ARRAYFORMULA(QUERY({'Form Responses 1'!B2:G},
"select Col1,max(Col3) where Col1<>''
and Col6 matches '" & TEXTJOIN("|",1,F2:2) & "'
group by Col1 pivot Col6 order by Col1 "))
Here, the list of desired courses to report on is in F2:2, where you had them originally, but this list could be kept anywhere, even on another tab. If you name the range where you place it, that can simplify this formula a bit. For now, you could just hide row 2. I've grouped it, on the left, to hide it. Use the [+] to reveal it again.

Use Query to display two columns and group rows based on one column's count?

I'm using an array to bring 2 columns of data together from 3 sheets.
There are duplicates in the second column, and I would like to group those duplicates together and display both Col1 and Col2, ordered alphabetically by Col1.
This is the formula I have right now:
=QUERY({'Sheet1!'A:B;'Sheet2!'A:B;'Sheet3!'A:B}, "Select Col1, count(Col2) where Col1 is not null group by Col1",1)
Which only displays Col1.
I've tried nesting QUERY, but I can't get it to work and can't find any direction anywhere online.
Here's an example sheet I made to show what I'm trying to do:
https://docs.google.com/spreadsheets/d/1_x0mXZC0ZjsHDCd6I0dDf9OI19lrzEcPYqfcMxuK74Y/edit?usp=sharing
In the example if an employee is listed twice the name may change but the email is consistent. I'm hoping to group by the email addresses and return only one name (it doesn't really matter which name).
I'm not sure if this is possible without formulas in more than one cell. Thank you either way!
#confuseddesk, try this array formula:
=ArrayFormula(QUERY({VLOOKUP(UNIQUE({Sheet2!B2:B;Sheet3!B2:B;Sheet4!B2:B}),{Sheet2!B2:B,Sheet2!A2:A;Sheet3!B2:B,Sheet3!A2:A;Sheet4!B2:B,Sheet4!A2:A},2,FALSE),UNIQUE({Sheet2!B2:B;Sheet3!B2:B;Sheet4!B2:B})},"Select * Where Col2 Is Not Null"))

Google Sheets import range returning incorrect data

The full google spread sheet system is used for score keeping and is prone to delays when updating, however I have never run into an issue like this were the same basic function is returning two separate results. The problem is repeatable and occurs on more than one spreadsheet.
I have created a test sheet-
https://docs.google.com/spreadsheets/d/1arh0D9ch5MpQjRh_bHjLfLx5S7TAW8R_pgGLf5tovig/
with the code in question; Can anyone help please?
=QUERY(IMPORTRANGE("***","***"),"select Col1 where Col1 <>5 order by Col9 desc")
in your QUERY formula you are selecting cells that are numeric and comparing it to <>5 but take a notice that A2 is not numeric:
that is the reason why 2 2 is not included in your C column
also it looks like that your QUERY formula smashed first cells into one because you did not specify the 3td query parameter. try:
=QUERY(IMPORTRANGE("1pnowvo6YVj-DZAPCaKE2x9vSIbpAAmlwhRMO2OZNlrE","color!A84:M115"),
"select Col1 where Col1 <>5 order by Col9 desc", 0)

Import Range from spreadsheet but exclude rows with missing data

I have 2 spreadsheets (sheet1 + sheet2)
Sheet2 Pulls in data from Sheet1 using the IMPORTRANGE function which works fine, except that there are a few rows that have missing information in 1-2 columns and for the purpose of what I am trying to do I need to just remove these rows.
Can anyone point me in the right direction? Not sure if I need to add something to the IMPORTRANGE function or create a new spreadsheet and use a different function or do I have to manually delete these rows?
Cheers
The QUERY function provides this ability. The "IS NOT NULL" argument works with numbers, and "!=" is for Strings (anything that's not just numbers).
=QUERY({IMPORTRANGE("YourKey","SheetName!A:B");
IMPORTRANGE("YourKey,"SheetName!A:B");},
"SELECT Col1, Col2 WHERE Col2 IS NOT NULL")
Or
=QUERY({IMPORTRANGE("YourKey","SheetName!A:B");
IMPORTRANGE("YourKey,"SheetName!A:B");},
"SELECT Col1, Col2 WHERE Col2 != ''")

Google spreadsheet Query Error - column doesn't exist

Another problem with Google Spreadsheet API. I'm trying to use QUERY() function in order to get all customers from our database who are from Warsaw. Google API seems however to have a big problem with parsing my query. I've checked it few times and everything is OK. Tried semicolons, different apostrophes and column names—it still won't work. I type this code in the sheet cell:
=QUERY(IMPORTRANGE("0ArsOaWajjzv9dEdGTUZCWFc1NnFva05uWkxETVF6Q0E"; "Kuchnia polska!A3:G40"); "select B where E contains 'Warszawa'")
And get error like this:
Invalid query: Column [E] does not exist in table.
And I'm 110% sure that the column exists and the spreadsheet key is OK. ;)
If you are using the Query function with a direct reference to a rectangle of cells, then you use capital letters to refer to the columns. However, if you are using Query against the output of an array formula, such as the return from ImportRange, then you instead need to use Col1, Col2, ... to refer to the columns. So, your example query string would need to read:
"select Col2 where Col5 contains 'Warszawa'"
Working example:
=Query(ImportRange("0AtEH2Kw9zfIodEQ2dFNFam9sdEFEZlVnNEV3ZEZMZEE", "data!A:G"), "select Col3, count(Col4) group by Col3 order by count(Col4) desc label count(Col4) 'count'")
I've no idea why it doesn't just let you use names from a header row.
Alternatively you can try the FILTER function in this case and then you don't need to bother with SQL. :)
=FILTER(ImportRange("0ArsOaWajjzv9dEdGTUZCWFc1NnFva05uWkxETVF6Q0E"; "Kuchnia polska!B3:B40"); ImportRange("0ArsOaWajjzv9dEdGTUZCWFc1NnFva05uWkxETVF6Q0E"; "Kuchnia polska!e3:e40")="Warszava")
Although I admit that it's not so pretty because of the two importRange functions.
Hope it helped anyway.

Resources