Expand my Community achievements bar.

Sum Column to decimal field

Avatar

Former Community Member

I know there are several variations of this question floating around, but I haven't found an answer that has solved my issue, so I hoping someone out there can offer up some assistance.

I have created a dynamic table using ES2. This table is a parts cost form (qty x of part y equals z dollars) I have a "add row" button which, go figure, adds a row when the user clicks it.

Now, I have a separate table set up to do some additional calcuations (hours to repair times hourly repair rate equals total labor cost, plus materials cost, equals total repair cost)

What i have accomplished so far is:

- The individual part costs caculate across in the first table, so that the right-most column shows the piece-part totals for each needed part.

- I have the second table doing the calculations for labor time x labor rate, equaling total labor cost

- I have the total cost of the first part listed in table one showing in the total material cost field

- i have the total labor plus the total material cost showing in the repair total field.

Here's my issue:

I need the total material cost field (located in the second table) to show the sum of all the parts listed in the first table. How do I script this? Keep in mind, the first table is dynamic, so it won't always have the same number of rows (parts). Is there a script that allows you to say "sum of all in this column"? Also, there is no column header, the top cell is the first price value.

Is this possible? Or am I wasting my time?

Anybody that has any knowledge of how to do this, please help.

3 Replies

Avatar

Former Community Member

It is possible but it is much easier to do using FormCalc than Javascript. There is a Sum function where you can pass an expression to sum. So if your Tabel 1 was structured as Table1.Row.Total, then each row woudl have a total that woudl be in this format Table1.Row[0].Total, Table1.Row[1].Total, Table1.Row[2].Total ....etc. So when you want to get a sum from Table 2 you woudl use the expression Sum(Table1.Total[*].Total.rawValue).

Hope that helps

paul

Avatar

Former Community Member

Paul,

Thanks for the response. I'm not quite sure how to implement this in my form though, my table looks like this:

PRIMARY PART NAMEPART NUMBERSQTYUNIT PRICEEXT. PRICE
ADDITIONAL PARTS REQUIRED

All my data is going into what is shown as the skinny columns. So the values i'm trying to add aer what would be shown in the right-most column. There is no column heading or anything like that, so I don't know what I would call out in the scripting, but I want the sum of all numbes entered in this column to calculate into a single cell on a second table. And this first table will grow to fit all parts needed for a necessary repair, it will not be fixed. Can Javascript or FormCalc do this?

Avatar

Level 10

A sample Scenario..

In the blank field at the end on Right, with out the column heading in your screen shot, above, let's call it as NumericField1. (You need to place a field in that column to hold the value).

So while refering to this field, you can use Table1.Row1.NumericField1..Where Table1 is table and Row1 is set to Repeat for each Data Item.

In the calculate event of the field in Table2 (where you want to display the total) place the below code in FormCalc language..

$.rawValue = Table1.Row1[*].NumericField1.rawValue;

Here is sample with the similar functionality..

https://acrobat.com/#d=01n8nsl1Nm756xAii6NBlA

Thanks

Srini