GAS novice here, but enjoying it.
Here is a data sample in a Google Sheet called "Sheet1".
I have a Google Script that formats this data, creates a new sheet called "totals by account" that sets "A1" to the formula: =QUERY(Sheet1!A:J,'select E, sum(J) group by E',0)"
This all works well, but the cell/Query gives a "Forumla parse error" message. I've seen this Query work before, but it doesn't seem to be consistent. I formatted column J to a number and "0.00" (DATA_SHEET.getRange("J1:J1000").setNumberFormat("0.00");)
Thank you for your help!
Try replacing quotes with double quotes in the query :
=QUERY(Sheet1!A:J,"select E, sum(J) group by E",0)
Related
I know this has been asked several times, but I just can't seem to understand how to write the formula and I'm hoping to get some help.
Consider the following (example data) sheet:
https://docs.google.com/spreadsheets/d/1t_I_stZmZea4sfGPsCu6GtBhGJJT16CZ-sEu7JubFKc/edit?usp=sharing
First, note that I am importing data on "API Data" utilizing importJSON().
My goal is to combine (join) data from two sheets. I need "dataseries cloudcover" from 'API data' and "Dataseries example,Dataseries example 1,Dataseries example 2" from 'join'.
I gave it a shot here:
=query('API data'!A:L,"Select " & vlookup(B:B,'API data'!B:L,3,FALSE) & ",B,C,D,E,F,G,H,I,J,K,L")
Here is a SS of what I would like to see
This formula can help you to get that data:
Note: Just add the formula in A2
={ARRAYFORMULA(IF(ISBLANK('API data'!C2:C),"",ARRAYFORMULA(VLOOKUP('API data'!C2:C,'API data'!C2:D25,2)))),ARRAYFORMULA(IF(ISBLANK(Join!A2:A),"",ARRAYFORMULA(VLOOKUP(Join!A2:A,Join!A2:D25,{2,3,4},FALSE))))}
And it will look like this:
Edit:
Editing and adding more information about the use of this formula.
The formula is constructed with 2 different VLookUps, 1 for each tab, and they are merged using:
={First Array, Second Array}
The first Array is:
ARRAYFORMULA(IF(ISBLANK('API data'!K2:K),"",ARRAYFORMULA(VLOOKUP('API data'!K2:K,'API data'!K2:L25,2))))
The second Array is:
ARRAYFORMULA(IF(ISBLANK(Join!I2:I),"",ARRAYFORMULA(VLOOKUP(Join!I2:I,Join!I2:L25,{2,3,4},FALSE))))
The core part of the first array for this formula is:
ARRAYFORMULA(VLOOKUP('API data'!K2:K,'API data'!K2:L25,2))
The IF(IsBlank(column,"",Vlookup) will remove any empty value of the Array.
The same thing with the second Array, with the difference that I use an Array {2,3,4} to call all the columns in the second sheet.
Reference:
VLOOKUP function.
ARRAYFORMULA function.
IF function.
ISBLANK function.
I have these 2 columns in my sheet: A and B.
A contains dates in format day.month.year. B contains hours in format hh:mm. I usually concatenate the values of these 2 columns by using this formula:
=concatenate((text(A3;"mm.dd.yyyy")&" "&text(B3;"hh:mm")))
I use the same formula to concatenate the values of 2 other cells: C (filled with dates!) and D (filled with hours!). The exact formula in this case is:
=concatenate((text(C3;"mm.dd.yyyy")&" "&text(D3;"hh:mm")))
The whole purpose of this little exercise is to get the dates and hours in the format that is required to create events in my Google Calendar. I am currently using it in my calendar event creation script with the method setFormulaR1C1(formula), but I am not sure if that´s a really good idea. So, please tell me:
How would an apps script equivalent of my formula look like?
And is there a way to write that apps script equivalent of my formula as a callback function?
Thank you so much in advance!
How would an apps script equivalent of my formula look like?
Given that the cells already display the date and time in the format you need, you can simply use this:
const sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
const datetimeString =
sheet.getRange('A3').getDisplayValue()
+ ' '
+ sheet.getRange('B3').getDisplayValue();
If the cells do not display the date and time in the required format, you will need to use Utilities.formatDate() and Spreadsheet.getSpreadsheetTimeZone(). There are some complications when interpreting spreadsheet time values in Apps Script. Refer to the recipe at Google Script when taking time from sheets adds +1 minute to avoid surprises.
To get the same with a spreadsheet formula more easily, use this:
=trim(A3) & " " & trim(B3)
I'll start by saying that my knowledge on using APIs is extremely limited. I'm impressed I've gotten as far as I have on this.
I've created a workbook in Google Sheets with imported data from the iexcloud API, which I'm using for data on stocks.
The requests have a cell reference in them so they update whenever a different symbol is selected.
So far, everything I've needed to request from it has the option to format as csv, so I can get cells with just the values.
However, this last thing I want doesn't have that option, so the whole response is wrapped in ["" ].
That really messes up what I need it for.
Here's an example
["PSA" CCI SHO ACC]
with each symbol being in its own cell.
I'm using the Peer Groups request.
A sample request:
> https://sandbox.iexapis.com/stable/stock/aapl/peers?token=Tsk_2b4c7c6fd98542f6a99f904cb7a3e721
Using Find and Replace doesn't work. I'm assuming because it's imported.
I need to use the cells with those symbols: PSA, CCI, SHO, ACC to reference in another request.
I recreated this in another Google Sheet that you can edit. The section in question in highlighted in blue
https://docs.google.com/spreadsheets/d/1BQ6FBD0S2YkDtDGZGIkDmQoKrQT4VmVDjuNsgV4mrXM/edit?usp=sharing
So I'm wondering if there's a way to have [ " ] automatically removed from any cells in that row, or if I copy and paste the values only, to have the values updated when the original cells are updated with new symbols (since I can have those characters removed in that row)
Or if there's a way I can format the response in sheets.
Any ideas?
I believe your goal as follows.
You want to achieve from ["CCI" SBAC CTL TDS RCI RCI-A-CT DTEGY] to CCI SBAC CTL TDS RCI RCI-A-CT DTEGY using the built-in functions of Google Spreadsheet.
Modified formula:
=ARRAYFORMULA(REGEXREPLACE(IMPORTDATA("https://cloud.iexapis.com/stable/stock/"&B3&"/peers?format=psv&token=###"),"[\[\]""]",""))
In this modified formula, [, ] and " are removed using REGEXREPLACE.
Please replace ### with your token at the above formula.
Result:
In this result, the values retrieved with =IMPORTDATA("https://cloud.iexapis.com/stable/stock/"&B3&"/peers?format=psv&token=###") are used. So the formula of cell "C9" is =ARRAYFORMULA(REGEXREPLACE(C6:I6,"[\[\]""]","")). But in this case, above modified formula can be used.
Note:
In this answer, I removed your token because I thought that it is your personal information.
Reference:
REGEXREPLACE
In Google Sheets, I have a formula in a cell that connects to an API with a script and spits out the JSON results. For example, I can connect to the Youtube API with a formula that looks like this,
=ImportJSON("https://www.googleapis.com/youtube/v3/videos?id=mv-cj6mBkPk&key=API KEY&fields=items(id,snippet(channelId,title,categoryId),statistics)&part=snippet,statistics")
I'd like to make part of that formula get it's value from a separate cell. For example, the video ID above (mv-cj6mBkPk), rather than have it typed in the above formula, I'd like to pull in the value from a cell (i.e. B1). Then I can create multiple versions of this formula with other video IDs (i.e B2, B3, etc.)
I've tried combining various parts of the formula through CONCATENATE-ing a few cells, but that doesn't seem to 'RUN' the formula, it just shows it.
My skills aren't so advanced in this area, so any help would be great. Thanks!!
It is not obvious what your problem is exactly, or where you got the code for the ImportJSON() function (as this is not a built-in function),
but a variation of the below SHOULD work - if it does not, then post what error you are getting (exactly).
Also, I presume you have substituted "API KEY" for the actual key... I have used API_KEY, so that the formula does not get broken across multiple lines here.
A1 : mv-cj6mBkPk
A2 : =ImportJSON("https://www.googleapis.com/youtube/v3/videos?id="&A1&"&key=API_KEY&fields=items(id,snippet(channelId,title,categoryId),statistics)&part=snippet,statistics")
I am using this link to return JSON data, but it is not working now. It shows a "Invalid query parameter value for grid_id" error. Any ideas? Thanks.
https://spreadsheets.google.com/feeds/list/1fe--KCLag0QNEuYqSeBU2HPZLUoyvicxYfoONnglx-k/821619139/public/values?alt=json
reference link
Google Spreadsheets retrieving JSON feed
Something recently changed in how google assigns the codes for each worksheet. For me, the key was to change the first worksheet from "0" to "od6".
The way to look them up is to use https://spreadsheets.google.com/feeds/worksheets/YOUR-SPREADSHEET_ID_HERE/public/basic. If I do that with your spreadsheet (https://spreadsheets.google.com/feeds/worksheets/1fe--KCLag0QNEuYqSeBU2HPZLUoyvicxYfoONnglx-k/public/basic), I see that the only worksheet id listed is "odl6521" - "821619139" no longer exists. But if I go to https://spreadsheets.google.com/feeds/list/1fe--KCLag0QNEuYqSeBU2HPZLUoyvicxYfoONnglx-k/odl6521/public/values?alt=json , I get out a json file that looks to be what you want.
Hope that helps!