Skip to main content
Participant
June 24, 2024
Question

IF THEN

  • June 24, 2024
  • 1 reply
  • 743 views

Hello I have the follwing formula that I need to add a "IF Then" statement.

event.value = Math.abs(Number(this.getField("A1").valueAsString) / Number(this.getField("A2").valueAsString));

 

I use it for calulating percentage accuracy.  It works find when A2 data is above A1 data.  When it is below my percentage is > 100%

 

This topic has been closed for replies.

1 reply

Nesa Nurani
Community Expert
Community Expert
June 24, 2024

What do you want to happen when A2 is less than A1?

You want to limit percentage to 100%?

In your current script, you need to check that A2 is not 0, or you will get an error when A2 is 0 or blank.

Participant
June 24, 2024

Right now when A2 goes below A1 the result for P1 is greather than 100% when i need it to be 90.62%.  All my results need to be below 100%.  

try67
Community Expert
Community Expert
June 24, 2024

Why that number? It doesn't make sense... You can set it as 100%, but that's not a correct result, either.

To do that latter add this to the end of your code (at your own risk):

if (event.value>1) event.value = 1;

As Nesa correctly noted, though, you have to add a condition that checks that A2 is not zero, or you'll get error messages when it is.