## Converting if statement in excel to work in a PDF formula

New Here ,
Apr 09, 2019

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!

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.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

97

Likes

Report

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

## Converting if statement in excel to work in a PDF formula

New Here ,
Apr 09, 2019

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!

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.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

98

Likes

Report

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

Copied

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

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.

Likes

Report

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

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.

Likes

Report

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

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;

Likes

Report

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

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.

Likes

Report

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

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.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 09, 2019 0
LATEST
New Here ,
Apr 10, 2019