Select to view content in your preferred language

Conditional label based on field value

335
2
Jump to solution
03-03-2024 04:46 PM
PipeVision
New Contributor

On a Point layer, i want to create a label, where if certain attributes have been entered, Then add those aswell.

2x relevant fields are:

IA_Cause - A dropdown / Domain list containing text reasons for the point
DTI - Text field, But, Eventually will be updated to be numeric (to only allow XX.X numbers)

I would like the IA_Cause to be the default label for the points.
However, IF a value has been added to the "DTI" field, i would also like that added to the label.
And IF the DTI field has a value, i would like to add "m" to the end of the DTI Value.

 

In an example, where a point without a DTI value added to the feature would just be labeled:
"Because of reasons"

In an example where the same point had "21.6" added to the DTI Attribute
"Because of reasons 21.6m"

 

I Currently use:

1. $feature["IA_Cause"]
2. DomainName($feature, "IA_Cause") + $feature["DTI"] + "m"

 

The issue with the formula is:
Where a point is added with ONLY the "IA_Cause" and NO DTI value, The label automatically adds an 'm' at the end, so i end up with a label saying "Because of reasonsm"

0 Kudos
1 Solution

Accepted Solutions
RoryMcPherson
New Contributor III

This is a great reason to use Arcade. Here is some Arcade you can apply to your label settings. I have also added a text conversion to the DTI field so that if you do eventually change this to a numeric field it will still work.

var ia = $feature["IA_Cause"];
var dti = $feature["DTI"];
var label;

if (IsEmpty(dti) == false) {
  label = ia + " " + Text(dti) + "m";
} else {
  label = ia;
};

return label;

 

View solution in original post

2 Replies
RoryMcPherson
New Contributor III

This is a great reason to use Arcade. Here is some Arcade you can apply to your label settings. I have also added a text conversion to the DTI field so that if you do eventually change this to a numeric field it will still work.

var ia = $feature["IA_Cause"];
var dti = $feature["DTI"];
var label;

if (IsEmpty(dti) == false) {
  label = ia + " " + Text(dti) + "m";
} else {
  label = ia;
};

return label;

 

PipeVision
New Contributor

Absolutely stunning! Thank you very much.

0 Kudos