@ScottJones1 I think you will need a new expression for this as I am not sure counting the days will work since you can have multiple entries per day. Another way of handling it would be to get the earliest submission and the last submission on an incident basis and then take the difference between those two dates for your duration.
var portal = Portal('https://www.arcgis.com');
var layer = FeatureSetByPortalItem(portal, itemId, layerIndex, [dateField, groupField]);
var groups = Distinct(layer, [groupField]);
var features = [];
for (var g in groups) {
var groupValue = g[groupField];
if (IsEmpty(groupValue)) continue;
var filtered = Filter(layer, groupField + " = @groupValue");
var start = First(Top(OrderBy(filtered, dateField + ' ASC'), 1));
var end = First(Top(OrderBy(filtered, dateField + ' DESC'), 1));
Push(features, {
attributes: {
Group: groupValue,
StartDate: start[dateField],
EndDate: end[dateField],
Duration: DateDiff(end[dateField], start[dateField], 'days')
}
});
}
return FeatureSet(Text({
fields: [
{ name: "Group", type: "esriFieldTypeString" },
{ name: "StartDate", type: "esriFieldTypeDate" },
{ name: "EndDate", type: "esriFieldTypeDate" },
{ name: "Duration", type: "esriFieldTypeDouble" }
],
geometryType: "",
features: features
}));
@ScottJones1 There were quotes missing from the field names:
var portal = Portal('https://www.arcgis.com');
var layer = FeatureSetByPortalItem(portal, itemId, layerIndex, ['date_of_event', 'Incident_']);
var groups = Distinct(layer, ['Incident_']);
var features = [];
for (var g in groups) {
var groupValue = g['Incident_'];
if (IsEmpty(groupValue)) continue;
var filtered = Filter(layer, 'Incident_' + " = @groupValue");
var start = First(Top(OrderBy(filtered, 'date_of_event' + ' ASC'), 1));
var end = First(Top(OrderBy(filtered, 'date_of_event' + ' DESC'), 1));
Push(features, {
attributes: {
Group: groupValue,
StartDate: start['date_of_event'],
EndDate: end['date_of_event'],
Duration: DateDiff(end['date_of_event'], start['date_of_event'], 'days')
}
});
}
return FeatureSet(Text({
fields: [
{ name: "Group", type: "esriFieldTypeString" },
{ name: "StartDate", type: "esriFieldTypeDate" },
{ name: "EndDate", type: "esriFieldTypeDate" },
{ name: "Duration", type: "esriFieldTypeDouble" }
],
geometryType: "",
features: features
}));
Also I assume you left the itemid and layer index out on purpose, but be sure those are correct.
no, not sure where I locate the itmeid and layer index
77fb11f20f7f4b689d38258d3b5b0f43&sublayer=0#data this is what I see when I click the field
77fb11f20f7f4b689d38258d3b5b0f43 this is for the entire layer... I entered this in for itemId, 0, not sure what to enter for LayerIndex
var layer = FeatureSetByPortalItem(portal, itemId, layerIndex, ['date_of_event', 'Incident_']);
Neal, could you take one more look? I am getting the same numbers pre advanced formula, (before it was a blank screen) with the triangle !. Then 'Need' in Incident Reference should only be counting 2 days, it has multiple entries on 10/7 and only 1 entry on 10/8 but it is counting all entries. Could it be, that I do not have a time attached to the Survey123 Connect? for my entries, the time is not important but if it would make the formula I can add it..
@ScottJones1 I think you are still in the advanced editor, that code is for a new data expression which is basically making a new feature set from your existing data.
1. Add a new table to your dashboard.
2. when it asks where to get data from, click the new data expression button.
3: Paste the code, and hit "run" to test. That should be a example of your new table.
so close, if there are two or more entries sequentially, I think it would work. However if there is only one entry it comes out as Zero, if there are missing days (which there most likely will be a few) it counts those as part of the time on INC.. in the example below, an entry was made on the 3rd and not again until the 7th, but the table counts all the dates in-between.
If you have an idea, feel free to share, if not, I'll keep an eye out for a work around..