Copy link to clipboard
Copied
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!
1 Correct answer
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.
Copy link to clipboard
Copied
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.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Here is a custom calculation script
event.value = this.getField("PorterVehicles").value + 600*12
if(this.getField("Vehicle").value == "Y")
event.value += 750*12;
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
That worked! Thank you so much for all your help! I have another one in the same document to do, but now that I can see the structure as it applies to my document, I think I can figure it out! Thank you again!

