I'm trying to use aggregate functions in my CAML query specifically the SUM function.
I have a list that has a UserName column and an Amount column. I'm using SPServices to pull the list into a CEWP which I can do with no problem however I need to group the items by UserName and sum the Amount column for each user.
At the moment I'm stuck trying to SUM the Amount column. I simplified the sample below. I'm only pulling Amount column but cannot get it to sum. The CAML query is showing all items on the list without summing.
I have a list that has a UserName column and an Amount column. I'm using SPServices to pull the list into a CEWP which I can do with no problem however I need to group the items by UserName and sum the Amount column for each user.
At the moment I'm stuck trying to SUM the Amount column. I simplified the sample below. I'm only pulling Amount column but cannot get it to sum. The CAML query is showing all items on the list without summing.
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$().SPServices({
operation: "GetListItems",
async: false,
listName: "SampleList",
CAMLViewFields: "<ViewFields><FieldRef Name='Amount' Type='SUM'/></ViewFields>",
CAMLQuery: "<Query><Aggregations Value='Number'><FieldRef Name='Amount' Type='SUM'/></Aggregations></Query>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var varAmount = "<div>" + $(this).attr("ows_Amount") + "</div>";
$("#calAmount").append(varAmount);
});
}
});
});
</script>
<div>
<div id="calAmount" style="float:left; padding:5px;"></div>
</div>
Can someone help me out?