# calculate sum of a field

Posted by john cruze on 30-Mar-2016 00:44

hi,

please suggest how can i sum of the field . let say i have three field and their value are

rating1         3

rating2         2

rating3         3

then how can i find sum of all the rating ( like sum = 8 )  .

thanks.

#### All Replies

Posted by Santosh Patel on 30-Mar-2016 00:49

Create a formula field with return type integer and use the template helper to do summation of rating1 rating2 and rating3.

Posted by Karthikeyan Bhaskaran on 30-Mar-2016 00:49

Hi John, You can make use of the Formula field. From Object Definition > Fields > New Formula Field, set the correct return type, and create a formula to add the fields. Thank you, Karthikeyan

Posted by john cruze on 30-Mar-2016 01:14

Hi ,

here i create a formula field that is

Field Label :   Rating Sum

Return Type  is Integer

and in Formula return type of  Template Helper i am doing  summation

like  return #CALC_SUM.Appraisal( Rating | true );  but i am not getting sum.

and when i debug formula result is like

Parsed Formula :

function wrapper() {

return 1.155912831E9;

}

wrapper();

and Result is :

1155912831

any help?

thanks.

Posted by Manooj Murali on 30-Mar-2016 01:19

Hi -

You should not need a CALC_SUM function in this case. Just get the value of each of these picklist fields by using their tokens, sum them and return. If this is not the case, then please explain your the object's and their relationships in your application for us to assist you further.

Regards.

Posted by Karthikeyan Bhaskaran on 30-Mar-2016 01:21

Hi, The Formula field should look something like: {!num1} {!num2} {!num3}

Posted by john cruze on 30-Mar-2016 01:35

hi ,

i have an object name Appraisal having three field

Rating ( pic list and their value is 1, 2, 3) ,

User (lookup field and relationship of user is "One user can have many Appraisal",

Overall Rating ( where i want to calculate SUM of all rating divide by COUNT of all Rating and result assign into

overall rating per user ).

let say

user 1   rating

2

1

3

--------------------- now overall rating calculated as (2+1+3) / (3) = 2

and same for user2

user 2   rating

3

3

3

--------------------- now overall rating calculated as (3+3+3) / (3) = 3

now what i want to see is

User                  Overall Rating

user1                        2

user2                        3

any help ?

thanks.

Posted by john cruze on 30-Mar-2016 01:46

Hi Manooj.

could you suggest me how to get each value to pic list , sum them and return.

thanks.

Posted by Manooj Murali on 30-Mar-2016 01:49

Hi -

If one user can have multiple appraisals, then I understand that overall rating field on user object should have the value from only one appraisal at any point of time, right?

If that is the case, then you can create a 'overall rating' formula field in the User object in which you can loop over the related appraisal, select the needed appraisal object, get values for rating1, rating2, rating3 fields values, compute average and return.

Regards,

Manooj

Posted by Manooj Murali on 30-Mar-2016 01:52

Something like this :

{!#LOOP_BEGIN.<relationship_name_appraisal>}

avg = (Number({!rating1#code}) + Number({!rating2#code}) + Number({!rating3#code}) ) / 3;

{!#LOOP_END.<relationship_name_Appriasal>}

Regards,

Manooj

Posted by john cruze on 30-Mar-2016 02:28

Hello Manooj,

yes one user have multiple Appraisal like

user1     rating

a                3

a                3

user2      rating

b                 1

b                 3

user1       rating

a                  2

a                  4   and so on ,

so my requirement is that when user create their last appraisal overall rating will be calculated as  sum of all rating of a user (it is not fixed , user can create 2,3,4 or more appraisal as per as required ) divide by count of rating created by user.

like for first user (a) calculated as (3+3+2+4) / (4)

and second user (b) calculated as (1+3) / (2)

thanks.