Skip to main content
Participating Frequently
April 9, 2019
Answered

Converting if statement in excel to work in a PDF formula

  • April 9, 2019
  • 1 reply
  • 1280 views

Good afternoon

I have been reading a lot of questions and answers on this forum for converting an Excel IF formula into a formula that will work in a PDF. I have been unable to find any that work with my case and I don't understand enough of what people are saying to figure it out on my own. Can someone please help? The current formula is set up like this:

=IF(D31="Y",750,0)*12+(D35+600*12)

I have different references for D31 and D35 in my PDF document which are as follows:

D31 - Vehicle

D35 - PorterVehicles

Any help in the right direction would be so appreciated. Thank you!

This topic has been closed for replies.
Correct answer Thom Parker

So close! It works perfectly when the value is not Y. When I change it to Y the value jumps up by about 72 million instead of 9,000.

I really really appreciate your help. It is definitely helping me see how to do this for other formulas that I have moving forward.


Well actually the "if" statement is working since things are changing when a Y is entered. It's the calculation that has the issue. I don't know why the value is jumping so much. I'd have to see your document to figure out the exact problem, but try this.

var nValue = Number(this.getField("PorterVehicles").value + 600*12);

if(this.getField("Vehicle").value == "Y")

  nValue += 9000;

event.value = nValue;

I suspect that in the first line the value is being interpreted as a string.

1 reply

Thom Parker
Community Expert
Community Expert
April 9, 2019

Here's an article on writing an "if":

https://acrobatusers.com/tutorials/conditional-execution

Explain the condition you want and we can provide some sample code.

For example: "If the Vehicle field is "Y" then the calculation in the "Result field" adds 750 to the calculated value.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
April 9, 2019

I did look at this article earlier from another forum post and was really confused...I think it hard for me to follow where I plug in my values to achieve the result needed.

The formula is asking that if the Vehicle field is is Y, then it adds 750*12 to the calculated value. If the Vehicle Field is N (or other letter) then it would just be the calculated value.

Thom Parker
Community Expert
Community Expert
April 9, 2019

Here is a custom calculation script

event.value = this.getField("PorterVehicles").value + 600*12

if(this.getField("Vehicle").value == "Y")

  event.value += 750*12;

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often