Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - SUMIF function
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

SUMIF function

 Post Reply Post Reply
Author
bren1519 View Drop Down
New Member
New Member
Avatar

Joined: 06 May 2013
Location: Toronto, ON
Points: 1
Post Options Post Options   Quote bren1519 Quote  Post ReplyReply Direct Link To This Post Topic: SUMIF function
    Posted: 06 May 2013 at 1:59pm
Hi there,
I am creating a simple form in adobe but need it to subtotal on amount column based on values in other two columns.  I originally just required the condition to be based on one column and someone on another forum kindly supplied me with the script (which worked brilliantly).  However, I've now been requested to include another column and I wondered if the script might be revised to do that.  I did make the request on the other forum but haven't yet heard back and I'm on a bit of a deadline.   Thanks for any assistance! Brenda
 
Example of form data:

Visa     A/R          250.00

Visa     Non A/R   50.00

Cash     Non A/R     50.00    

Cash     A/R          100.00

Visa     A/R          125.00

 

Total A/R Sales:

Visa     $375.00

Cash     $100.00

 

Total Non A/R Sales:

Visa     $50.00

Cash     $50.00

 

Two scripts were provided, both of which work but I think I prefer the first.  Is it possible to alter the script to take the second column (AR) into account? 

 

A sum if equal function using hierarchal field names:

function SumIfEq(cIndex, cRange, cValue) {
// function to sum cRange for item in cIndex that equals  cValue;
// using hierarchical fields;
var nSum = 0; // variable to sum payment type;
// using hierarchical field names;
// get the payment type and amount high level field objects;
var oPayType = this.getField(cIndex);
var oAmount = this.getField(cRange);
// convert the highlevel field objects to arrays;
var aPayType = oPayType.getArray();
var aAmount = oAmount.getArray();
// verify that there are an equal number of fields;
if(aPayType.length != aAmount.length) {
app.alert("The number of payment type fields and amount fields must be equal!", 0, 0);
} else {
// loop through the fields
for(i = 0; i < aPayType.length; i++) {
console.println(aPayType.value);
if(aPayType.value == cValue) {
// add the payment to the sum;
nSum += Number(aAmount.value);
} // end match payment type;
} // end loop through the fields;
} // end field length;
return nSum; // return computed sum;
} // end SumIfEq function

// custom calculation script using the SumIfEq function;
// call sum if equal for payment "Type", for "Amount", equal to "Visa";
event.value = SumIfEq("Type", "Amount", "Visa");
// end custom calculation script;

The Sum If Equal function using an array of field names:

function SumIfEq(aIndex, aRange, cValue) {
// function to sum cRange for item in cIndex that equals  cValue;
// do not change code below;
var nSum = 0; // variable to sum payment type;
// verify that there are an equal number of fields;
if(aIndex.length != aRange.length) {
   app.alert("The number of payment type fields and amount fields must be equal!", 0, 0);
   } else {
   // loop through the fields
   for(i = 0; i < aIndex.length; i++) {
   if(this.getField(aIndex).value == cValue) {
      // add the payment to the sum;
      nSum += Number(this.getField(aRange).value);
      } // end match payment type;
   } // end loop through the fields;
} // end field length;
return nSum; // return computed sum;
} // end SumIfEq function

// custom calculation script using the SumIfEq function;
// using arrays of field names;
var aIndex = new Array("Type.0", "Type.1", "Type.2", "Type.3", "Type.4", "Type.5", "Type.6", "Type.7", "Type.8", "Type.9");
var aRange = new Array("Amount.0", "Amount.1", "Amount.2", "Amount.3", "Amount.4", "Amount.5", "Amount.6", "Amount.7", "Amount.8", "Amount.9"); 
// call sum if equal for payment "Type", for "Amount", equal to "Visa";
event.value = SumIfEq(aIndex, aRange, "Visa");
// end custom calculation script;

 

 

Back to Top
Sponsored Links


Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.035 seconds.