Select to view content in your preferred language

How to use Count expression with no selection?

479
5
09-14-2023 08:00 AM
AndyWells
Occasional Contributor II

I want to have a count of selected features, but sometimes there is no selection. If I use a text widget, connected to my layer, using Selected instead of Default, this will work fine as long as there is at least one feature selected. If there is none, the Count formula just displays the formula. Is there a workaround to display something when there is no selection to count?

0 Kudos
5 Replies
JeffreyThompson2
MVP Regular Contributor

I attempted using IIF() from Arcade and setting an empty data view. Neither one worked in my quick trial, but if it's possible in OOTB text widget, I feel like it would be down one of those roads.

https://developers.arcgis.com/experience-builder/guide/select-data/#data-details-and-data-views

https://developers.arcgis.com/arcade/function-reference/logical_functions/#iif

GIS Developer
City of Arlington, Texas
0 Kudos
AndyWells
Occasional Contributor II

I thought maybe I could check "View for empty selection" and then give it  filter like OBJECTID = -1, but that doesn't work. And I don't see anyway to get an Arcade expression to work in ExB. 

0 Kudos
AndyWells
Occasional Contributor II

Well, I just realized if I use the "Expression" tab under Dynamic Content for the text widget, instead of "Statistics", then I can give the expression a name, something like "No current selection" and it will display that text when there is no selection. 

It would still be great if we could use Arcade expressions though, or at least have some sort of logic functions built into the expression editors.

0 Kudos
JeffreyThompson2
MVP Regular Contributor

Could you post your syntax? I tried the Expression tab and didn't get it to work. What happens with a blank name? Maybe you could even try grabbing an invisible unicode character?

GIS Developer
City of Arlington, Texas
0 Kudos
AndyWells
Occasional Contributor II

I created an expression to display the words "Parcels Selected: " and then the number currently selected. Above it, where it normally says "Expression 1", I changed that to "No Parcels Selected"

AndyWells_0-1694709586227.png

So when there is a selection the text displays:

AndyWells_1-1694709623713.png

And when there is no selection, the text displays:

AndyWells_2-1694709655854.png

 

 

 

0 Kudos