In our workflow we often export results from a query on BigQuery to Google Sheets, e.g. for distribution to customers in .xlsx format.
I'm running into something weird: when explicitly casting the output of a query to numeric, the export in Sheets gives errors in for the decimals.
For example,
select
cast('12.3' as numeric),
cast('12.34' as numeric),
cast(12.056 as numeric),
cast('12.345786' as float64)
Yields the following query result in the WebUI
Row f0_ f1_ f2_ f3_
1 12.3 12.34 12.056 12.345786
However, the result in Google Sheets (again, using the WebUI, option Save to Sheets), is this:
f0_ f1_ f2_ f3_
12.3 1234 12056 12345786
Only pattern I can see is that the decimal sign is erroneously dropped when there are two or more decimals.
I really have no clue what is causing this, let alone how to fix it. Exporting the data to .csv and .json does yield the correct result.
Help, anyone?
Related
Having an issue figuring out a proper Google sheets formula that works
This is my reference sheet
=SUM(IF(AND('Online Arbitrage'!A:A = D5, 'Online Arbitrage'!M:M >=DATE(A2,1,1), 'Online Arbitrage'!M:M <=DATE(A2,12,31), 'Online Arbitrage'!N:N> 0),'Online Arbitrage'!H:H*'Online Arbitrage'!N:N))
I tried this formula in the "Taxes" worksheet and other variants with no success.
I am needing it to pull through the total purchases per supplier from the "Online Arbitrage" sheet based on the year that I have entered into A2.
In this example, I am expecting a result of $2,696.04 and it is producing a result of $0. I've tried other variations of this formula and it produced a result of around $5,700 which was also incorrect.
Try:
=sumproduct(('Online Arbitrage'!$A$4:$A=D5)*('Online Arbitrage'!$M$4:$M>=DATE(A2,1,1))*('Online Arbitrage'!$M$4:$M<=DATE(A2,12,31))*('Online Arbitrage'!$N$4:$N>0)*'Online Arbitrage'!$H$4:$H*'Online Arbitrage'!$N$4:$N)
You generally can't use AND/OR statements in arrays as they aggregate so won't give you the expected result. Instead, use * instead of AND and + instead of OR. I've also limited your ranges to avoid the header cells.
Find 14+ ways to repeat range with formulas.
do it with a small range which has duplicates.
each formula should start from different function.
make formulas as short as you can.
Sample data:
A
B
ðYay!
1
ðWow!
2
ð€£Ah!
3
ð€£Ah!
3
The desired result is the same range, repeated by formulas with the use of built-in functions.
I've created a template sheet with all possible ways I could do it. Is there something I've missed?
there are always more like:
=OFFSET(B3,,,4,2)
=ARRAYFORMULA(IF(,,B3:C6))
=INDEX(IF(,,B3:C6))
=INDIRECT("R3C2:R6C3", )
=INDIRECT(ADDRESS(3, 2)&":"&ADDRESS(6, 3))
or:
=INDEX(VLOOKUP(ROW(B3:B6), {ROW(B3:C6), B3:C6}, {2, 3}, 0))
=INDEX(TEXT(B3:C6, "#"))
={B3:B6, C3:C6}
=INDEX(ARRAY_CONSTRAIN(UNIQUE({B3:C6, ROW(B3:C6)}), 9^9, 2))
further you go it's more questionable why would you do it that way and not the obvious easy way... e.g. one day we would need to do it for example this way due to some specific reasons:
=INDEX(SPLIT(FLATTEN(QUERY(TRANSPOSE(B3:C6),,9^9)), " "))
but not for casual usage tho.
Sample File
Functions to Repeat a Range
These functions can produce a range:
#
Function
Formula Sample
1
{}
={B3:C6}
2
ArrayFormulaâ¡1
=ARRAYFORMULA(B3:C6)
3
INDEXâ¡
=INDEX(B3:C6)
4
FILTERâ¡
=FILTER(B3:C6,ROW(B3:B6))
5
SORTâ¡
=SORT(B3:C6,SEQUENCE(4),1)
6
SORTNâ¡
=SORTN(B3:C6,2^99,0,SEQUENCE(4),1)
7
QUERY
=QUERY(B3:C6)
8
OFFSET
=OFFSET(B3:C6,,)
9
ARRAY_CONSTRAIN
=ARRAY_CONSTRAIN(B3:C6,4,2)
10
TRANSPOSE
=TRANSPOSE(TRANSPOSE(B3:C6))
11
UNIQUE
=UNIQUE(B3:C6,1)
12
INDIRECT
=INDIRECT("B3:C6")
13
IMPORTRANGE
=IMPORTRANGE(SS_ID,"Sheet1!B3:C6")
14
IMPORTDATA
=IMPORTDATA(CSV_URL)
IMPORTHTML
=IMPORTHTML(HTML_URL,"table",1)
IMPORTXML
=IMPORTXML(HTML_URL,"//tr[td]")
1â¡â ArrayFunctions. They convert expression inside into array. Sample: =index(C3:C6*3)
SS_ID
Spreadsheet ID or URL, the first parameter for IMPORTRANGE
For my sample file:
https://docs.google.com/spreadsheets/d/1vP2866RplNvcJz7ZOn-CUqVuspF_ARdBk__QSqpg79E/edit#gid=0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Use the whole URL, or ID: 1vP2866RplNvcJz7ZOn-CUqVuspF_ARdBk__QSqpg79E
CSV_URL and HTML_URL
The IMPORTDATA function requires .csv data source.
IMPORTHTML and IMPORTXML require .html data source.
You may convert your Google Spreadsheet into both:
Go to File > Share > Publish to Web
Select Web Page or Comma Separated Values (.csv)
Select Sheet to import and proceed.
Add range reference to the url: &range=B3:C6
Sample html URL:
https://docs.google.com/spreadsheets/d/e/2PACX-1vQSjBDAV36sy3ua2TSbLEXPsn0_h-_iUCTWKBMgUL2T8TcQt2-1X_vl0GxGlhK04BubF1phiJZQLwJa/pubhtml?gid=0&range=B3:C6&single=true
You may open it like a usual url!
Sample csv URL:
https://docs.google.com/spreadsheets/d/e/2PACX-1vQSjBDAV36sy3ua2TSbLEXPsn0_h-_iUCTWKBMgUL2T8TcQt2-1X_vl0GxGlhK04BubF1phiJZQLwJa/pub?gid=0&range=B3:C6&single=true&output=csv
Other functions
All other cases use the same finctions as descrided to reproduce a range. The first function should be always an ArrayFunction or a function that can reproduce a range.
See also:
RANDARRAY - creates array of random numbers
SEQUENCE - creates a sequence 1,2,3... etc.
FLATTEN - gets an aray and produces the 1-column output
I am using the filter function in a master sheet to grab data from 2 other sheets in google sheets. Both of these sheets go through row M.
When I run the filter functions individually, they both run.
=FILTER('Query Manual'!A2:M,'Query Manual'!A2:A<>"")
=FILTER('Query CSI'!A2:M,'Query CSI'!A2:A<>"")
But when I combine them I get a formula parse error with the #ERROR response.
=(FILTER('Query Manual'!A2:M,'Query Manual'!A2:A<>""), FILTER('Query CSI'!A2:M,'Query CSI'!A2:A<>""))
I'm not sure why I'm getting this error when I put the two together, but individually they each work fine?
={FILTER('Query Manual'!A2:M,'Query Manual'!A2:A<>""); FILTER('Query CSI'!A2:M,'Query CSI'!A2:A<>"")}
Curly Brackets instead of commas. I put on my reading glasses and realized this lol.
The data on the page is delivered as follows:
https://int.soccerway.com/international/europe/uefa-champions-league/20192020/group-stage/r54142/
1 - Below each schedule is a link to the match.
2 - I would like to import all data at once.
3 - The result I seek would be as follows:
4 - Import separately, I can, but as they are separate formulas, it takes a long time, I would like a way to import all at once, for a formula only if it were possible.
5 - The Xpath are:
"//*[#class='date no-repetition']"
"//*[#class='score-time status']/a"
"//*[#class='score-time status']/a/#href"
6 - An important detail, I indicated the 'score-time status' because there are games that appear as 'score-time score' but these cannot be imported.
7 - There is another detail that complicates, the time comes with spaces between the sign of :, so for him I use the =SUBSTITUTE(," ","")
Is there any way to do this that I want?
I've tried using ={;;} to import the data, but can't make calls to more than two =IMPORTXML().
I also tried for =IMPORTHML() but it can't fetch the links from each of the below-hours matches and the date also appears in only one of the games...
How about this answer? I think that there are several answers for your situation. So please think of this as just one of several possible answers.
xpath:
Unfortunately, I couldn't find the xpath for directly retrieving the 3 values in your question. So in this answer, the following xpath are used.
Date: //td[#class='date no-repetition']/span
Time: //td[#class='score-time status']/a/span
URL: //td[#class='score-time status']/a/#href
Sample formula:
=ARRAYFORMULA({IMPORTXML(A1,"//td[#class='date no-repetition']/span"),IMPORTXML(A1,"//td[#class='score-time status']/a/span"),"https://"&IMPORTXML(A1,"//td[#class='score-time status']/a/#href")})
In this formula, the URL of https://int.soccerway.com/international/europe/uefa-champions-league/20192020/group-stage/r54142/ is put to the cell "A1".
Retrieved 3 values are put to the column "A", "B" and "C".
Result:
Note:
In above case, I think that the time zone might be the place when the values are retrieved by IMPORTXML.
If you want to change the timezone to your own Spreadsheet, how about the following sample formula?
=ARRAYFORMULA({IMPORTXML(A1,"//td[#class='date no-repetition']/span/#data-value")/86400+DATE(1970,1,1),IMPORTXML(A1,"//td[#class='date no-repetition']/span/#data-value")/86400+DATE(1970,1,1),"https://"&IMPORTXML(A1,"//td[#class='score-time status']/a/#href")})
In this case, please set the format to the column "A" and "B".
In above formula, the date and time is retrieved the unix time. This value is converted to the serial number. So the converted value can be used as the date and time at Spreadsheet.
References:
IMPORTXML
ARRAYFORMULA
If this was not the direction you want, I apologize.
Is there anywhere where I can find the list google uses when you a-z sort a list with a filter?
EDIT: Image for clarity:
More specifically, I need a character that is discreet; ideally a blank character; that is sorted after the plus sign '+'.
I've made a test. You may see the result in Sample File:
I tried first 3000 chars:
Column A: numbers from 1 to 3000
Column B: char formula: =CHAR(A2)
I sorted the range with filter and got an unexpected result: Google is not using ASCII to sort text.
Also, see sort function works the same way as sort by a filter. But sorting with query gives another result.
When I tried the same experiment in Excel I was confused even more:
=CHAR(A2) gives another result in Excel, it not an ASCII char
sorting range of chars gives different from Sheets result. Please try it yourself to see.