Hello, I have the bellow dataset, very simple so far.
No a want to show in a field (whatever the type) on my page, the sum of all values in column "lengte". I really can't figure this out how to do so.
![](https://static.wixstatic.com/media/a27d24_af724f973bd64ff6ab5bd2c4095e07ab~mv2.jpg/v1/fill/w_905,h_242,al_c,q_80,enc_auto/a27d24_af724f973bd64ff6ab5bd2c4095e07ab~mv2.jpg)
Can you please assist?
Many thanks in advance
Important forum update
This forum is migrating to one unified Wix community forum starting July 26th, and will be read-only during the process.
Wishlist Page is the official platform for requesting new features. You can vote, comment, and track the status of the requested features.
let CapitalPoolSum = 0; wixData.aggregate("YourTableName") .sum("lengte") .run() .then( (results) => { if (results.items.length > 0) { CapitalPoolSum = results.items; console.log(CapitalPoolSum); } else { // handle case where no matching items found } } ) .catch( (error) => { let errorMsg = error.message; let code = error.code; } );
Hi,
The code should look look this, please modify it to match your site.
import wixData from 'wix-data'; export function dataset1_beforeInsert(item, context) { console.log(item); wixData.query("sums") .eq("name", "dataset1") .find() .then((results) => { let firstItem = results.items[0]; let toUpdate = {"_id": firstItem._id,"sum":firstItem.sum + item.number, "name": firstItem.name} wixData.update("sums", toUpdate) .then((results) => { let item = results; }) .catch((err) => { let errorMsg = err; }); }) .catch((err) => { let errorMsg = err; }); return item; }
Good luck:)
Would appreciate if you could help me out in the code
Hi,
You can create a new collection called "sums" for example and crate a item named "lengteSum", then you can update its value in a new field everytime you insert an item to the original collection using hooks.
If you need help writing this code we will be happy to help.
Good luck :)