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
Thursday
|
1
|
1
|
139
|
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
Thursday
|
2
|
1
|
91
|
POST
|
You have a typo in line 21 ("iff" instead of "iif") var avg = iif(totalrows == 0, 0, Floor(total / totalrows))
... View more
a week ago
|
1
|
0
|
154
|
POST
|
When posting code, please use the "Insert/edit code sample" button. It make it easier to read your code and refer to specific lines. There are a couple of things going on with your code. You have to convert the text to a valid date. Your current code will return a null. The Count function works on arrays, not values, which is what's throwing the error. You want to get the running total of differences and calculate the average outside the loop. You'll have to return a FeatureSet in a Data Expression for an Indicator. Most of these were covered in my reply to your previous post. Give this a try var portal_ = Portal("https://arcgis.com");
var fs = FeatureSetByPortalItem(portal_, "Item ID", 0, ["*"], false);
function StringToDate(input) {
var arr = Split(input, "/");
return Date(arr[2], arr[0] - 1, arr[1]);
}
var total;
for (var f in fs) {
var date_Applied = f["Applied_Date"];
var date_Issued = f["Issued_Date"];
var startDate = DateOnly(StringToDate(date_Applied));
var endDate = DateOnly(StringToDate(date_Issued));
var differences = DateDiff(startDate, endDate, "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: { Days: avg } }]
}
);
... View more
a week ago
|
1
|
2
|
189
|
POST
|
When building the date, just insert a variable for the year var time = Now();
var time3 = Text(Now(), "MMMM DD, YYYY");
var thisYear = Year(Now());
if (time >= Date(thisYear, 7, 1) && time < Date(thisYear, 8, 1)) {
return $feature["August"];
}
... View more
a week ago
|
2
|
1
|
63
|
POST
|
I've used your layers in a map and it works as expected. The code I'm using is var fs = FeatureSetByName($map, "Lawrence Zoning District", ["ZoningDistrict"]);
var WithinFS = Within($feature, fs);
iif(
Count(WithinFS) == 0,
"Not in a zoning district.",
First(WithinFS).ZoningDistrict
); which returns this when run in the text editor (using iif to return a message if there are no features returned by the Within) and this in the popup ("R-2", circled in red)
... View more
a week ago
|
0
|
1
|
122
|
POST
|
It doesn't matter if you have the layer within a group layer. This works on a test I set up. var fs = FeatureSetByName($map, "USA Census States")
var output = Within($feature,FS)
return {
type : 'text',
text : first(output).STATE_NAME
} Did you test the code on an actual feature in the Zoning District? Running the code in the editor will use the first feature in the FeatureSet, which may or may not give you a feature within the Zoning District layer. You can use a feature you know will work by filtering the parcel to a specific one. In my example, I can filter the earthquakes to a specific event to test it out. This code var feat = First(Filter($layer, "id = 'mb90114598'"))
var fs = FeatureSetByName($map, "USA Census States")
var output = Within(feat,FS)
return output
return {
type : 'text',
text : first(output).STATE_NAME
} returns this The code in your latest post fails because you're supplying an incorrect name for the FeatureSetByName function, which returns a null. When used in the WIthin function, it's being interpreted as a null feature in the Geometry Within function (which returns a boolean) instead of the FeatureSet Within function (which returns a FeatureSet)
... View more
a week ago
|
0
|
5
|
142
|
POST
|
You can see all the icons on the Calcite Design System's Icon page
... View more
2 weeks ago
|
0
|
1
|
151
|
POST
|
Lines 20 tests whether a relationship exists, not whether there are records in the relationship. The code fails when you try to access a field from a null in line 22 You'll have to test whether that relationship has any records. if (Count(related_site) > 0) {
... View more
2 weeks ago
|
1
|
0
|
90
|
POST
|
Chrome (140.0.7339.186) and Firefox (143.0.1) work, but Edge (140.0.3485.81) doesn't for me.
... View more
3 weeks ago
|
0
|
0
|
65
|
POST
|
Here's one way to calculate the difference (this shows the number of days since the beginning of the year). Note that the month number in the Date function is 0-based (0 is January) function StringToDate(input) {
var arrDate = Split(input, "/");
return Date(arrDate[2], arrDate[1] - 1, arrDate[0]);
}
var date1 = "01/01/2025";
var date2 = Text(Now(), "DD/MM/Y"); //gives today's date as dd/mm/yyyy
Floor(DateDiff(StringToDate(date2), StringToDate(date1), "days")); If your goal is to put this number into an indicator, then you have to return a FeatureSet containing that number function StringToDate(input) {
var arrDate = Split(input, "/");
return Date(arrDate[2], arrDate[1] - 1, arrDate[0]);
}
var date1 = "01/01/2025";
var date2 = Text(Now(), "DD/MM/Y"); //gives today's date as dd/mm/yyyy
var days = Floor(DateDiff(StringToDate(date2), StringToDate(date1), "days"));
return FeatureSet(
{
fields: [{ name: "Days", type: "esriFieldTypeInteger" }],
features: [{ attributes: { Days: days } }]
}
);
... View more
3 weeks ago
|
0
|
0
|
173
|
POST
|
First, check all the field names. I may have overlooked changing one back to your schema. Click the Run button in the Arcade editor to see if it's returning a FeatureSet. Add some Console messages to see what the code is doing a various intervals. This should help you figure out what's going wrong.
... View more
3 weeks ago
|
0
|
2
|
135
|
Title | Kudos | Posted |
---|---|---|
2 | Thursday | |
1 | Thursday | |
1 | a week ago | |
1 | a week ago | |
2 | a week ago |
Online Status |
Online
|
Date Last Visited |
4 hours ago
|