Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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)

  • #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.



    Comment


    • #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


      • #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.

        Comment


        • #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


          • #6
            for one cent if I have understand :
            you need a formula who return "select SUM(score) from result where deleted=0" ?

            Comment

            Working...
            X