Using aggregate return type to find the sum
Hey there! In this guide, we'll show you how to effortlessly calculate the sum of a specific field using Xano's no-code API. This can be super handy for scenarios like calculating the total interest payments from a list of transactions or finding the combined revenue from multiple orders. Let's dive in!
Step 1: Navigate to the Query All Records Function
First things first, head over to the Query All Records function for the data model you want to work with. This function allows you to fetch and manipulate data from your model.
Step 2: Jump to the Output Tab
Once you're in the Query All Records function, click on the Output tab. This is where the magic happens!
Step 3: Set Up the Aggregation
- In the Output tab, click on the
returnstatement. - Select the
return type aggregateoption. - Click on
add aggregated byand choose the field you want to sum up (e.g.,interest). - Give your new field a name, like
sum of interest. - Under the Aggregator dropdown, select the
sumoption.
Step 4: Save and Run the Query
After making the changes, don't forget to save the query. Then, simply run the function, and voila! You'll see the sum of the specified field displayed in the output.
For example, if you were summing up the interest field, and the values in your database were 5, 10, 15, and 115, the output would show sum of interest: 145.
Just like that, you've harnessed the power of Xano's no-code API to calculate sums without writing a single line of code! Pretty neat, right?
This functionality can be a real time-saver, especially when working with large datasets or complex calculations. Give it a try and see how easily you can crunch those numbers with Xano's visual interface.
Happy summing!
Sign up for Xano.
100,000+ people build on Xano.
Start today and scale to millions.