Select to view content in your preferred language

Arcade expression to display multiple field values based on corresponding field value

9139
6
Jump to solution
04-29-2021 07:37 AM
Labels (1)
kshahmmp
Emerging Contributor

Hi,

I need to display fields and its values in popup panel based on one of its corresponding field values. I tried using if/else statement but doesn't return the values that I want. I found esri support help resources (https://support.esri.com/en/technical-article/000024112) but couldn't able to resolve. What is was particularly looking is 

if ($FieldName4 == 1) {

    return FieldName1.Value, FieldName2.Value, FieldName3.Value

}

if ($FieldName4 == 2) {

    return FieldName1.Value, FieldName2.Value, FieldName3.Value

}

For instance in the above esri resource table; I need to display all the values for fields i.e. 'Student_ID', 'Grade1', 'Grade2' that are related to Field value 'Excellent' from 'Results' Field.

Both expression has to be displayed in same popup though. 

Not sure if there is any better way to do other than if/else statement. I would greatly appreciate for any help or resources in this regard.

Thanks,

kshah

 

1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi @kshahmmp ,

A couple of pointers here. When you want to access to value in a field called "FieldName1", you can use two ways to do this:

$feature.FieldName1
$feature["FieldName1"]

 

The second option is preferred when you have a field name containing an underscore:

$feature["Field_Name1"]

 

The code you posted raised a couple of questions:

  • Do you want to return a text containing the values of 3 fields separated by a comma?
  • Do you want to return the same 3 fields when FieldName4 is either 1 and 2 (or are there other fields to return?)

Based on a number of assumptions see the example below. In this case, when FieldName4 is 1 a text with FieldNames 1, 2, and 3 will be returned and when FieldName4 is 2, a text with FieldNames 5, 6, and 7 will be returned. It uses the Concatenate function and provides an array (list) of the field values and the text to separate the field values.

if ($feature.FieldName4 == 1) {
    return Concatenate([$feature.FieldName1, $feature.FieldName2, $feature.FieldName3], ", ");
} else if ($feature.FieldName4 == 2) {
    return Concatenate([$feature.FieldName5, $feature.FieldName6, $feature.FieldName7], ", ");
}

 

 

View solution in original post

6 Replies
jcarlson
MVP Esteemed Contributor

Just to clarify: do you want the popup to include all values in each column or just the other fields in the individual feature?

- Josh Carlson
Kendall County GIS
0 Kudos
kshahmmp
Emerging Contributor

Hi Josh,
In the pop up I want to include other fields in the individual feature but it should be filter out based on a corresponding particular field value i.e ($Feature.Field1 == 1) and on the same pop up I need display same other fields for that same individual feature but this time ($Feature.Field == 2). I think when the first one is returned second should be easy as it applies same principle. 

Thanks

kshah

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @kshahmmp ,

A couple of pointers here. When you want to access to value in a field called "FieldName1", you can use two ways to do this:

$feature.FieldName1
$feature["FieldName1"]

 

The second option is preferred when you have a field name containing an underscore:

$feature["Field_Name1"]

 

The code you posted raised a couple of questions:

  • Do you want to return a text containing the values of 3 fields separated by a comma?
  • Do you want to return the same 3 fields when FieldName4 is either 1 and 2 (or are there other fields to return?)

Based on a number of assumptions see the example below. In this case, when FieldName4 is 1 a text with FieldNames 1, 2, and 3 will be returned and when FieldName4 is 2, a text with FieldNames 5, 6, and 7 will be returned. It uses the Concatenate function and provides an array (list) of the field values and the text to separate the field values.

if ($feature.FieldName4 == 1) {
    return Concatenate([$feature.FieldName1, $feature.FieldName2, $feature.FieldName3], ", ");
} else if ($feature.FieldName4 == 2) {
    return Concatenate([$feature.FieldName5, $feature.FieldName6, $feature.FieldName7], ", ");
}

 

 

kshahmmp
Emerging Contributor

Hi Xander,

That helps. I was wanting to return multiple fields with their values based on clause. Just out of curiosity, is there better way to configure pop up display in single window rather than toggle 1 of 2, 2 of 2...?

Thanks you

XanderBakker
Esri Esteemed Contributor

Hi @kshahmmp ,

I wish that was possible. Arcade would be able to extract whatever other features are beneath the feature the user clicked on, but this won't stop ArcGIS to consult the feature below and apply the same Arcade expression to see what other features it can find. This will come at a cost (performance) and you will still see the "1 of 2" and "2 of 2" (although in this case, the user would not have to go to the second feature to obtain the details.

0 Kudos
KateDoughty1
Regular Contributor

Can this be done to merge FieldName1 values, based on if/else condition of FieldName2?