I have one calculated column and I want to display the sum of all its values but I know that's impossible in a OOTB way. How can I copy all the values to a new column (type number)? Do I need to use JavaScript?
ps: I'm using SharePoint on-line
I can't paste the whole page with detailed instructions
But you can get this:
By wacking some HTML & JavaScript in a Calculated Column.
Not suggested for large volume lists, but fine for Views that fit in your display.
Takes 9 steps and some 15 minutes (or 2 if you just copy/paste the last step)
See: http://www.viewmaster365.com/#/Create/Sum
SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {
function sumColumn(columnName){
var rows=ctx.ListData.Row; // global ctx!!
var sum=rows.reduce(function(sums,item){ // loop over all Array items
var value=item[columnName];
return sums + (value ? Number(value) : 0); // calculate sums, does not take care of strings!
},0); // sums starts at 0
var id="Sum"+columnName; // unique id so multiple columns can be summed
var sumDIV=document.getElementById(id);
if(!sumDIV){ // if no Sum div exist
sumDIV=document.createElement('DIV');
sumDIV.id=id;
// find column
var header=document.querySelector("[id*='thead-WPQ1'] div[name='"+columnName+"']");
header.appendChild(sumDIV);
}
sumDIV.innerHTML=String.format("<B>Sum: {0}</B>",sum);
}
function init() {
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
Templates: {},
OnPostRender: function(ctx) {
sumColumn('MonthSpan'); // USE INTERNAL FIELD NAME!
},
});
}
RegisterModuleInit(SPClientTemplates.Utility.ReplaceUrlTokens("~siteCollection/Style Library/sumcalculated.js"), init);
init();
});
If you only need to see it there's a quick and easy way with no prog languages.
Because I see the objective is to "display" the sum of all calculated volume.
1) Go to [modify view], expand [totals]. Select "sum" for the column that you want the sum to be displayed.
The sum will be on display in your main list/library.
2) If you need a breakdown of "sum" into 'sub-sum's based on other columns, you can do so too. Go to [modify view], expand [group by]. Select the column(s) you want to create subgroup with. The total sum will be on display in your main list/library; and a 'sub-sum' will be displayed for each of the groups.