Sum up values from number-fields in collection

Hi there,

I have a collection with a number field.
The numbers vary between 10 and 300.000

I’d like to add up all numbers and show this number somewhere.
Possibility is that i have to use pagination to show the entire collection, so i think i can’t use jquery.

Is there another way to display all summed up values from one (number)fiels of an entire collection?

2 Likes

Why is it that no-one has a simple answer to a simple sum function?
I can’t be the only one with this request.

As seen in other questions here, there is some progress being made here: Math using CMS fields - #9 by anthonysalamin
But i need more examples/methods things to calculate.

Hey @icexuick,
This would require custom code. Check this thread here: Calculate and return values based on user input from Webflow form - #11 by Mitchell_Joseph as it looks like @pepperclip and @Mitchell_Joseph solved it.

Thx. I have asked there. But this is all a bit too little ‘no-code’ for me.
I have done some slight tweaks in JS, but i can’t build my own arrays of collection items… (yet).

I could also do a workaround through Airtable for example, and calc the amount there in a separate table/col with their “rollup” feature, and put that back into webflow in a separate collection & item.

But that would require me to automate all this, which i think is overkill for just a simple “sum” thing.

Yeah, I feel your frustration… Webflow’s system is so powerful yet you quickly hit limits that feel like they should have been removed 20 years ago. There are quite a few example like that, but nonetheless there often are workarounds (especially thanks to the community). Hopefully you’ll manage to get this issue solved, but I can’t help you further unfortunately as I’m no dev either (hence why I feel your frustration perfectly :sweat_smile: ).

1 Like

This worked for me.

Include this jq script to your header.

https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js

var items = $(‘.crew-count’),
itemTotal = $(‘.crew-total’),
sum = 0;

$.each(items, function(value) {
var itemValue = parseFloat(items[value].innerHTML);
sum += !isNaN(itemValue) ? itemValue : 0;
});

itemTotal.html(sum);

We ran into this issue with a customer project also. We were able to solve it with a simple fix by adding a little code that will allow you to add multiple numbers inputs together.

Please see this tutorial video, it walks you through the issue, as well as step by step on how to solve it!

If anyone has any questions please feel free to tag me!

Happy Thursday!