Issue with custom field calculation in Google Sheets Pivot Table using Apps Script and Sheets API

54 views
Skip to first unread message

Jason Spanomanolis

unread,
Apr 17, 2023, 12:08:52 PM4/17/23
to Google Apps Script Community
I am using Apps Script in conjunction with the Google Sheets API to create a pivot table in Google Sheets. While I am able to create the pivot table and add values, I am having trouble creating a custom field that calculates the click-through rate (CTR) by dividing the number of link clicks by the number of impressions. When I add the custom field to the pivot table using the following formula:

{ "formula": "=sum('Link clicks')/sum(Impressions)", "name": "CTR", "summarizeFunction": "SUM" }

The custom field is created successfully, but it just outputs the value "0.0" in all cells, instead of the expected CTR values. I have tried updating the formula to reference the column index instead of the header name, as well as removing the summarizeFunction parameter, but the issue persists. Does anyone know why this might be happening, or have any ideas for a solution? Thank you in advance for your help!

Web Dev

unread,
Apr 18, 2023, 8:32:23 PM4/18/23
to Google Apps Script Community
Its difficult to know how those values are read without an example but the first thing that comes to mind is the data type. Are you reading and manipulating strings vs numbers?

Christopher Dongo H.

unread,
Apr 18, 2023, 9:13:49 PM4/18/23
to Google Apps Script Community
Most likely, the data type is not correct or you are inserting the information wrong into the field you are creating. Have you been able to verify if said amount is generated?
Reply all
Reply to author
Forward
0 new messages