Highlighted

Custom Calculation

New Here ,
Aug 18, 2020

Copy link to clipboard

Copied

I am trying to do a custom calculation, but cannot figure out how to do it.  I know how to do it in Excel, but this is obviously different.  Here is what I need help with:

 

I am making a PDF fillable form for ROI on company vehicles.  I have a cell that has a calculated total, which is called "Total Vehicle Price."  I have one that is called "Annual Billable Revenue" and one that is call "Annual Cost."

 

The formula I need is: Total vehicle price/ (Annual Billable Revenue - Annual Cost)

 

If possible, I would like to also know how to add a custom label after this formula to say "Years"

 

Greatly appreciate any help!

TOPICS
PDF forms

Views

28

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Custom Calculation

New Here ,
Aug 18, 2020

Copy link to clipboard

Copied

I am trying to do a custom calculation, but cannot figure out how to do it.  I know how to do it in Excel, but this is obviously different.  Here is what I need help with:

 

I am making a PDF fillable form for ROI on company vehicles.  I have a cell that has a calculated total, which is called "Total Vehicle Price."  I have one that is called "Annual Billable Revenue" and one that is call "Annual Cost."

 

The formula I need is: Total vehicle price/ (Annual Billable Revenue - Annual Cost)

 

If possible, I would like to also know how to add a custom label after this formula to say "Years"

 

Greatly appreciate any help!

TOPICS
PDF forms

Views

29

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 18, 2020 0
Engaged ,
Aug 18, 2020

Copy link to clipboard

Copied

You didn't say in what field you want this calculation so I assume you have 4th field for that if not, adapt code as necessary.
Use this code as "Custom Calculation Script" of your field:
var a = this.getField("Total Vehicle Price").value;
var b = this.getField("Annual Billable Revenue").value;
var c = this.getField("Annual Cost").value;
var x = a/(b-c);
event.value = x.toFixed(2) + " Years";

If you want currency sign next to value add it like this: "$"+ x.toFixed(2) + " Years";
also if you don't want your field to show "NaN Years" when there is no calculation going on, add this code as
"Custom Validation Script" of the same field:

if(event.value == "NaN Years")
event.value = "";

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 18, 2020 0
Most Valuable Participant ,
Aug 18, 2020

Copy link to clipboard

Copied

It's not good to do it like that. You should check if (b-c) is zero before dividing by it. Also, the result of division by zero is not NaN, it's Infinity...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 18, 2020 0
Engaged ,
Aug 18, 2020

Copy link to clipboard

Copied

Thank you for pointing that out I myself am new at this ( I only started using acrobat 1 month ago) so il take any chance to improve my knowledge. 🙂
I belive that he knows that result won't be 0 or he wouldn't ask for that equation.
I mention NaN because when all 3 fields are cleared, then calculation field show "NaN Years"
"Infinity Years" is showed if result would be 0 but since I belive that wouldn't be the case I think it will be fine.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 18, 2020 0