I'm new to Sheets and the query function as of last night, so don't know the terminology etc - sorry!
I have two workbooks, a master and a template. I need the templete to pull specific data from the master when Col2 matches a particular number. I have it working great if i manually input the number, but don't want to have to do this everytime I give a copy of the template to a new job. This number in Col2 is unique to each of the templates I give to a new job, and the number will already be manually input into cell J16 of the template. I want the code to pull the number from J16 and search rather than me telling it what the number is everytime. The code I have that works with the manual input number, in this case 4032 is below. Thanks in advance for any help.
Vince.
=QUERY(IMPORTRANGE("1yTp3SajbKovHf_Wjx7CHO9FsIPeQGvmdMytQIkr9gog","Invoices"),"select Col1, Col5, Col11 where Col2 = 4032")
Do you want to get the number (any) from J16 into your query?
Use:
=QUERY(IMPORTRANGE("file_id","Invoices"),"select Col1, Col5, Col11 where Col2 = " & J16)
or better:
=QUERY(IMPORTRANGE("file_id","Invoices"),a1)
where a1 is:
="select Col1, Col5, Col11 where Col2 = " & J16
Related
I have a form connected to Google Sheets which is populating a dynamic matrix into a single column per row for a customer claim. E.g. one customer claim by PO number for a number of products (containing SKU name, article number, UoM, quantity)
enter image description here
I want to split out each item by customer, PO number and reason for claim (see desired outcome tab in spreadsheet) like this
enter image description here
https://docs.google.com/spreadsheets/d/1NeVdCVA0oayx1D3UC8WBxv4SJtrZiTyOf2v3zpnN2Sc/edit#gid=219062088
The formula I am trying to use split the products removing the text before is
=(IFERROR(ArrayFormula(((REGEXEXTRACT(F2,": (.+)"))SPLIT(E2:E, ",")), " ")))
I still haven't worked out how transpose into a new table format. Any help much appreciated :)
In the sheet 'JPV Help' I entered
=ArrayFormula(query(split(regexreplace(flatten(iferror('Product Breakdown'!A2:A&"/ "&substitute('Product Breakdown'!B2:B, "po",)&"/ "&'Product Breakdown'!C2:C&"/ "&split('Product Breakdown'!D2:D, char(10)))), "(,)(\s[A-Z]\w+\:)", "/$2"),"/:"), "Select Col1, Col2, Col3, Col5, Col6, Col8, Col10 where Col5 <>''"))
See if that works for you?
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.)
When I import data, it comes in this format (image 1), with blank spaces. I would like to know if there is any way to adjust so that these blanks disappear, the two models expected (image 2 and 3) if there was any way to reach them would be important to me.
Remembering that all dates have / and all times have :
I tried to filter from QUERY, but when trying to "Select Col1, Col2, Col4 Where Col2 is not null" the dates disappear and only the times remain, I tried via REGEXMATCH to separate the dates from the times using / and : but also I was not successful.
I also tried it via IMPORTXML, but some data ends up not being imported correctly on some pages of the site, for IMPORTHTML these errors do not happen. The XML's I used were:
"//tr[#class='no-date-repetition-new' and ..//td[#class='team team-a']] | //tr[#class='no-date-repetition-new live-now' and ..//td[#class='team team-a']]"
"//td[#class='team team-a']/a | //td[#class='team team-a strong']/a"
The current formula is as follows:
=IMPORTHTML("https://int.soccerway.com/national/austria/1-liga/20192020/regular-season/r54328/","table",1)
IMPORTHTML Original:
Expected formats:
---
Rather than filtering what you need is to restructure the imported data.
Anyway, I think that the easier solution to get the final result is to use multiple IMPORTXML formulas.
URL
A1: https://int.soccerway.com/national/austria/1-liga/20192020/regular-season/r54328/
Headers
A2: //table[contains(#class,'matches')]/thead/tr/th
Day
A3: //td[contains(#class,'date')]/parent::tr
Teams and Score
A4: //td[contains(#class,'team-a')]/parent::tr
A6: =transpose(IMPORTXML($A$1,A2))
A7: =IMPORTXML($A$1,A3)
B7: =IMPORTXML(A1,A4)
You might want to replace the formula on A6 by static values in order to place them properly.
You can join 2 queries together (one next to the other) in a single formula, to get your results
={QUERY(IMPORTHTML("https://int.soccerway.com/national/austria/1-liga/20192020/regular-season/r54328/","table",1),
"select Col1 where Col2 is null and not Col1 contains '*'",1),
QUERY(IMPORTHTML("https://int.soccerway.com/national/austria/1-liga/20192020/regular-season/r54328/","table",1),
"select Col1, Col2, Col3, Col4 where Col2 is not null label Col1 'Time'",1)}
How the formula works:
As you notice the data part of both queries is the same in both of them. What is actually different is "what we ask for from the query"
In the first one we use "select Col1 where Col2 is null and not Col1 contains '*'"
In the second one "select Col1, Col2, Col3, Col4 where Col2 is not null label Col1 'Time'"
We create an array by joining them together as in ={1stQUERY,2ndQUERY}
In google sheets, I need to query a subset of a table.
The table range is A1:K, where column A is used for filtering.
I want to construct a query that looks like:
=query(A1:K,"Select B,C,D,E,F,G,H,I,J,K where A =x")
except I want it to look more like:
=query(A1:K,"Select B-K where A =x")
Is this possible?
In my case, I also need to be able to do this on averages, so:
=query(A1:K, "Select avg(B-K) where A=x label avg(B-K) ''")
The reason why I want to not spell this out is because this query is being generated dynamically. Is this possible, or must I generate the string for the query seperately?
I think, the only way is to generate the string.
But if you make query like this:
=query({A1:K}, "Select ...")
then A-Z notation becomes Col1, Col2, Col3 and so on. You can take advantage of it:
use this formula to generate text "Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11":
=join(", ",ARRAYFORMULA("Col" & row(OFFSET(A2,,,10))))
And this formula will make text "AVG(Col2), AVG(Col3), AVG(Col4), AVG(Col5), AVG(Col6), AVG(Col7), AVG(Col8), AVG(Col9), AVG(Col10), AVG(Col11)":
=join(", ",ARRAYFORMULA("AVG(Col" & row(OFFSET(A2,,,10))&")") )
Also change A2 and 10 in 2 formulas above to return different number of subsets.
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 != ''")