0

I have my connector where I'm able to get the spend value within a given time frame (on the request passed to the getData it has the startDate and endDate parameters and the fields with spend, all normal). Now I want a card that shows the average spend per day. That would be a field like

spend / DATE_DIFF(endDate, startDate)

But how do I pass those date values to the formula?

1 Answers1

0

In order to see the average spending amount instead of the total amount, you need to change your aggregation type from "Sum" to "Average".

Please see here the documentation and the Apps Script reference.

ziganotschka
  • 25,866
  • 2
  • 16
  • 33
  • Thank you, but it doesn't apply to my case as the API doesn't return the spend value day by day. Instead it's the whole value for a given time frame. – Francisco Farias Jul 23 '19 at 14:34
  • Do you have some Apps Script code that show how you get your data? If you implement the getData() request as specified here: https://developers.google.com/datastudio/connector/reference#getdata you can set the fields in the request https://developers.google.com/apps-script/reference/data-studio/field and set the aggregationType of the field https://developers.google.com/apps-script/reference/data-studio/field#setAggregation(AggregationType) to AggregationType.AVG – ziganotschka Jul 23 '19 at 16:03
  • Once again, thank you. But the API returns the sum already. Sadly I can't share the code with you as it doesn't belong to me. – Francisco Farias Jul 23 '19 at 18:43
  • It is not easy for me to understand the way you get your data without seeing the code, but if you want to manually set a formula to a field calculate your average value, you can do it with fields.newMetric().setFormula() – ziganotschka Jul 23 '19 at 20:05