How do i get the sum of values in a column. ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sujithraalink
    Member
    • Oct 2018
    • 94

    How do i get the sum of values in a column. ?

    I have an entity called "Result" and there is a field "score" in the entity . i want to get the sum of all entries comes in "score" column. and i want to store the total to "grandTotal" field.
    This is the formula i have applied. but it doesn't work.
    grandTotal = entity\sumRelated('Result', 'score');
    Please help me to resolve this issue.
    NB: Entity - Result(Label - Result), Field -score(label -Score), Field - grandTotal(label - Grand Total)
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    You need to have relationship between your entity and Result entity. Check the relationship name in Administration > Entity Manager > Relationships. The name should start with a lower case letter. Then use that name in your formula as the first argument.

    entity\sumRelated('results', 'score');

    Where results is a relation name.



    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • sujithraalink
      Member
      • Oct 2018
      • 94

      #3
      i have corrected this. grandTotal = entity\sumRelated('results', 'score'); but the result doesnt reflect in grandTotal field which is from same entity Result.

      Comment

      • yuri
        Member
        • Mar 2014
        • 8440

        #4
        sumRelated intended to sum related records. If you want to sum for the same entity, the formula won't help. You need to create a hook and write some code.
        If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

        Comment

        • sandra6012
          Member
          • Jul 2018
          • 33

          #5
          From what I understand, your fields are within your own entity?
          If so, then your formula is wrong, I apply a formula for a collection entity:

          "grandTotal=field1+field2;"

          or in case you apply multiplication:

          grandTotal=(field1*field2)+field3;

          And if not then I did not understand your problem.

          Good luck with that problem!

          Comment

          • item
            Active Community Member
            • Mar 2017
            • 1476

            #6
            for one cent if I have understand :
            you need a formula who return "select SUM(score) from result where deleted=0" ?
            If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

            Comment

            Working...