Add up fields from large table
Hello Xano experts,
I've got a table with many records and each record contains many integer fields. I need to sum up the same fields for all records. So the output has one record of sums for all fields: field_1_sum, field_2_sum, ... field_500_sum.
Adding up through the loop doesn't look feasible. Is there a more elegant way of doing that, e.g. by transforming the objects into arrays and doing "sum" filter for arrays?
Thanks!
Denis
Best Answers
-
hi @Denis Vasiliev - I'd actually recommend trying this through the query all records function, it has an aggregate return type. You could aggregate on each field that you need summed up and use a sum aggregator.
-
Great!!
Answers
-
@Michael Udinski thank you very much! It helped a lot
-
@Michael Udinski is it possible to do this and aggregate two different fields from the same table and return those sums in the same query? Or would I need to set up a 2nd call and aggregate that return by the 2nd field.
-
@jackb excellent question. Yes, this is possible by use of evals. You can create a new field that combines the two separate fields by selecting one and using the add filter with the other. This field then becomes available as an aggregate. Here's an example:
https://www.loom.com/share/7c6a7a17fa414e8f86c80311cf0124c0?sid=7d27babb-e8df-4376-a54a-e9d255a6180b
-
@Michael Udinski thanks Michael. Much appreciated, that makes sense.
-
@Michael Udinski Hi Michael, thanks for a tip. Yet, I fail to replicate your example. I create a new variable "combo" at the Aggregate output. But it doesn't show up in the Evals list of variables. Any ideas why this can happen?
Thanks!
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback