Skip to main content
MzKinn
Participating Frequently
August 13, 2020
Answered

Form Calculation: add a code to multiply a summed column

  • August 13, 2020
  • 2 replies
  • 5663 views

I am hoping to get help with a calculation to multiply a summed total by a fixed amount.  The example is on a timesheet which totals the stipend for all staff .  I would like to take the "project total field" and multiply it by .144 to calculate the cost of benefits plus wages.  I was able to figure out the sum of the stipend but I cannot figure out how to multiply the stipend total.

Thanks in advance for any help!!

 

This topic has been closed for replies.
Correct answer ls_rbls

When you say is not working what results are you getting?  Is the Project Total field completely blank or is it throwing the wrong numbers?


Share an example of how you named those fields.

 

That is why I specified in my initial reply about prefixing and suffixing.

 

If you've employed a field name that prefix a name like this : "Stipends.1" (without the quotes, of course)  then you can't use this field name in the Simplified field notation. 

 

Spaces, periods, underscores, dashes (or any other special characters that you've used for a field name) must be escaped with a back slash ( \ ) when you use Simplified Field Notation.

 

For example :  Stipends\.1 + Stipends\.2

 

If your field names are prefixed, and you want to  use Simplified Field Notation, then  you need to phrase it like this:

 

Stipends\.1 + Stipends\.2 + Stipends\.3 + Stipends\.4 + Stipends\.5 + Stipends\.6 + Stipends\.7 + Stipends\.8) +((Stipends\.1 + Stipends\.2 + Stipends\.3 + Stipends\.4 + Stipends\.5 + Stipends\.6 + Stipends\.7 + Stipends\.8) +)*.144) 

 

Now, be advised that using Simplified Field Notation won't rond down the value automatically , it will always round up automatically.  While this is convenient you may want to consider how to work around this if you need the total to be precise, specially on governement forms .

2 replies

Nesa Nurani
Community Expert
Community Expert
August 13, 2020

I'm assuming you are using "Simplified field notation" to do calculations?
You want it to show result in total field? if yes then do like this:
if you just want to show .144 use: (field1+field2+field3)*.144
if you want to add .144 to "total" field sum use (field1+field2+field3)*1.144
Of course change field names to the names you are using.

MzKinn
MzKinnAuthor
Participating Frequently
August 14, 2020
Thank you for your response. This calculation was my first thought but it
is not working for me...clearly user error! I am stumped and perhaps
overthinking the process.


--

Robin Kinn

Administrative Assistant

Park Community Charter School

509 Lawe Street | Kaukauna, WI 54130

kinnr@kaukaunasd.org | 920.766.6129
Known Participant
August 14, 2020

From what I got once you get total sum you want to multiply it by. 144 in what field do you want to show result from that? 

ls_rbls
Community Expert
Community Expert
August 13, 2020

In the Project Total field you can use something like this:

 

 

var f= this.getField("Total");
var g = f.getArray();
var  v = 0.0;  
for (var i=0; i<=g.length; i++) {  
    event.value =
var subtotal = v += g[i].value; 
event.value = subtotal +(subtotal*.144);
}

 

 

This example is using the getArray() method so it is intended to work if you have a parent field prefixed and all the children fields suffixed.  If you use different fieldnames then you would need to employ a slightly different method to have the script calculate numerical fields with the new Array() method,for example. 

 

For my example, every field under the Total Stipends column I renamed to "Total.1", "Total.2", "Total.3", etc.  which made everything very easy and more organized. But this can be achieved in many other ways with JavaScript.