Arcade Expression for conditions

2301
11
Jump to solution
01-26-2021 02:47 PM
KhemAryal
New Contributor III

Hi 

I have data collected in the field as

Depth rim to invert (A)

Depth Rim to Debris (B)

Depth Rim to Bottom (C)

KhemAryal_0-1611701093634.png

I need Arcade expression for display as

If (C-B)>(C-A)/3              ‘Need Cleaning’

Else                                          ‘No Cleaning Needed’

Here is my expression

KhemAryal_1-1611701093640.png

The expression Test passed but doesn’t reflect the counts in the layers as there is one data that supposed to return “Cleaning Needed”. This is reflected as 'Other' with 0 counts.

Not sure what I am missing

 

 

KhemAryal_2-1611701093642.png

Thanks in advance

1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi @KhemAryal ,

If I look at your expression and the explanation it seems that you inverted debris and invert in the conditional statement.

var A = 2.50; // rim to Invert (A)
var B = 1.60; // rim to Debris (B)
var C = 3.50; // rim to Bottom (C)

var debris = C-A; // rim to Bottom (C) - rim to Debris (A)
var invert = C-B; // rim to Bottom (C) - rim to Invert (B)
Console("debris: " + debris);
Console("invert: " + invert);

// If (C-B)>(C-A)/3  'Need Cleaning'
// Else             'No Cleaning Needed'

Console("debris/3: " + debris/3);

if (invert>debris/3) {
    return 'Need Cleaning';
} else {
    return 'No Cleaning Needed';
}

 

This returns "Need Cleaning" and it writes the following to the console:

debris: 1
invert: 1.9
debris/3: 0.3333333333333333

 

View solution in original post

11 Replies
DavidPike
MVP Frequent Contributor

It looks fine to me, but the logical test is obviously failing on everything and the Else is being returned.

Perhaps it's a text field rather than a float/number?  Only other suggestion is to try returning debris, invert and your logical test to debug.

0 Kudos
KhemAryal
New Contributor III

Thanks @DavidPike 

The field type is not text but 'Double'

KhemAryal_0-1611762592780.png

 

Wondering how do you debug the logical test?

0 Kudos
DavidPike
MVP Frequent Contributor

just label everything as debris, then invert/3 and see whats happening possibly.  maybe needs to be invert/3.0 if arcade is funny that way?

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @KhemAryal ,

If I look at your expression and the explanation it seems that you inverted debris and invert in the conditional statement.

var A = 2.50; // rim to Invert (A)
var B = 1.60; // rim to Debris (B)
var C = 3.50; // rim to Bottom (C)

var debris = C-A; // rim to Bottom (C) - rim to Debris (A)
var invert = C-B; // rim to Bottom (C) - rim to Invert (B)
Console("debris: " + debris);
Console("invert: " + invert);

// If (C-B)>(C-A)/3  'Need Cleaning'
// Else             'No Cleaning Needed'

Console("debris/3: " + debris/3);

if (invert>debris/3) {
    return 'Need Cleaning';
} else {
    return 'No Cleaning Needed';
}

 

This returns "Need Cleaning" and it writes the following to the console:

debris: 1
invert: 1.9
debris/3: 0.3333333333333333

 

KhemAryal
New Contributor III

Hey XanderBakker

That expression now solved my problem. 

You are a GEM and a great resource for us in this forum.  

0 Kudos
XanderBakker
Esri Esteemed Contributor

You're welcome @KhemAryal . I'm glad it works.

0 Kudos
KhemAryal
New Contributor III

Hi @XanderBakker 

I did not notice this yesterday but Its showing different than expected on the count. there are actually total of 3187 features (not 1000). and there should be 2 counts 'need cleaning', What do you think?

KhemAryal_0-1611936112848.png

 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @KhemAryal ,

The symbology is probably limited to reading 1000 features for performance reasons. Do you need the correct statistics for the entire layer?

0 Kudos
KhemAryal
New Contributor III

Yes I need to reflect all the features in the layer with the symbology. Otherwise I have to create more fields and individually insert domains - cleaning needed or not needed

0 Kudos