|
POST
|
You have the order of the DateDiff parameters reversed if the ExpDate is in the future. For those dates, your expression returns a negative number. Here's an easier way to write your expression, using the When function. This assumes that the ExpDate field is a date field. if (IsEmpty($feature.Expdate) return "Expiry Date Unavailable"
var diff = DateDiff($feature.Expdate, Now(), "days");
When(diff <= 0, "Expired",
diff <= 30, "Expires within 30 days",
diff < 100, "Expires between 30 to 100 days",
"Expires in more than 100 days"
);
... View more
a month ago
|
1
|
0
|
200
|
|
POST
|
I've tested the code using some of my own data and it returned the expected data. I did make a change to line 17 to use the field type "esriFieldTypeInteger" since Count returns an integer, but keeping it as it is also works. The next step would be to put some debugging Console messages in the code at various places (like before and after line 11) and click the Run button in the editor window. This will give you a better idea where the code is crashing.
... View more
a month ago
|
0
|
0
|
397
|
|
POST
|
Doing lots of intersects is a resource hog, since the code has to make external calls for each feature in the loop. @jcarlson wrote a good post about how to store the features in memory (using his Memorize function) to speed up this process. This would be good if you wanted to create a table showing how many lakes are in each tract. However, since you're looking to just get the sum off all the lakes in all the tracts, you can loop through the tracts FeatureSet to union them into a single feature, then use that feature in your Intersects function. You can get the count of that FeatureSet to see how many lakes there are and use the Area function to get the total area of all the lakes. var port = Portal("https://www.arcgis.com");
// Load layers with correct area field name
var tracts = FeatureSetByPortalItem(port, "b9fcbedac0384e32bc3dba6aec1a8cf6", 0, ["OBJECTID"], true);
var lakes = FeatureSetByPortalItem(port, "5564b2e702364aefba08df8c95216a1f", 0, ["OBJECTID"], true);
var arrTracts = [];
for (var tract in tracts) {
Push(arrTracts, tract);
}
var lakesFS = Intersects(lakes, Union(arrTracts));
return FeatureSet(
{
fields: [
{ name: "LakeCount", type: "esriFieldTypeSingle" },
{ name: "Acres", type: "esriFieldTypeDouble" }
],
features: [
{
attributes:
{
LakeCount: Count(lakesFS),
Acres: Area(lakesFS, "acres")
}
}
]
}
);
... View more
11-11-2025
02:03 PM
|
0
|
2
|
470
|
|
POST
|
You should start a new discussion when asking a question like this. Also, when posting code, use the "Insert/Edit code sample" button. It makes it easier to read and refer to specific lines. There are several problems in this line. var countLakes = Count(Filter(lakes, Intersects(Geometry(lakes), tractGeom))); You don't need to filter the results of the Intersects function and even if you did need it, you weren't providing the required sqlExpression. The Geometry function takes a feature as an input instead of a FeatureSet. And in the previous line, you don't need to cast t as a Geometry. Try this instead var countLakes = Count(Intersects(lakes, t));
... View more
11-11-2025
09:32 AM
|
1
|
0
|
190
|
|
POST
|
You can use the SQL CASE statement in the first GroupBy to bin the ages. This will also calculate the age group for the current year instead of 2025. The second GroupBy will count the number of each of the age groups var fs = FeatureSetByPortalItem(
Portal('https://www.arcgis.com/'),
'123456', 0,
['year_of_birth_please_write_full'],
false
);
var sql =
`Case
When year_of_birth_please_write_full > ${Year(Now()) - 18} Then '<18'
When year_of_birth_please_write_full > ${Year(Now()) - 30} Then '18-30'
When year_of_birth_please_write_full > ${Year(Now()) - 40} Then '31-40'
When year_of_birth_please_write_full > ${Year(Now()) - 50} Then '41-50'
When year_of_birth_please_write_full > ${Year(Now()) - 60} Then '51-60'
else '>60'
end`
;
var grouped = GroupBy(
fs,
'OBJECTID', // unique ID field
{ name: 'Age_years', expression: sql, statistic: 'MAX' }
);
GroupBy(
grouped,
"Age_years",
{ name: "Age_Groups", expression: "1", statistic: "COUNT" }
);
... View more
11-06-2025
09:22 AM
|
0
|
1
|
263
|
|
POST
|
Glad to help. Don't forget to click the "Accept as Solution" button to help others searching for this answer.
... View more
11-05-2025
08:42 AM
|
0
|
0
|
186
|
|
POST
|
Try using the escape character "}" for "{" and "}" for "}". This syntax seems to work var output = `https://clientURL/?search={[Property Card]:[Sec_Block_Lot] = "77-3-34"}&openlfoneresult=true`
return {
type : 'text',
text : output
}
... View more
11-04-2025
03:26 PM
|
1
|
2
|
230
|
|
POST
|
You can convert it like this var geom = Geometry($feature);
if (IsEmpty(geom)) {
return null;
} else {
return geom.Z * 3.28084;
} An even simpler expression would be var geom = Geometry($feature);
IIf(IsEmpty(geom), null, geom.Z * 3.28084);
... View more
11-04-2025
07:10 AM
|
5
|
0
|
169
|
|
POST
|
Labels in web maps aren't able to render the formatting tags with Arcade. I think the only solution would be to set up a label class for each of the different colors used in your labels.
... View more
10-28-2025
02:07 PM
|
0
|
0
|
232
|
|
POST
|
The first rule of data expressions is they have to return a FeatureSet. Your expression is only returning a number, so the easiest way to make that into a FeatureSet would be using this syntax for the return return FeatureSet(
{
fields: [{ name: "Total", type: "esriFieldTypeSingle" }],
features: [{ attributes: { Total: Round(total_promedio, 2) } }]
}
);
... View more
10-28-2025
01:21 PM
|
0
|
0
|
195
|
|
POST
|
"yourField" is the name of the date field in your layer. "DESC" just means to sort the attributes in that field in descending order. Please refer to the OrderBy function documentation
... View more
10-20-2025
05:55 AM
|
1
|
0
|
162
|
|
POST
|
The section of the code "$dataSources('dataSource_1')" will give you the FeatureSet, but then you have to do some additional things to get the latest date. You would then have to sort the FeatureSet by the date field (line 2), get the first feature (line 3), then pass the attribute from the date field into the text expression (line 4). That would look something like this, if "yourField" is the name of the date field. var fs = $dataSources("dataSource_1");
var sorted = OrderBy(fs, "yourField DESC");
var feat = First(sorted);
return "Last date update: " + Text(feat.yourField, "MM.DD.YYYY");
... View more
10-16-2025
09:33 AM
|
0
|
2
|
226
|
|
POST
|
This has some more error checking in it (making sure the dates aren't null and has three numbers separated by "/"). I also fixed an error in line 26 that used the wrong variable name. And I reversed the dates in the line 17. function StringToDate(input) {
if (IsEmpty(input)) return null;
var arr = Split(input, "/");
if (Count(arr) != 3) return null;
for (var i of arr) {
if (IsNan(Number(i))) return null;
}
var theDate = DateOnly(arr[2], arr[0] - 1, arr[1]);
iif(IsNan(theDate), null, theDate);
}
var total;
for (var f in fs) {
var date_Applied = StringToDate(f["Applied_Date"]);
var date_Issued = StringToDate(f["Issued_Date"]);
if (IsEmpty(date_Applied) || IsEmpty(date_Issued)) continue;
var differences = DateDiff(date_Issued, date_Applied, "days");
total += Sum(differences);
}
var totalrows = Count(fs);
var avg = iif(totalrows == 0, 0, Floor(total / totalrows));
return FeatureSet(
{
fields: [{ name: "Average", type: "esriFieldTypeInteger" }],
features: [{ attributes: { Average: avg } }]
}
);
... View more
10-09-2025
11:48 AM
|
1
|
1
|
417
|
|
POST
|
This can be done with a single GroupBy statement. GroupBy(
fs,
["date"],
[
{
name: "Adult Male",
expression:
"CASE WHEN lifestage = 'adult' and sex = 'male' THEN quantity ELSE 0 END",
statistic: "Sum"
},
{
name: "Adult Female",
expression:
"CASE WHEN lifestage = 'adult' and sex = 'female' THEN quantity ELSE 0 END",
statistic: "Sum"
},
{
name: "Adult Unsexed",
expression:
"CASE WHEN lifestage = 'adult' and sex is null THEN quantity ELSE 0 END",
statistic: "Sum"
},
{
name: "Juvenile",
expression:
"CASE WHEN lifestage = 'juvenile' THEN quantity ELSE 0 END",
statistic: "Sum"
},
{
name: "Metamorph",
expression:
"CASE WHEN lifestage = 'metamorph' THEN quantity ELSE 0 END",
statistic: "Sum"
}
]
); I replicated your sample data in the Playground and got your table
... View more
10-09-2025
11:09 AM
|
2
|
1
|
284
|
|
POST
|
You have a typo in line 21 ("iff" instead of "iif") var avg = iif(totalrows == 0, 0, Floor(total / totalrows))
... View more
10-09-2025
07:27 AM
|
1
|
0
|
432
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 3 weeks ago | |
| 2 | 3 weeks ago | |
| 1 | 4 weeks ago | |
| 1 | 4 weeks ago | |
| 1 | a month ago |
| Online Status |
Offline
|
| Date Last Visited |
45m ago
|