1

Is it possible to get the total count of items within a column on another column in the same list using calculated column formula?

I researched a lot cant find any calculated column formula that would provide the sum of the all numeric value within a single column.

example:

column 1
1
5
8
2
3
6

Looking for a formula that would show the total using calculated column, as I want reuse the total value for further calculation and using CSR it will only display the value but not sure how i can use in a new column to perform additional calculations.

3 Answers 3

3
        OnPostRender: function (ctx) {
            var rows = ctx.ListData.Row;
            var sum = 0;
            for (var i = 0; i < rows.length; i++) {
                var value = rows[i]["FieldInternalName"];
                sum = +sum + +value;
            }
            alert(sum);
        }

Can be condensed to:

        OnPostRender: function (ctx) {
            var sum = 0;
            ctx.ListData.Row.forEach(function(row){
                sum += row["FieldInternalName"];
            });
            console.info(sum);
        }

You can then use JSOM or REST to write the value to another Field

0

I'm not 100% clear what you're asking, but if I've interpreted you correctly, you should be able to add separate column values together (i.e. =([Column 1] + [Column 2] + [Column 3]) etc.). You may have to convert to a numeric value if they are "Single Lin of Text" columns, and also check for empty values as well in this scenario.

If you're looking to add the values contained in a single column, I'm not sure that is possible in SP2010 or older. If this is SP2013 or SharePoint Online you can probably achieve it through the use of JavaScript and the JSLink property to create your own customised column but this will require development effort to achieve.

Hope this helps.

1
  • First of all thanks for responding. CSR will show the total, but I want the data to feed as a field value in a column. Reason: Need to then perform further calculation against the field value with the other fields on the same list. I was looking at calculated column, but doesnt has any option to do a sum for value only in a column. So do you have any suggestion, wherein I want to show the percentage of items completed by having the count of the column that has the value completed and divide it against the total of items in the list.
    – Jason
    Jun 17, 2016 at 7:35
0

You may use client side rendering OnPostRender to sum up all the values of a particular column. Use the below code.

(function () {
    var option = {
        OnPostRender: function (ctx) {
            var rows = ctx.ListData.Row;
            var sum = 0;
            for (var i = 0; i < rows.length; i++) {

                var value = rows[i]["FieldInternalName"];
                sum = +sum + +value;
            }
            alert(sum);
        }
    }
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(option);
})();
7
  • Can the value derived using CSR be copied using jquery to a column?
    – Jason
    Jun 17, 2016 at 9:17
  • The code i have posted is already implemented in CSR only. So i dont think it will be a problem for you to retrieve the value. Jun 17, 2016 at 9:18
  • Also csr solution would require jslink. If yes, can it be exported to be part if a site template?
    – Jason
    Jun 17, 2016 at 9:18
  • Yes it will. You are going to upload a JS file to some library and reference it in JSLink part of the webpart. So when you save site as template, all your library and webparts will also be present. So dont worry, it will work. Jun 17, 2016 at 9:24
  • Go through the link and get to know what gets saved and what doesnot when saving a site template. support.office.com/en-us/article/… Jun 17, 2016 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.