Arcade expression for area ranges (max and min) with Null values in labels

3712
6
Jump to solution
11-19-2020 01:50 PM
DianaWilson1
New Contributor III

Hi All,
I am working in a arcade expression for label the size range for each parcel with multiple buildings with different size. I have 4 fields: "Area1", "Area2", "Area3", and "Area4". There are null values in the within the fields. I wrote those expressions, but they do not work. could you please review it and let me know how will be the right expression.
If(!IsEmpty($feature.AREA1)) {return($feature.AREA1)}
else if (!IsEmpty($feature.AREA2)) {return($feature.AREA2)}
else if (!IsEmpty($feature.AREA3)) {return($feature.AREA3)}
else if (!IsEmpty($feature.AREA4)) {return($feature.AREA4)}
The other expression is:
Min($feature.AREA1,$feature.AREA2,$feature.AREA3,$feature.AREA4)+"-"+Max($feature.AREA1,$feature.AREA2,$feature.AREA3,$feature.AREA4)
With the second expression, as an example I get expression like 0-1050. but I do not want to get the "0", just because there is a null value in the "Area1"
Any advice? thank you!

 

0 Kudos
2 Solutions

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi @DianaWilson1 ,

 

I assume you applied the text formatting to the original value and not to the resulting min and max value after processing the values. It is best to apply it on the lines below:

// determine min and max values
var minval = Text(MinOK(lst), "#,###");
var maxval = Text(MaxOK(lst), "#,###");

 

This will return the result with the thousands separator as shown below:

XanderBakker_0-1605892555173.png

 

View solution in original post

DianaWilson1
New Contributor III

Thank you Alex! you are the best!

View solution in original post

6 Replies
XanderBakker
Esri Esteemed Contributor

Hi @DianaWilson1 ,

Have a look at the example below. It consists of 3 functions ("RemoveNulls", "MinOK" and "MaxOK") and at the end a couple of lines of code to create the initial list from your attribute values. It will remove the empty values from the list and return a corrected list that allows you to use the Min and Max (and other) functions:

Function RemoveNulls(lst1) {
    // remove empty values from list
    var lst2 = [];
    for (var i in lst1) {
        if (!IsEmpty(lst1[i])) {
            lst2[Count(lst2)] = lst1[i];
        }
    }
    return lst2;
}

Function MinOK(lst1) {
    // return min from corrected list
    var lst2 = RemoveNulls(lst1);    
    if (Count(lst2)>0) {
        return Min(lst2);
    } else {
        return Null;
    }
}

Function MaxOK(lst1) {
    // return max from corrected list
    var lst2 = RemoveNulls(lst1);    
    if (Count(lst2)>0) {
        return Max(lst2);
    } else {
        return Null;
    }
}

// read your input values
var AREA1 = 3;    // $feature.AREA1
var AREA2 = 7;    // $feature.AREA2
var AREA3 = null; // $feature.AREA3
var AREA4 = 2;    // $feature.AREA4

// create a list
var lst = [AREA1, AREA2, AREA3, AREA4];

// determine min and max values
var minval = MinOK(lst);
var maxval = MaxOK(lst);

// return result
return minval + "-" + maxval;

 

0 Kudos
DianaWilson1
New Contributor III

Xander, 

Thank you! The query is not giving me the max and min in all the parcels. Look screen shot. Thanks! 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @DianaWilson1 ,

 

Can you share more information about how you implemented the expression? I just did a test with the values you shared in the image and it works as expected:

XanderBakker_0-1605886445523.png

 

0 Kudos
DianaWilson1
New Contributor III

I see the mistake that I made, I fixed and it works! Thank you, 

How to display the decimal places in this query. I used TEXT($feature.AREA1,'#,###'); but I just got NaN 

Thank you, 

 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @DianaWilson1 ,

 

I assume you applied the text formatting to the original value and not to the resulting min and max value after processing the values. It is best to apply it on the lines below:

// determine min and max values
var minval = Text(MinOK(lst), "#,###");
var maxval = Text(MaxOK(lst), "#,###");

 

This will return the result with the thousands separator as shown below:

XanderBakker_0-1605892555173.png

 

DianaWilson1
New Contributor III

Thank you Alex! you are the best!