Sum up a data table column using codeless logic

Hi together,

I have some issues implementing a codeless logic for calculating the SUM of a database column.

Table: “stocks” includes the column “result”. With my logic I’m currently trying to iterate the table and summarize the value (result). The problem is I’m not sure how to use the “Load table objects”-block.

I hope somebody can help me out with that “issue”.

Best Regards
Roman

Hi @Ro_Bu !

“Load Table objects” block uses BackendlessDataQuery uder the hood to load objects from specified table. In your case you should use aggregation function in props to obtain desired result
I recommend you to check our documentation about Codeless Data API - Backendless Codeless Development Guide
Also for better understanding how to build where and having clauses you can check this documentation
Search with the Where Clause - Backendless SDK for JavaScript API Documentation

Regards, Andriy

Hi @Andriy_Konoz

do you have an example how “aggregation function in props to obtain desired result” works with the codeless logic?

BR
Roman

Hi Ro,

What is the name of the column you need to calculate the sum of?

Regards,
Mark

The name is “result”

To obtain avarage value for field in table you can use next construction
image

I have made it as return value of service but you can save this value to your variable instead

Regards, Andriy

Hi Andriy,

I’ve tried to transfer your example into my logic. Seems I still have some issues. Please find my current on click logic here:

Could you please give me further hints what is wrong here.

Regards,
Roman

Hi Roman,

Could you please describe what issues you are having?

Regards,
Mark

Hi Mark,

the current issue is that I’m still not able to sum up my column from the table.
I tried to rebuild the example of Andriy for my case. But this on click event does not work. If I click on my button nothing happen with this logic.

Regards,
Roman

Have you tried running the same query in REST Console in Backendless Console? I recommend starting there first to make sure you get the expected data.

Hello @Ro_Bu ,

if you specify just sum(result) properties, then you’ll receive value in a sum field:

If you would like to receive value in a result field, specify an alias - sum(result) as result:

Regards,
Stanislaw