2 Replies Latest reply on Oct 1, 2013 9:23 AM by PM1887

Sum of related values in a table

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. Re: Sum of related values in a table

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

• 2. Re: Sum of related values in a table

Thanks very much.  That worked perfectly.