Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Sum of related values in a table

Avatar

Level 1

Forgive me...  I'm a total newby at livecycle.  I have a dynamic table where the user starts out with only one row for information, but can add rows as needed  (add instance) to list more buildings.  Among other things, they must indicate the location of the building (from a drop down menu - ie. there is a binding value for each location) and an amount representing the insurable value of the building.

LocationAmount
LC1$ 100,000
LC1$ 125,000
LC1$ 100,000
LC2$ 150,000
LC2$ 130,000
LC3$ 200,000
LC3$ 175,000
LC3$ 100,000

In a totally different subform I can generate the grand total quite nicely using formcalc:    sum (Buildings.Row4[*].Amount[*])

But how would I generate a sum for each location?  In other words, use the location as the criteria for amounts that get lumped together.

1 Accepted Solution

Avatar

Correct answer by
Level 10

You can use a for loop to do this.

This example sums all locations named LC3.

var s = 0

for i=0 upto Buildings._Row.count -1 do

     if (Buildings.Row[i].Location eq "LC3") then

          s = sum(s, Buildings.Row[i].Amount)

     endif

endfor

$ = s

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

You can use a for loop to do this.

This example sums all locations named LC3.

var s = 0

for i=0 upto Buildings._Row.count -1 do

     if (Buildings.Row[i].Location eq "LC3") then

          s = sum(s, Buildings.Row[i].Amount)

     endif

endfor

$ = s

Avatar

Level 1

Thanks very much.  That worked perfectly.