Hello,
I have a text widget that is linked to an interactive map. the widget displays information relating to cycling infrastructure, and has two expressions: one that indicates the total length of cycle track (a type of cycling infrastructure) based on the map extent, and the other, percent of total network based on the map extent.
For example, if there is a total of 10 kilometres of cycling infrastructure displayed on the map, and there's 2 kilometres of cycle track infrastructure, then the widget would display: CYCLE TRACK 2 Km Total Length, 20% of Total Network.
My issue is with the expression I'm using for percent of total network:
SUM({Length_km})/SUM({Length_km})*100
The first SUM being the total length of Cycle Track, the second SUM being the total length of all cycling infrastructure. The widget is connected to two Views: the default view and one with the filter: Cycling Infrastructure is Cycle Track.
The issue with this expression is that when I zoom into an area that has no cycling infrastructure, the widget displays: CYCLE TRACK 0 Km Total Length, Expression 1% of Total Network
Can someone help me edit this arcade expression so that when either the numerator or denominator of the expression has a value of zero, the widget displays: 0% of Total Network
Solved! Go to Solution.
@Tim_C, it's just defaulting to showing the name of your expression, which you can rename. For example, here's a quick (non-sensical) example I put together with expressions showing how much of the population in view is part of Michigan. The top dynamic text has a generic expression name, and the bottom I've named "0%":
Hi @Tim_C,
I think you might be getting into an issue with dividing by zero when you are outside.
// Get your numerator and denominator values
var cycleTrackSum = SUM({Length_km}); // Numerator (Filtered View)
var totalNetworkSum = SUM({Length_km}); // Denominator (Default View)
// Check if the total network is zero or null
// If it is, return 0. Otherwise, perform the calculation.
var percent = IIF(totalNetworkSum > 0, (cycleTrackSum / totalNetworkSum) * 100, 0);
return Round(percent, 0) + "% of Total Network";
Please refer the link below for more information on IIF function reference.
If - else | ArcGIS Arcade | Esri Developer
I hope this helps and let me know.
@Tim_C, it's just defaulting to showing the name of your expression, which you can rename. For example, here's a quick (non-sensical) example I put together with expressions showing how much of the population in view is part of Michigan. The top dynamic text has a generic expression name, and the bottom I've named "0%":
Hi Nicole,
Haha, that is genius in its simplicity! I'm actually trying to learn how to code, so I will try Venkat's suggestion first, and if I can't get that to work, resort to naming my expression 0.
Thank you!