Arcade: Show names as labels if a condition is met

1582
10
Jump to solution
01-31-2024 05:30 AM
Ed_
by MVP Regular Contributor
MVP Regular Contributor

Based on the dummy data below how can I show only those values under `C1` as labels when let's say values of `C2` are greater than 40?

 

Sample data:

C1	C2
A	20
B	0
C	60
D	40
E	70
F	35
G	80
H	90
I	15

 

Question | Analyze | Visualize
Tags (3)
0 Kudos
3 Solutions

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You can use this Expression

if ($feature.C2 > 40) return $feature.C1

View solution in original post

ZachBodenner
MVP Regular Contributor

Without too much trouble, actually! Depending on your environment, the actual locations of where you'd create the Arcade expression may change, but the basic formula is something like this:

 

var label = $feature.C1
var qual = $feature.C2

if (qual > 40){
return label}
else {
return
}

View solution in original post

KenBuja
MVP Esteemed Contributor

You can accept more than one answer!

View solution in original post

10 Replies
KenBuja
MVP Esteemed Contributor

You can use this Expression

if ($feature.C2 > 40) return $feature.C1
Ed_
by MVP Regular Contributor
MVP Regular Contributor

Hi @KenBuja nice to hear from you, hope all is well, thank you for the super quick response 🙂. So I don't have to setup a variable first?

Question | Analyze | Visualize
0 Kudos
KenBuja
MVP Esteemed Contributor

No, this shows the results of the one-line code. The two highlighted points show the Data field above and below 40

code.png

Ed_
by MVP Regular Contributor
MVP Regular Contributor

Oh that's neat and super concise wish I could accept two answers lol 

Question | Analyze | Visualize
0 Kudos
KenBuja
MVP Esteemed Contributor

You can accept more than one answer!

AlfredBaldenweck
MVP Regular Contributor
if ($feature.C2 > 40){
    var lab = $feature.C1
} else {
    var lab = Null
}
return lab

The points are labelled with both C1 and C2 in red, and then this expression is for the black text.

AlfredBaldenweck_0-1706709417792.png

 

Ed_
by MVP Regular Contributor
MVP Regular Contributor

Hi @AlfredBaldenweck thank you for quick response, so in your code lab =  C1 then how come both C1 and C2 are being returned on the map?

Question | Analyze | Visualize
0 Kudos
AlfredBaldenweck
MVP Regular Contributor

That's in a different label class for demonstration. The black text is what's being returned by this expression.

ZachBodenner
MVP Regular Contributor

Without too much trouble, actually! Depending on your environment, the actual locations of where you'd create the Arcade expression may change, but the basic formula is something like this:

 

var label = $feature.C1
var qual = $feature.C2

if (qual > 40){
return label}
else {
return
}