Copy link to clipboard
Copied
I have 3 calculated fields.
Field1: sum of 5 values at timepoint1
Field 2: sum of 5 values at timepoint 2
Field 3: based on Field1 and Field2 sums ( it's a % change) --- (sum2-sum1)/sum1
The problem is this:
Field 2 is defaulting at 0 before anyone enters a 0. It should be null until a value is entered. Valid values can be 0,1,2,3,4 etc. anything greater or equal to 0.
Field 3 is then calculating before Field 2 has a valid entered value - because of the default 0 for Field2. I need it to calculate when an actual >=0 value is entered for field2.
How can I do this? I've tried so many options - the typical event.value==0 et.et. But i need to figure out with my limited javascripting how to ....any help will be awesome.
Example below:
the 10= FIELD1
Field 2: Diameter (mm) value = 0 because nothing is entered in the rows above - see all NULLS
Field 3: From BASELINE = -100 because its' calculating percent change from (0-10/10) *100 = -100. I need the 0 only to be calculated if that sum really is 0 vs null as it is now
Copy link to clipboard
Copied
How did you set up the calculation? If you used a script, post it, please.
Copy link to clipboard
Copied
Ok thanks: Here are my calculations
Field1: diameter baseline sum : sum function in the text field properties
I also have this in the validate :
// null filed value if entry is zero
if(event.value == 0) event.value = "";
Field2:
Diameter 2 --- sum function in text field ( where the sum default is 0)
with this in validate:
// null filed value if entry is zero
if(event.value == 0) event.value = 0
Field 3:
% change from baseline ( the one with the -100 when no field2 is entered but hte default is 0)
in calculate:
var baseDiaSum = this.getField("BASEDIAMETERSUM1").value;
var Dia2 = this.getField("DIAMETERSUM2").value;
if((!baseDiaSum) || (baseDiaSum == 0) ){
event.value = 0;
}
else{
event.value = ((Dia2 - baseDiaSum)/baseDiaSum)*100
}
in validate i was playing around with it and put this for now:
// null filed value if entry is zero
if(event.value ==0) event.value = "n/a";
Copy link to clipboard
Copied
Can you share the actual file (using Dropbox, Google Drive, Adobe Cloud, etc.)?
Copy link to clipboard
Copied
Sure thanks for caring: here it is
https://drive.google.com/open?id=0BwcnQ6AWXzkRT256em10NVhwWDJaUW9GYV9pQl9GcnBOWTBv
Copy link to clipboard
Copied
The "-100" result is correct for the values you entered. If Dia2 is 0 and baseDiaSum is 10 then the formula is:
((0 - 100)/100)*100 = -100
If you don't want it to produce that result then you need to define how it should behave in this situation. For example, you can add a condition that if Dia2 is 0 then the result is 0, no matter what, like you did with baseDiaSum.
Copy link to clipboard
Copied
CORRECT, it is if the value really is 0 , but the value shouldnt be 0 for field2. it should be NULL - until the user actually enters 0 for hte fields above that are summed. I know that adobe sees that as '0' but i need that to be NULL until the user actually inputs a 0...
understand? They didnt. THats automatic
Copy link to clipboard
Copied
A null value if accessed as a number is null or zero. If you want to alter the behavior then you will need to do some custom scripting for the format of the field. You need to test the event value for the null value of "", an empty string and then set the value to an empty string.
Using the "Field is the ____ of the following fields" or the simplified field notation assumes the result will be a numeric value and not a string value. You can override this bu using the custom format option on the "Format" tab. Note, using custom JavaScript calculation option also does this but the programmer can force the value of the field to the null string value.
Copy link to clipboard
Copied
As I said, you need to check if that field is empty, just like you do with the other one.
Copy link to clipboard
Copied
@try67 thanks for assisting thus far, what do you mean check if empty like the other one? Which field?
Copy link to clipboard
Copied
Like this:
var Dia2 = this.getField("DIAMETERSUM2").valueAsString;
if (Dia2=="") event.value = "";
else {
// place rest of calculation code here
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now