<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Arcade: Count days of data collection with Survey123 field app in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1212041#M47853</link>
    <description>&lt;P&gt;This is freaking awesome!&amp;nbsp; Thank you so much for building and sharing this.&amp;nbsp; It has helped me out immensely.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I built some things based on what you have here and couldn't get it work.&lt;/P&gt;&lt;P&gt;So, I basically copied and pasted what you did and made minor changes (changed the date field it is referencing, and called the layer to call upon itself instead of a variable.).&amp;nbsp; I am not getting the same results.&amp;nbsp; Something dealing with the 'responses' variable doesn't seem to be working.&amp;nbsp; Any idea what it may be?&lt;/P&gt;</description>
    <pubDate>Tue, 13 Sep 2022 16:40:43 GMT</pubDate>
    <dc:creator>MosquitoGIS</dc:creator>
    <dc:date>2022-09-13T16:40:43Z</dc:date>
    <item>
      <title>Arcade: Count days of data collection with Survey123 field app</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1201089#M47302</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like help with Arcade, I'm making a Dashboard and I need to count the days that data was collected with Survey123 and show this in a Indicator.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example: in a month I may have 27 surveys, that were collected in 16 days. how can I count this with Arcade?&lt;/P&gt;&lt;P&gt;So for instance in a period of 4 months in which the survey was performed I would like to know how many work days and now many days data was not collected&lt;/P&gt;&lt;P&gt;make sense?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Federico&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/64786"&gt;@GeeFernando&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2022 21:43:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1201089#M47302</guid>
      <dc:creator>FedericoRiet_Sapriza</dc:creator>
      <dc:date>2022-08-09T21:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Count days of data collection with Survey123 field app</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1201196#M47305</link>
      <description>&lt;P&gt;I packed it all in one expression, you will probably have to extract this into multiple expressions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// load your survey
var survey_dict = {geometryType: "", fields: [{name: "DateCollected", type: "esriFieldTypeDate"}], features: [{attributes: {DateCollected: Number(Date(2022,7,1))}},{attributes: {DateCollected: Number(Date(2022,7,1))}},{attributes: {DateCollected: Number(Date(2022,7,2))}},{attributes: {DateCollected: Number(Date(2022,7,3))}},{attributes: {DateCollected: Number(Date(2022,7,3))}},{attributes: {DateCollected: Number(Date(2022,7,4))}},{attributes: {DateCollected: Number(Date(2022,7,4))}},{attributes: {DateCollected: Number(Date(2022,7,4))}},{attributes: {DateCollected: Number(Date(2022,7,6))}},{attributes: {DateCollected: Number(Date(2022,7,6))}},{attributes: {DateCollected: Number(Date(2022,7,8))}},{attributes: {DateCollected: Number(Date(2022,7,8))}},{attributes: {DateCollected: Number(Date(2022,7,10))}},{attributes: {DateCollected: Number(Date(2022,7,11))}},{attributes: {DateCollected: Number(Date(2022,7,11))}},]}
var survey = FeatureSet(Text(survey_dict))
//return survey

//var survey = FeatureSetByName(...)

// optionally, filter the survey
//survey = Filter(survey, "SurveyID IN (1, 2, 3)")

// abort if nothing was found
if(Count(survey) == 0) { return null }

// get first and last date
var first_date = First(OrderBy(survey, "DateCollected")).DateCollected
var last_date = First(OrderBy(survey, "DateCollected DESC")).DateCollected

// get the range in days
var range_days = DateDiff(last_date, first_date, "days") + 1

// get crazy binning the survey resonses into weekdays,
// counting the workdays, and days without response
var weekday_bins = [0, 0, 0, 0, 0, 0, 0]
var workdays = 0
var days_without_response = 0

var current_date = first_date
for(var i = 0; i &amp;lt; range_days; i++) {
    var iso_day = IsoWeekday(current_date)
    var responses = Filter(survey, "DateCollected = @current_date")
    weekday_bins[iso_day-1] += Count(responses)
    workdays += (iso_day &amp;lt; 6)
    days_without_response += (Count(responses) == 0)
    current_date = DateAdd(current_date, 1, "days")
}

var return_lines = [
    `The survey was running from ${Text(first_date, "Y-MM-DD")} to ${Text(last_date, "Y-MM-DD")} (${range_days} days, ${workdays} work days).`,
    `In this time, ${Count(survey)} responses were submitted. There were ${days_without_response} days without response.`,
    `Mo: ${weekday_bins[0]}`,
    `Tu: ${weekday_bins[1]}`,
    `We: ${weekday_bins[2]}`,
    `Th: ${weekday_bins[3]}`,
    `Fr: ${weekday_bins[4]}`,
    `Sa: ${weekday_bins[5]}`,
    `Su: ${weekday_bins[6]}`,
    ]
return Concatenate(return_lines, TextFormatting.NewLine)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;The survey was running from 2022-08-01 to 2022-08-11 (11 days, 9 work days).
In this time, 15 responses were submitted. There were 3 days without response.
Mo: 4
Tu: 1
We: 3
Th: 5
Fr: 0
Sa: 2
Su: 0&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Aug 2022 08:17:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1201196#M47305</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-08-10T08:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Count days of data collection with Survey123 field app</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1202813#M47414</link>
      <description>&lt;P&gt;Awesome, I'll try this and let you know&lt;/P&gt;&lt;P&gt;YOU ROCK!!!&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2022 13:54:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1202813#M47414</guid>
      <dc:creator>FedericoRiet_Sapriza</dc:creator>
      <dc:date>2022-08-15T13:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Count days of data collection with Survey123 field app</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1204033#M47490</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;Johannes,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have been working&amp;nbsp;on expression and I encounter some issues,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I don't have the functions:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;"FeatureSetByName"&lt;/P&gt;&lt;P&gt;or the&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Filter"&lt;/P&gt;&lt;P&gt;these are not available for me, I'm also using the $datapoint.datecollected.&lt;/P&gt;&lt;P&gt;Nevertheless, still not being able not solve this issue.&lt;/P&gt;&lt;P&gt;Thanks again for your time.&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Federico&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2022 01:40:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1204033#M47490</guid>
      <dc:creator>FedericoRiet_Sapriza</dc:creator>
      <dc:date>2022-08-18T01:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Count days of data collection with Survey123 field app</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1212041#M47853</link>
      <description>&lt;P&gt;This is freaking awesome!&amp;nbsp; Thank you so much for building and sharing this.&amp;nbsp; It has helped me out immensely.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I built some things based on what you have here and couldn't get it work.&lt;/P&gt;&lt;P&gt;So, I basically copied and pasted what you did and made minor changes (changed the date field it is referencing, and called the layer to call upon itself instead of a variable.).&amp;nbsp; I am not getting the same results.&amp;nbsp; Something dealing with the 'responses' variable doesn't seem to be working.&amp;nbsp; Any idea what it may be?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 16:40:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1212041#M47853</guid>
      <dc:creator>MosquitoGIS</dc:creator>
      <dc:date>2022-09-13T16:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Count days of data collection with Survey123 field app</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1212536#M47889</link>
      <description>&lt;P&gt;The Filter() function doesn't find anything. I tested with dates without time, so searching for "DateField =&amp;nbsp;@current_date" returned values. If you use a datetime field, that won't work. But of course, datetime fields will be the majority of cases, so&amp;nbsp;&lt;SPAN&gt;I reworked the script.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The main difference: convert the datetime to date, change the Filter() expression:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// What is your datetime field?
var datetime = "Zeitstempel"

// get first and last datetime
var first_datetime = First(OrderBy($layer, datetime))[datetime]
var last_datetime = First(OrderBy($layer, datetime + " DESC"))[datetime]

// convert to date and get number of days
var first_date = Date(Text(first_datetime, "Y-MM-DD"))
var last_date = Date(Text(last_datetime, "Y-MM-DD"))
var days = DateDiff(last_date, first_date, "days") + 1


var workdays = 0
var days_without_response = 0
var weekday_bins = [0, 0, 0, 0, 0, 0, 0]

var current_date = first_date
for(var i = 0; i &amp;lt; days; i++) {
    var next_date = DateAdd(current_date, 1, "days")
    var sql = `${datetime} &amp;gt;= @current_date AND ${datetime} &amp;lt; @next_date`
    var responses = Count(Filter($layer, sql))
    var iso_day = IsoWeekday(current_date)
    weekday_bins[iso_day-1] += responses
    workdays += (iso_day &amp;lt; 6)
    days_without_response += (responses == 0)
    current_date = next_date
}

var return_lines = [
    `The survey was running from ${Text(first_date, "Y-MM-DD")} to ${Text(last_date, "Y-MM-DD")} (${days} days, ${workdays} work days).`,
    `In this time, ${Sum(weekday_bins)} responses were submitted. There were ${days_without_response} days without response.`,
    `Mo: ${weekday_bins[0]}`,
    `Tu: ${weekday_bins[1]}`,
    `We: ${weekday_bins[2]}`,
    `Th: ${weekday_bins[3]}`,
    `Fr: ${weekday_bins[4]}`,
    `Sa: ${weekday_bins[5]}`,
    `Su: ${weekday_bins[6]}`,
    ]
return Concatenate(return_lines, TextFormatting.NewLine)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I tested this with a layer that spans 15 years. The for loop took way too long, so I used a GroupBy to get the count of responses on each distinct date. That massively shortens the for loop but it means that we have to calculate the workdays instead of counting them.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// What is your datetime field?
var datetime = "Zeitstempel"

// get first and last datetime
var first_datetime = First(OrderBy($layer, datetime))[datetime]
var last_datetime = First(OrderBy($layer, datetime + " DESC"))[datetime]

// convert to date and get number of days
var first_date = Date(Text(first_datetime, "Y-MM-DD"))
var last_date = Date(Text(last_datetime, "Y-MM-DD"))
var days = DateDiff(last_date, first_date, "days") + 1

// calculate work days
// can be approximated with Round(days/7*5), but this can be off by several days
var workdays = 0
    // get first monday, add "surplus" work days
var first_monday = first_date
var first_weekday = IsoWeekday(first_date)
if(first_weekday &amp;gt; 1) {
    first_monday = DateAdd(first_date, 8 - first_weekday, "days")
    workdays += Max(6 - first_weekday, 0) 
}
    // get last monday, add "surplus" work days
var last_monday = last_date
var last_weekday = IsoWeekday(last_date)
if(last_weekday &amp;gt; 1) {
    last_monday = DateAdd(last_date, -last_weekday + 1, "days")
    workdays += Min(last_weekday - 1, 4) 
}
    // add 5 workdays for every week, add the last monday
workdays += DateDiff(last_monday, first_monday, "days") / 7 * 5 + 1


// group the featureset by date, get count
// convert to text to remove time
var extract_date_string = `CONCAT(EXTRACT(YEAR FROM ${datetime}), '-', EXTRACT(MONTH FROM ${datetime}), '-', EXTRACT(DAY FROM ${datetime}))`
var grouped_by_date = GroupBy($layer, 
    [{name: "DateString", expression: extract_date_string}],
    [{name: "Count", expression: "1", statistic: "COUNT"}])

// loop through the grouped records and fill weekday bins
var weekday_bins = [0, 0, 0, 0, 0, 0, 0]
for(var row in grouped_by_date) {
    var date_parts = Split(row.DateString, "-")
    var current_date = Date(date_parts[0], date_parts[1]-1, date_parts[2])
    var iso_day = IsoWeekday(current_date)
    weekday_bins[iso_day-1] += row.Count
}

// get total responses and days without response
var responses = Sum(weekday_bins) // same as Count($layer)
var days_without_response = days - Count(grouped_by_date)

// return
var return_lines = [
    `The survey was running from ${Text(first_date, "Y-MM-DD")} to ${Text(last_date, "Y-MM-DD")} (${days} days, ${workdays} work days).`,
    `In this time, ${responses} responses were submitted. There were ${days_without_response} days without response.`,
    `Mo: ${weekday_bins[0]}`,
    `Tu: ${weekday_bins[1]}`,
    `We: ${weekday_bins[2]}`,
    `Th: ${weekday_bins[3]}`,
    `Fr: ${weekday_bins[4]}`,
    `Sa: ${weekday_bins[5]}`,
    `Su: ${weekday_bins[6]}`,
    ]
return Concatenate(return_lines, TextFormatting.NewLine)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1663173789027.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51192iFCFB60F2F95D4876/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1663173789027.png" alt="JohannesLindner_0-1663173789027.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 16:43:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1212536#M47889</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-09-14T16:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Count days of data collection with Survey123 field app</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1212541#M47891</link>
      <description>&lt;P&gt;Excellent!&amp;nbsp; Thank you so much!&amp;nbsp; And I must say your code writing is like an art form!&amp;nbsp; Seriously, incredible!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 17:00:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1212541#M47891</guid>
      <dc:creator>MosquitoGIS</dc:creator>
      <dc:date>2022-09-14T17:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Count days of data collection with Survey123 field app</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1212543#M47892</link>
      <description>&lt;P&gt;And I appreciate the other way you posted as well.&amp;nbsp; As I have one I may be running it on one that has a pretty large amount of data.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 17:02:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1212543#M47892</guid>
      <dc:creator>MosquitoGIS</dc:creator>
      <dc:date>2022-09-14T17:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Count days of data collection with Survey123 field app</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1212548#M47893</link>
      <description>&lt;P&gt;Sorry, completely forgot to answer you. I didn't mean to let you hanging...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The $datapoint global is only available in the advanced formatting of indicators. What exactly are you trying to do?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of what you could do.&lt;/P&gt;&lt;P&gt;Data expression:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// What is your datetime field?
var datetime = "Zeitstempel"

// load data
var p = Portal("...")
var id = "82c62b3205874b139191f6ca0db43ac3"
var lyr = 1
var layer = FeaturesetByPortalItem(p, id, lyr, [datetime], false)

// get first and last datetime
var first_datetime = First(OrderBy(layer, datetime))[datetime]
var last_datetime = First(OrderBy(layer, datetime + " DESC"))[datetime]

// convert to date and get number of days
var first_date = Date(Text(first_datetime, "Y-MM-DD"))
var last_date = Date(Text(last_datetime, "Y-MM-DD"))
var days = DateDiff(last_date, first_date, "days") + 1

// group the featureset by date, get count
// convert to text to remove time
var extract_date_string = `CONCAT(EXTRACT(YEAR FROM ${datetime}), '-', EXTRACT(MONTH FROM ${datetime}), '-', EXTRACT(DAY FROM ${datetime}))`
var grouped_by_date = GroupBy(layer, 
    [{name: "DateString", expression: extract_date_string}],
    [{name: "Count", expression: "1", statistic: "COUNT"}])


// create output featureset
var output_fs = {
    fields: [
        {name: "Date", type: "esriFieldTypeDate"},
        {name: "Responses", type: "esriFieldTypeInteger"},
        {name: "Weekday", type: "esriFieldTypeString"},
        ],
    geometryType: "",
    features: []
}

// fill the output featureset
for(var row in grouped_by_date) {
    var date_parts = Split(row.DateString, "-")
    var current_date = Date(date_parts[0], date_parts[1]-1, date_parts[2])
    var new_feature = {
        attributes: {"Date": Number(current_date), "Responses": row.Count, "Weekday": Text(current_date, "dddd")}
    }
    Push(output_fs.features, new_feature)
}

// return
Featureset(Text(output_fs))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Use that Data Expression in a pie chart (show percentage of responses on each weekday):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1663175206332.png" style="width: 732px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51194i94F80DBAD92573D3/image-dimensions/732x286?v=v2" width="732" height="286" role="button" title="JohannesLindner_1-1663175206332.png" alt="JohannesLindner_1-1663175206332.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 17:07:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1212548#M47893</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-09-14T17:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Count days of data collection with Survey123 field app</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1212557#M47894</link>
      <description>&lt;P&gt;One more quick question if I may ask.&amp;nbsp; I have no problems trying to hash it out, but I figure I would ask in case there is as simple way to do it from what you have already done (as I said, your code writing is like an art form).&amp;nbsp; My ultimate goal is to essentially average out the amount of records a person did a day over a full years worth of data.&amp;nbsp; So, the final result is just one number that shows at the end of the year, this person (based on something like the 'Editor' field) was able to do *said number* a day.&amp;nbsp; Have any suggestions or best practices to pull this off, especially if it was to pull the names dynamically?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 17:18:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1212557#M47894</guid>
      <dc:creator>MosquitoGIS</dc:creator>
      <dc:date>2022-09-14T17:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Count days of data collection with Survey123 field app</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1212781#M47902</link>
      <description>&lt;P&gt;Everything you need is actually already in my scripts, we just need to rearrange a little. You could do something like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// What is your datetime and name field?
var datetime = "AngelegtAm"
var name = "AngelegtVon"

// function to get mean edits per day over the whole period
function total(fs, user) {
    var first_datetime = First(OrderBy(fs, datetime))[datetime]
    var last_datetime = First(OrderBy(fs, datetime + " DESC"))[datetime]
    var first_date = Date(Text(first_datetime, "Y-MM-DD"))
    var last_date = Date(Text(last_datetime, "Y-MM-DD"))
    var days = DateDiff(last_date, first_date, "days") + 1
    var edits = Count(Filter(fs, `${name} = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/591126"&gt;@user&lt;/a&gt;`))
    //return edits / days
    return {edits: edits, days: days, mean: edits/days}
}

// function to get mean edits per day where the user actually edited
function specific(fs, user) {
    var fs = Filter(fs, `${name} = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/591126"&gt;@user&lt;/a&gt;`)
    var extract_date_string = `CONCAT(EXTRACT(YEAR FROM ${datetime}), '-', EXTRACT(MONTH FROM ${datetime}), '-', EXTRACT(DAY FROM ${datetime}))`
    var grouped_by_date = GroupBy(fs, 
        [{name: "DateString", expression: extract_date_string}],
        [{name: "Count", expression: "1", statistic: "COUNT"}])
    var edits = Sum(grouped_by_date, "Count")
    var days = Count(grouped_by_date)
    //return edits / days
    return {edits: edits, days: days, mean: edits/days}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To show the difference between the functions:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Load data
var p = Portal("...")
var id = "b19c6cfbacaf46489495b5b896ad9490"
var lyr = 16
var layer = FeaturesetByPortalItem(p, id, lyr, [datetime, name], false)
layer = Filter(layer, `${name} IS NOT NULL AND ${datetime} IS NOT NULL`)

// get users
var users = Distinct(layer, name)

// create output featureset
var output_fs = {
    fields: [
        {name: "User", type: "esriFieldTypeString"},
        {name: "TotalDays", type: "esriFieldTypeInteger"},
        {name: "SpecDays", type: "esriFieldTypeInteger"},
        {name: "Edits", type: "esriFieldTypeInteger"},
        {name: "TotalMean", type: "esriFieldTypeDouble"},
        {name: "SpecMean", type: "esriFieldTypeDouble"},
        ],
    geometryType: "",
    features: []
}

// fill the output featureset
for(var user in users) {
    var total_mean = total(layer, user[name])
    var spec_mean = specific(layer, user[name])
    var new_feature = {
        attributes: {
            User: user[name],
            Edits: total_mean.edits,
            TotalDays: total_mean.days,
            SpecDays: spec_mean.days,
            TotalMean: total_mean.mean,
            SpecMean: spec_mean.mean
        }}
    Push(output_fs.features, new_feature)
}

// return
Featureset(Text(output_fs))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1663220855398.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/51256i80C451DA1F85A5DF/image-size/large?v=v2&amp;amp;px=999" role="button" title="JohannesLindner_1-1663220855398.png" alt="JohannesLindner_1-1663220855398.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 05:48:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1212781#M47902</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-09-15T05:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Count days of data collection with Survey123 field app</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1213095#M47928</link>
      <description>&lt;P&gt;Thanks, I will be scouring over this code learning.&amp;nbsp; You seriously have been extremely helpful.&lt;BR /&gt;&lt;BR /&gt;One more question for you if you are willing, how is it the you work with or handle nulls?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 19:14:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1213095#M47928</guid>
      <dc:creator>MosquitoGIS</dc:creator>
      <dc:date>2022-09-15T19:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Count days of data collection with Survey123 field app</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1213351#M47940</link>
      <description>&lt;P&gt;In this example, I excluded records with nulls in the user or date field from the input data, see line 6:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;layer = Filter(layer, `${name} IS NOT NULL AND ${datetime} IS NOT NULL`)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As this problem is all about working with dates, we have to exclude null values in the date field. But it could be interesting to know about null values in the user field. For that, we have to change the filter inside the function according to whether the user argument is null or not:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function specific(fs, user) {
    var sql = `${datetime} IS NOT NULL AND ${name} = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/591126"&gt;@user&lt;/a&gt;`
    if(user == null) {
        sql = `${datetime} IS NOT NULL AND ${name} IS NULL`
    }
    var fs = Filter(fs, sql)
    var extract_date_string = `CONCAT(EXTRACT(YEAR FROM ${datetime}), '-', EXTRACT(MONTH FROM ${datetime}), '-', EXTRACT(DAY FROM ${datetime}))`
    var grouped_by_date = GroupBy(fs, 
        [{name: "DateString", expression: extract_date_string}],
        [{name: "Count", expression: "1", statistic: "COUNT"}])
    var edits = Sum(grouped_by_date, "Count")
    var days = Count(grouped_by_date)
    //return edits / days
    return {edits: edits, days: days, mean: edits/days}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you use the editor tracking fields for this, you won't get any meaningful results, because when the user field is empty, the date field will obviously be empty, too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 11:55:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1213351#M47940</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-09-16T11:55:23Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Count days of data collection with Survey123 field app</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1213384#M47942</link>
      <description>&lt;P&gt;Awesome, thank you so much!&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 13:33:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-count-days-of-data-collection-with/m-p/1213384#M47942</guid>
      <dc:creator>MosquitoGIS</dc:creator>
      <dc:date>2022-09-16T13:33:50Z</dc:date>
    </item>
  </channel>
</rss>

