# Smart functions in Wix Data Query

**URL:** <https://forum.wixstudio.com/t/smart-functions-in-wix-data-query/37605>\
**Category:** Ask the community\
**Tags:** code\
**Created:** [April 22, 2018, 3:34pm UTC](https://forum.wixstudio.com/t/smart-functions-in-wix-data-query/37605 "2018-04-22T15:34:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![andreas-kviby](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/andreas-kviby/32/790_2.png) [@andreas-kviby](https://forum.wixstudio.com/u/andreas-kviby)\
**Post date:** [April 22, 2018, 3:34pm UTC](https://forum.wixstudio.com/t/smart-functions-in-wix-data-query/37605/1 "2018-04-22T15:34:30Z")

</div>

Let’s say I want to sum all orders in my orders Data Collection. Today I need to do this with scripts.

I would like to perform the following in Wix Code.

```javascript
import wixData from 'wix-data';   
wixData.query("Customer") 
.sum("orderAmount") 
.find() 
.then( (results) => {      
    console.log(results.items.sum); 
} );

```

The above query will sum all my orders using the field orderAmount and it will give me the result back in the items.sum result. This would be great.

The next one is about getting the order with highest orderAmount fast.

```javascript
import wixData from 'wix-data';    
wixData.query("Customer") 
.max("orderAmount") 
.find() 
.then( (results) => {           
    console.log(results.items.max); 
} ); 

```

Small things but they would be appreciated.

---

<div class="post-metadata">

**Author:** ![marius](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/marius/32/2849_2.png) [@marius](https://forum.wixstudio.com/u/marius)\
**Post date:** [April 22, 2018, 8:48pm UTC](https://forum.wixstudio.com/t/smart-functions-in-wix-data-query/37605/2 "2018-04-22T20:48:37Z")

</div>

This will be very useful, but I think the ideal would be to have that functionality when connecting/binding a text box to the dataset numeric field - right on the page.  
So when you you select [Text connects to] and you pick a number field, further options should be made available with math functions e.g. sum, min, max , avg etc  
This will be useful when creating a report like order totals etc.

to expand on this idea.

1. The same could be done for other types of fields like date and time
2. Also referring to Andreas’s other idea of adding formulas in the collection field during collection design. How about having that capability on the page itself. e.g. bind the text box to the dataset and use a formula/function to calculate a value (in stead of doing that with a script) just by entering e.g. =sum(“fieldname”) or =“fieldname”\*(“fieldname”+“fieldname”)
