Query with import range for multiple google sheets - google-sheets-formula

I am trying to import data from different GOOGLE sheets with the below formula, suggesting the correct formula getting Error "AS Unable to parse query string for Function QUERY parameter 2: NO_COLUMN: Col18. Please guide for correct formula" & "In ARRAY_LITERAL, an Array Literal was missing values for one or more rows."
=Query({IMPORTRANGE("1srpJok8Clb_hIW0mVfx74VjrAOmGmHXavXFZ1H77pnQ","Daily DPS Delhi!A4330:R");IMPORTRANGE("1__6apvi3ICKaMQz7R4SNzm_KXtCIERavBTxQ8Dkf1bs","Trip Data!A174295:R");IMPORTRANGE("1r3CbiyP_AFcpvm4eNvJO_VvNWZjxkrIHdiOgGhyLZQg","DPS Bangalore!A20640:R")},"Select Col1,Col18,Col7,Col11,Col12 where Col1 is not null")

=QUERY({
IMPORTRANGE("1srpJok8Clb_hIW0mVfx74VjrAOmGmHXavXFZ1H77pnQ","Daily DPS Delhi!A4330:R");
IMPORTRANGE("1__6apvi3ICKaMQz7R4SNzm_KXtCIERavBTxQ8Dkf1bs","Trip Data!A174295:R");
IMPORTRANGE("1r3CbiyP_AFcpvm4eNvJO_VvNWZjxkrIHdiOgGhyLZQg","DPS Bangalore!A20640:R")},
"select Col1,Col18,Col7,Col11,Col12
where Col1 is not null")
the formula is ok but you need to run each importrange separately and allow access to connect all spreadsheets. only then you can use this formula

Related

to how can I do web scraping to get prices for my products which I have ony google spreadsheet? dynamically queries

could you please give me an idea about how I can get thi
Many sites go to great lengths to actively prevent scraping. Giving you just the data you want entirely undermines their business model. If you're a consumer, they're denied the chance to show you advertising. If you're a reseller, you can use fairly simple programming and marketing to undercut their prices.
If you find yourself unable to scrape, it may be because it's not going to be possible.
unfortunately, that won't be possible because the site is controlled by JavaScript and Google Sheets can't understand/import JS. you can test this simply by disabling JS for a given link and you will see a blank page:
A workaround. You can import the data with the following script (credits to Brad Jasper) : ImportJSON, then request with QUERY formula. This is an example with "iPhone 8" and "Playstation 4".
In column A, you write the product to search. The url to get the JSON data is automatically build in column B with a concat operator.
="https://wss2.cex.uk.webuy.io/v3/boxes?q="&A2
In column C, you have the QUERY formula combined with the ImportJSON data step.
=QUERY(ImportJSON(B2);"SELECT Col4,Col20 WHERE Col4 CONTAINS 'Plus' AND Col4 CONTAINS '64' AND Col4 CONTAINS 'Unlocked' LIMIT 1 label Col4'',Col20''";1)
Col4 : product description, Col20 : price of the product. Since the JSON will return a lot of results (multiple iPhone 8 versions), this is the step where you can refine your search. I've searched for "Plus","64" and "Unlocked" in the product description.

How do I use IMPORTXML to import just a limited range within a table, not the entire table?

I'm using Google Sheets to scrape a website table using the IMPORTXML function. The initial XPath obviously only references a single cell in that table so I'm wondering how to alter the syntax to import only the first 100 rows of the second column.
I've tried using IMPORTHTML but the syntax seems to be even more limited.
=importxml(B4,"//*[#id='historical-data']/div/div[2]/table/tbody/tr[1:100]/td[2]")
The above code gives the following error:
"Imported XML content cannot be parsed."
try this perhaps:
=QUERY(IMPORTXML(B4, "//*[#id='historical-data']/div/div[2]/table/tbody/tr/td[2]"),
"limit 100", 0)
The [1:100] syntax does not work. Try [position()<=100] instead:
=importxml(B4,"//*[#id='historical-data']/div/div[2]/table/tbody/tr[position()<=100]/td[2]")
I switched IMPORTXML for IMPORTHTML to give quite an elegant solution:
=query(importhtml(B4,"table",1),"select Col2 limit 110 offset 1",0)
Shoutout to #player0 for getting me 90% there.

Empty filter results gives #VALUE! error

I've been working on this project where I need to consolidate data from two other sheets within the spreadsheet and filter the result for easy viewing. But I realized the problem when the filter gives no result there will be a #VALUE! error. The error isn't solved even when I have used IFERROR.
Link to the sample of the Google Spreadsheets.
There are two classes and I wish to filter out those who passed in the class and populate the table in the collated sheet.
You should be able to do something like this:
=query({Class1!A2:C; Class2!A2:C}, "where Col3 = 'pass'")
(change the sheet names and ranges to suit !).
(Also check the formula I entered in A1 of sheet 'JP')

Why is this function throwing a filter error?

I'm working with a Google Spreadsheet that's pulling data from another sheet if certain conditions are met. Well, at least that's what it should be doing—instead, I'm getting "No matches are found in FILTER evaluation."
The function is:
=filter(importRange("https://docs.google.com/spreadsheets/d/1Z_7hl4uEc-an2rOUgOd_zYhCeb_QNIZopahJqBYooRg/edit#gid=0", "Sheet1!R2:R5000"), SEARCH( A3 , index(importRange("https://docs.google.com/spreadsheets/d/1Z_7hl4uEc-an2rOUgOd_zYhCeb_QNIZopahJqBYooRg/edit#gid=0", "Sheet1!V2:V5000")) ) )
I've tried it with a variety of row and column parameters for the index() function. I've also tried adding * to the beginning and end of the search term in A3, in case that's the issue. I've also tried putting quotes around the value in A3.
What am I missing? Sample spreadsheet is here.
I can't find a reference at the moment, but there is a known issue associated with the fact that the newest version of Sheets requires that you explicitly allow access to the other sheet via ImportRange. The issue is, when the ImportRange is nested, it doesn't give the opportunity to allow access - it will just return a #REF error inside your formula.
The work around is to just invoke the ImportRange by itself first (you could use a smaller range):
=ImportRange("https://docs.google.com/spreadsheets/d/abcdefg","Sheet1!R2")
then "Allow access" when prompted; then nest it in your formula.
As an aside, it is advisable to use ImportRange as few times as possible, so in your case it might be better to use QUERY:
=QUERY(ImportRange("https://docs.google.com/spreadsheets/d/abcdefg","Sheet1!R2:V5000"),"select Col1 where Col5 contains '"&A3&"'",0)
You can cheat the IMPORTRANGE issue by having a page which just pulls a single cell from every sheet you want to reference nested. Once it's been given permission the permission persists throughout the sheet.

Exporting Table Data to Google Spreadsheet via XPath

I´m trying to export table data to Google Spreadsheet by using the importxml command and XPath but it doesn´t work. A parser error appears, which says that there´s an error while parsing the formula.
I want to get the mobile PIs from this page: http://ausweisung.ivw-online.de/index.php?i=1121&a=a9170
I tried a command like this: =IMPORTXML("http://ausweisung.ivw-online.de/index.php?i=1121&a=a9170"; "//*[#id="ibody"]//div[1]/div/div[3]/div[2]/table/tbody/tr[4]/td[5]")
As mentioned in the comments below, I also want to perform the request more dynamic. I want to search for a specific string and then jump to a column of my choice.
There is a formula error because you use double quotes (") inside other double quotes. You have to use single quotes inside a string that is delimited by double quotes.
=IMPORTXML("http://ausweisung.ivw-online.de/index.php?i=1121&a=a9170", "//*[#id='ibody']//div[1]/div/div[3]/div[2]/table/tbody/tr[4]/td[5]")
The result is still #N/A, presumably because your path expression does not match anything.
EDIT
I´m looking for the right xpath command to get (in this case) just the data '11.824.563'.
The correct expression to retrieve this value would be:
=IMPORTXML("http://ausweisung.ivw-online.de/index.php?i=1121&a=a9170", "//div[#class='statistik']/div[#class='uebersicht']/table/tr[3]/td[2]")
But unfortunately, IMPORTXML is so buggy and unreliable that this still yields "#N/A" as a result. This seems to have worked in older versions of Google Spreadsheets:
https://productforums.google.com/forum/#!msg/docs/yWPaNDK0Kpg/3UIIeDA0SAIJ
Thanks to a user from the Google product forums I got the right formula to solve my request correctly.
=arrayformula( value( regexreplace( query( importHTML("http://ausweisung.ivw-online.de/index.php?i=112&mz_szm=201408"; "table"; 3) & ""; "select Col5 where Col3 = 'GLAMOUR (Smartphone-Apps)' "; 0 ); "[^\d]"; "" ) ) )
This request is looking for a specific string in a specified table, and grabs the data from the fifth column in this row.

Resources