I have retrieved item count for particular field values in my list using CAML Query. But when I try to add up all those counts it's not getting added, infact it is getting appended.

For example, my item count for the values Q1,Q2,Q3 and Q4 are 5 1 0 8 3. When I tried var total=Q1+Q2+Q3+Q4, it is displaying 51083. Can anybody tell whats happening?

  • add your code in question. May be some coding error.
    – P S
    Commented Nov 21, 2015 at 8:09
  • Don' understand correctly. as per your question you are adding strings try to change it to Integer or any appropriate data type.
    – Ankur
    Commented Nov 21, 2015 at 9:30
  • It looks like your problem is a C# syntax one... you're concatenating string variables, and not additionning int variables... Please, share your code so we can better understand your point.
    – Evariste
    Commented Nov 23, 2015 at 6:48
  • are you using C# ? Commented Aug 12, 2016 at 23:19

3 Answers 3


Sample example:

var cnt ;
var a1 ='20'
var b1 ='30'
//Now if you add it, it will append as it is string
cnt = a1 + b1
// you have to parse as int
cnt = parseInt(a1) + parseInt(b1)

Hope it helps!

var total= parseInt(Q1) + parseInt(Q2) + parseInt(Q3) + parseInt(Q4)

Convert your each variable into number/int format using parseInt()


The return count value may be stored as a string variable, so convert that value to integer format by using parseInt( var ) or Number( var ).

Then add the values and get the total for that.

Your Answer

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

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