Usually the sum value for a list occurs at the top as in the image below.
Is there any way we can display it in some textbox or label?
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityNote:
in June 2017, Microsoft disabled the use of JavaScript in a Calculated Column
That means given answers may not apply for newer SharePoint versions
For long explanation and work arounds see:
June 13th 2017 Microsoft blocked handling HTML markup in SharePoint calculated fields - how to get the same functionality back
In 2013 its best to apply CSR with a JSLink, but this method has some drawbacks like having to set the JSLink for every View, and not being able to (easily) have multiple Views on one page.
In SP2010 I used these steps to Sum a Calculated Column (which can not be done with a View Total)
It uses Javascript in a Calculated Column to do the math while the page is loading.
The complete Formula is:
(remember to set the datatype to Number)
="<div style=""color:"
& IF( [Rate]<[Buy] ,"red","green")
& """>"
& DOLLAR( [Qty]*[Rate] )
& "</div>"
& "<div class=""vmSums"" style=""display:none;font-weight:bold;border-top:1px solid black;""></div>"
& "<img src=""/_layouts/images/blank.gif"" onload=""{"
&"var TBODY=this;while(TBODY.tagName!='TBODY'){TBODY=TBODY.parentNode}"
& ",dataSum='data-vmSum',dataCnt='data-vmCount',total=value="
& [Qty]*[Rate]
& ",count=0;"
& "if(TBODY.getAttribute(dataSum)){"
& "total=parseFloat(TBODY.getAttribute(dataSum))+value;"
& "count=~~TBODY.getAttribute(dataCnt)+1}"
& "TBODY.setAttribute(dataSum,Number(Math.round(total+'e2')+'e-2').toFixed(2));"
& "TBODY.setAttribute(dataCnt,count);"
& "window.clearTimeout(window.vmSumFunc);"
& "window.vmSumFunc=window.setTimeout((function(){"
& "var lastrow=~~TBODY.getAttribute(dataCnt),"
& "el=document.getElementsByClassName('vmSums').item(lastrow);"
& "el.textContent='$'+parseFloat(TBODY.getAttribute(dataSum)).toFixed(2);"
& "el.style.display='block';"
& "}), 100)"
& "}"">"
Some things to note:
###CalcMaster Bookmarklet to edit Formulas It is a PITA to debug Calculated Columns. Because you don't get feedback until you save a Formula and you end up having to click multiple times to get back to your Formula.
I have written a small 'CalcMaster' bookmarklet which hooks into the formula-editor and does a save of the Formula on every keypress; giving immediate feedback.
Recently published a first version on GitHub:
https://github.com/Danny-Engelman/CalcMaster
ICC
You can use JSLink in View form and create textbox dynamically and display sum value in that textbox using JQuery or you can dynamically calculate value using JQuery and display in textbox created by Jquery and place it anywhere you want.
You can use the below small code..
<script src="https://code.jquery.com/jquery-3.2.1.min.js"> </script>
<script type="text/javascript">
$(document).ready(function(){
var sumValue=0;
var listUrl = _spPageContextInfo.webServerRelativeUrl;
$.ajax({
url: listUrl+"/_api/web/lists/getbytitle('TeamAutoPopulate')/items?$Select=Total", // site url goes here
type: "GET",
headers: {
"Accept": "application/json;odata=verbose"
},
success: function(data, textStatus, xhr) {
$.each(data.d.results, function(index, item) {
// alert("The items in list are : " + item.Total);
sumValue=sumValue + parseFloat(item.Total);
})
// alert("The Sum value is : " +sumValue);
$("#aggrWPQ2 .ms-vb2").next().next().next().next().next().next().next().next().text("Sum= "+sumValue).css({ 'font-weight': 'bold' });
},
error: function r(xhr, textStatus, errorThrown) {
alert("error:" + JSON.stringify(xhr));
}
});
});
</script>