Trying to sum values from Query JSON with SQL query

I'm trying to sum the values returned from a Query JSON with SQL query, but getting only zero as the result. Here's my code:
select sum(availableRenewal) from {{ => parseInt(i.availableRenewal))}}

In the watcher I can see that the JSON object is populated with the right data in the right type (ints not strings). Any ideas? Thanks.

Hey @sfbrophy, good to hear from you again :slight_smile:

We should be able to get this figured out. Can you send over a screenshot of the values of the relevant properties in the property inspector?

We were able to get this sorted out by moving the data type conversion around:

select SUM(CAST(availableRenewal AS NUMBER)) 
from {{ }}

Hello here,
I think I have a similar issue on my retool.
Here is the values I would like to sum.
Capture d’écran 2021-04-20 à 23.48.57
shootingItems is a Postgresql query.

I would be very happy to have an answer from you,

I found a solution using something like this #lodash
Hope this will help someone :slight_smile:

1 Like

Hi Justin,
How to get a sum of column values to show in the statistics component. I have a table column name "Inc Fee" in which string values like "$1500". I need to show the sum of all of that column. Please help me get out of it.

Hey @SalmanMaqbool! You'll need to:

  1. Remove the $ from the string
  2. Then convert it to a number

The syntax depends on what database you're using.

I am importing data from google sheets. If I remove $ sign and get data in numbers then how to sum all the fields of a column? Any casting require from string to number or maping to sum all column values?

@SalmanMaqbool could you share more details on what the column looks like / a screenshot? If you're using Query JSON with SQL then a simple SUM(column_name should do it.

See this image

. I have data from google sheet not from json or SQL query. Its simple google sheet data with some columns having number and I want to get sum of a specific column. Look I have tried {{_.sum(['7'])}}. But is saying that is requires string and you are providing numbers. ['7'] presents the column "Expected views".