Skip to main content
Participant
August 1, 2023
Answered

Need assistance writing a calculation with two conditions

  • August 1, 2023
  • 1 reply
  • 429 views

This one is a little beyond me so I'm hoping someone can help -

I'm working with 5 fields, I'll label them "fieldA"-"fieldE" for simplicity sake. 

Here is what I'm after: fieldD = fieldB, unless: 1) fieldE is greater than 50,000 and 2) fieldB is null, then fieldD = fieldC. 

Field D is where the calculation would be. 

Example 1:

fieldA: $100,000

fieldB: null (not sure how to express this in the field itself, does null or N/A work, or leaving it blank wihtout it reading as 0?)

fieldC: $60

fieldD: (result should be $60)

fieldE: $150,000

Example 2:

fieldA: $95,000

fieldB: $20

fieldC: (this will default as a 0.00)

fieldD: (result should be $20)

fieldE: $90,000

Thanks all of you wonderful people! 

This topic has been closed for replies.
Correct answer try67

Null, an empty string and zero are not the same things, so it's important to know what you're dealing with.

Assuming it's a blank field, you can use this code as the custom calculation script of fieldD:

 

var fieldB = this.getField("fieldB").valueAsString;
var fieldC = this.getField("fieldC").valueAsString;
var fieldE = this.getField("fieldE").valueAsString;

if (Number(fieldE)>50000 && fieldB=="") event.value = fieldC;
else event.value = fieldB;

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 1, 2023

Null, an empty string and zero are not the same things, so it's important to know what you're dealing with.

Assuming it's a blank field, you can use this code as the custom calculation script of fieldD:

 

var fieldB = this.getField("fieldB").valueAsString;
var fieldC = this.getField("fieldC").valueAsString;
var fieldE = this.getField("fieldE").valueAsString;

if (Number(fieldE)>50000 && fieldB=="") event.value = fieldC;
else event.value = fieldB;
try67
Community Expert
Community Expert
August 1, 2023

PS. fieldA doesn't seem to have a role in this formula...