<?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: Calculating changes in a feature over different dates in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-changes-in-a-feature-over-different/m-p/1238610#M7064</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;&amp;nbsp;I think you may be right that there could be a date issue in line 63 as my &lt;EM&gt;datecount_&lt;/EM&gt; field has both time and date and there could be more than one count a day (as I discovered) and I think there is an issue with some date expressions if the hours and minutes is Not Null.&amp;nbsp; I get a message &lt;STRONG&gt;&lt;SPAN class=""&gt;Execution Error:&lt;/SPAN&gt;Invalid data type for expression [date '2022-09-15 14:56:00']&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Ironically this is not the first record in the table. Is there an issue if there is no previous count?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LenOlyottBrisbane_1-1670392681346.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/57835i4D471B4A1CB81B05/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LenOlyottBrisbane_1-1670392681346.png" alt="LenOlyottBrisbane_1-1670392681346.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does '&lt;EM&gt;Between&lt;/EM&gt; Date1 &lt;EM&gt;and&lt;/EM&gt; Date2' work from an SQL point of view?&lt;/P&gt;&lt;P&gt;Substituting my real fieldnames into the expression,&lt;/P&gt;&lt;P&gt;// load the count fs&lt;BR /&gt;var portal = Portal('&lt;A href="https://XXXXX/portal/" target="_blank" rel="noopener"&gt;https://XXXXX/portal/&lt;/A&gt;');&lt;BR /&gt;var count_fs = FeatureSetByPortalItem(&lt;BR /&gt;portal,&lt;BR /&gt;'YYYYYYYYYYYYYYY',&lt;BR /&gt;0,&lt;BR /&gt;[&lt;BR /&gt;'datetime_count',&lt;BR /&gt;'field_11',&lt;BR /&gt;'sandbag_outside',&lt;BR /&gt;'sandbag_insde',&lt;BR /&gt;'total_note',&lt;BR /&gt;],&lt;BR /&gt;false&lt;BR /&gt;);&lt;BR /&gt;//return count_fs&lt;/P&gt;&lt;P&gt;// load the production fs&lt;BR /&gt;var production_fs = FeatureSetByPortalItem(&lt;BR /&gt;portal,&lt;BR /&gt;'ZZZZZZZZZZZZ',&lt;BR /&gt;0,&lt;BR /&gt;[&lt;BR /&gt;'datetime_',&lt;BR /&gt;'depot_',&lt;BR /&gt;'produced_sandbag',&lt;BR /&gt;],&lt;BR /&gt;false&lt;BR /&gt;);&lt;BR /&gt;//return production_fs&lt;/P&gt;&lt;P&gt;// create the output dict&lt;BR /&gt;var out = {&lt;BR /&gt;fields: [&lt;BR /&gt;{name: "DateOfCount", type: "esriFieldTypeDate"},&lt;BR /&gt;{name: "Depot", type: "esriFieldTypeString"},&lt;BR /&gt;{name: "Count", type: "esriFieldTypeInteger"},&lt;BR /&gt;{name: "Taken", type: "esriFieldTypeInteger"},&lt;BR /&gt;{name: "Produced", type: "esriFieldTypeInteger"},&lt;BR /&gt;],&lt;BR /&gt;features: [],&lt;BR /&gt;geometryType: ""&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// loop over depots&lt;BR /&gt;var depots = ["DARRA", "LOTA", "MORNINGSIDE", "NEWMARKET", "ZILLMERE"]&lt;BR /&gt;for(var d in depots) {&lt;BR /&gt;// find all counts of the depot and order by date&lt;BR /&gt;var depot = depots[d]&lt;BR /&gt;var depot_count_fs = Filter(count_fs, "field_11 = @depot")&lt;BR /&gt;depot_count_fs = OrderBy(depot_count_fs, "&lt;EM&gt;datetime_count&lt;/EM&gt;")&lt;BR /&gt;// loop over depot_count_fs&lt;BR /&gt;var previous_depot_count = First(depot_count_fs)&lt;BR /&gt;for(var depot_count in depot_count_fs) {&lt;BR /&gt;// find all entries in the production_fs between now and the previous count date&lt;BR /&gt;var start_date = previous_depot_count.datetime_count&lt;BR /&gt;var end_date = depot_count.datetime_count&lt;BR /&gt;var production_between_dates = Filter(production_fs, "depot_ = @depot AND &lt;EM&gt;datetime_&lt;/EM&gt;&amp;nbsp;&amp;gt; @start_date AND datetime_ &amp;lt;= @end_date")&lt;BR /&gt;// calculate the values&lt;BR /&gt;var current_count = depot_count.total_note&lt;BR /&gt;var produced = Sum(production_between_dates, "produced_sandbag")&lt;BR /&gt;var taken = previous_depot_count.total_note + produced - current_count&lt;BR /&gt;// append new feature&lt;BR /&gt;Push(out.features, {attributes: {DateOfCount: Number(depot_count.datetime_count), Depot: field_11, Count: current_count, Taken: taken, Produced: produced}})&lt;BR /&gt;// set previous&lt;BR /&gt;previous_depot_count = depot_count&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;return Featureset(Text(out))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again, I feel that I am nearly there after a week of trying.&lt;/P&gt;</description>
    <pubDate>Wed, 07 Dec 2022 05:58:46 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2022-12-07T05:58:46Z</dc:date>
    <item>
      <title>Calculating changes in a feature over different dates</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-changes-in-a-feature-over-different/m-p/1238122#M7059</link>
      <description>&lt;P&gt;So this is potentially not possible to do with a data expression but I really do not know as this seems to be quite a complex calculation.&lt;/P&gt;&lt;P&gt;Consider the following table of daily sandbag counts. We are trying to dynamically count the &lt;STRONG&gt;Sandbags Taken&lt;/STRONG&gt; figure based on data collected using a Survey123 count. There are 5 depots. I have been able to create a data expression that reports the latest count by depot and can use the Sum statistic on a gauge indicator to get the total current count. I am assuming that if I had the &lt;STRONG&gt;Sandbags Taken&lt;/STRONG&gt; figure for each depot, I could do the same and get the grand total.&lt;/P&gt;&lt;P&gt;This next bit requires calculating totals for the last two dates (counts are not always daily and could be weeks apart hence needing Max(Date) and Max(Date)-1 or similar) and subtracting the total counts to calculate how many have been taken. For a bonus bit of difficulty, ideally we include the daily production figure (but currently this is in a different dataset to add a bit of complexity).&lt;/P&gt;&lt;P&gt;I would appreciate any thoughts on this, table below for (hopefully) some clarity.&lt;/P&gt;&lt;P&gt;The other alternative approach could be with Python to populate fields in the feature layer itself if a Data Expression is not going to cut it.&lt;/P&gt;&lt;P&gt;thanks in advance,&lt;/P&gt;&lt;P&gt;Len&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="100"&gt;&lt;P&gt;DateOfCount&lt;/P&gt;&lt;/TD&gt;&lt;TD width="58"&gt;&lt;P&gt;Depot&lt;/P&gt;&lt;/TD&gt;&lt;TD width="58"&gt;&lt;P&gt;Count&lt;/P&gt;&lt;/TD&gt;&lt;TD width="305"&gt;&lt;P&gt;Taken (calculated)&lt;/P&gt;&lt;/TD&gt;&lt;TD width="79"&gt;&lt;P&gt;Produced&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="100"&gt;&lt;P&gt;1/11/2022&lt;/P&gt;&lt;/TD&gt;&lt;TD width="58"&gt;&lt;P&gt;A&lt;/P&gt;&lt;/TD&gt;&lt;TD width="58"&gt;&lt;P&gt;100&lt;/P&gt;&lt;/TD&gt;&lt;TD width="305"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="79"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="100"&gt;&lt;P&gt;2/11/2022&lt;/P&gt;&lt;/TD&gt;&lt;TD width="58"&gt;&lt;P&gt;A&lt;/P&gt;&lt;/TD&gt;&lt;TD width="58"&gt;&lt;P&gt;50&lt;/P&gt;&lt;/TD&gt;&lt;TD width="305"&gt;&lt;P&gt;50 (count Date1 – countDate2)&lt;/P&gt;&lt;/TD&gt;&lt;TD width="79"&gt;&lt;P&gt;150&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="100"&gt;&lt;P&gt;3/11/2022&lt;/P&gt;&lt;/TD&gt;&lt;TD width="58"&gt;&lt;P&gt;A&lt;/P&gt;&lt;/TD&gt;&lt;TD width="58"&gt;&lt;P&gt;150&lt;/P&gt;&lt;/TD&gt;&lt;TD width="305"&gt;&lt;P&gt;50 (CountDate2+ProductionDate1-CountDate3)&lt;/P&gt;&lt;/TD&gt;&lt;TD width="79"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="100"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="58"&gt;&lt;P&gt;B&lt;/P&gt;&lt;/TD&gt;&lt;TD width="58"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="305"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="79"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="100"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="58"&gt;&lt;P&gt;B&lt;/P&gt;&lt;/TD&gt;&lt;TD width="58"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="305"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="79"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="100"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="58"&gt;&lt;P&gt;B&lt;/P&gt;&lt;/TD&gt;&lt;TD width="58"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="305"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="79"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 06 Dec 2022 07:31:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-changes-in-a-feature-over-different/m-p/1238122#M7059</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-12-06T07:31:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating changes in a feature over different dates</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-changes-in-a-feature-over-different/m-p/1238150#M7061</link>
      <description>&lt;P&gt;It is absolutely possible.&lt;/P&gt;&lt;P&gt;I changed your example table to reflect that the counts are not taken daily. I used the same values for depots A and B:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_4-1670317581961.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/57731i194B0B198B74B80F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_4-1670317581961.png" alt="JohannesLindner_4-1670317581961.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the production, I just assumed that depot A fills 10 sandbags per day, while depot B manages to fill 20.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_3-1670317519975.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/57730i592CF383D68BDE08/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_3-1670317519975.png" alt="JohannesLindner_3-1670317519975.png" /&gt;&lt;/span&gt;&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;LI-CODE lang="javascript"&gt;// load the count fs
var count_fs = Featureset(Text({
    fields: [
        {name: "DateOfCount", type: "esriFieldTypeDate"},
        {name: "Depot", type: "esriFieldTypeString"},
        {name: "Count", type: "esriFieldTypeInteger"},
        ],
    features: [
        {attributes: {DateOfCount: Number(Date(2022,11,1)), Depot: "A", Count: 100}},
        {attributes: {DateOfCount: Number(Date(2022,11,6)), Depot: "A", Count: 50}},
        {attributes: {DateOfCount: Number(Date(2022,11,22)), Depot: "A", Count: 150}},
        {attributes: {DateOfCount: Number(Date(2022,11,1)), Depot: "B", Count: 100}},
        {attributes: {DateOfCount: Number(Date(2022,11,6)), Depot: "B", Count: 50}},
        {attributes: {DateOfCount: Number(Date(2022,11,22)), Depot: "B", Count: 150}},
        ],
    geometryType: ""
}))
//return count_fs

// load the production fs
var production_fs = {
    fields: [
        {name: "DateOfProduction", type: "esriFieldTypeDate"},
        {name: "Depot", type: "esriFieldTypeString"},
        {name: "Count", type: "esriFieldTypeInteger"},
        ],
    features: [],
    geometryType: ""
}
for(var i = 0; i &amp;lt; 30; i++) {
    Push(production_fs.features, {attributes: {DateOfProduction: Number(DateAdd(Date(2022,11,1), i, "days")), Depot: "A", Count: 10}})
    Push(production_fs.features, {attributes: {DateOfProduction: Number(DateAdd(Date(2022,11,1), i, "days")), Depot: "B", Count: 20}})
}
production_fs = Featureset(Text(production_fs))
//return production_fs


// create the output dict
var out = {
    fields: [
        {name: "DateOfCount", type: "esriFieldTypeDate"},
        {name: "Depot", type: "esriFieldTypeString"},
        {name: "Count", type: "esriFieldTypeInteger"},
        {name: "Taken", type: "esriFieldTypeInteger"},
        {name: "Produced", type: "esriFieldTypeInteger"},
        ],
    features: [],
    geometryType: ""
}

// loop over depots
var depots = ["A", "B"]
for(var d in depots) {
    // find all counts of the depot and order by date
    var depot = depots[d]
    var depot_count_fs = Filter(count_fs, "Depot = @depot")
    depot_count_fs = OrderBy(depot_count_fs, "DateOfCount")
    // loop over depot_count_fs
    var previous_depot_count = First(depot_count_fs)
    for(var depot_count in depot_count_fs) {
        // find all entries in the production_fs between now and the previous count date
        var start_date = previous_depot_count.DateOfCount
        var end_date = depot_count.DateOfCount
        var production_between_dates = Filter(production_fs, "Depot = @depot AND DateOfProduction &amp;gt; @start_date AND DateOfProduction &amp;lt;= @end_date")
        // calculate the values
        var current_count = depot_count.Count
        var produced = Sum(production_between_dates, "Count")
        var taken = previous_depot_count.Count + produced - current_count
        // append new feature
        Push(out.features, {attributes: {DateOfCount: Number(depot_count.DateOfCount), Depot: depot, Count: current_count, Taken: taken, Produced: produced}})
        // set previous
        previous_depot_count = depot_count
    }
}
return Featureset(Text(out))&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_5-1670317869128.png" style="width: 640px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/57732iAE89C997141550F5/image-dimensions/640x200?v=v2" width="640" height="200" role="button" title="JohannesLindner_5-1670317869128.png" alt="JohannesLindner_5-1670317869128.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The "Taken" and "Produced" columns list the sandbags that were taken and produced between the current and the previous count.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lines 1-35 define the sample data. They should of course be replaced with code loading your actual data sets.&lt;/P&gt;&lt;P&gt;Depending on your database and date format, you might have to change the sql clause in line 64.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2022 09:14:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-changes-in-a-feature-over-different/m-p/1238150#M7061</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-12-06T09:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating changes in a feature over different dates</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-changes-in-a-feature-over-different/m-p/1238610#M7064</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;&amp;nbsp;I think you may be right that there could be a date issue in line 63 as my &lt;EM&gt;datecount_&lt;/EM&gt; field has both time and date and there could be more than one count a day (as I discovered) and I think there is an issue with some date expressions if the hours and minutes is Not Null.&amp;nbsp; I get a message &lt;STRONG&gt;&lt;SPAN class=""&gt;Execution Error:&lt;/SPAN&gt;Invalid data type for expression [date '2022-09-15 14:56:00']&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Ironically this is not the first record in the table. Is there an issue if there is no previous count?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LenOlyottBrisbane_1-1670392681346.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/57835i4D471B4A1CB81B05/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LenOlyottBrisbane_1-1670392681346.png" alt="LenOlyottBrisbane_1-1670392681346.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does '&lt;EM&gt;Between&lt;/EM&gt; Date1 &lt;EM&gt;and&lt;/EM&gt; Date2' work from an SQL point of view?&lt;/P&gt;&lt;P&gt;Substituting my real fieldnames into the expression,&lt;/P&gt;&lt;P&gt;// load the count fs&lt;BR /&gt;var portal = Portal('&lt;A href="https://XXXXX/portal/" target="_blank" rel="noopener"&gt;https://XXXXX/portal/&lt;/A&gt;');&lt;BR /&gt;var count_fs = FeatureSetByPortalItem(&lt;BR /&gt;portal,&lt;BR /&gt;'YYYYYYYYYYYYYYY',&lt;BR /&gt;0,&lt;BR /&gt;[&lt;BR /&gt;'datetime_count',&lt;BR /&gt;'field_11',&lt;BR /&gt;'sandbag_outside',&lt;BR /&gt;'sandbag_insde',&lt;BR /&gt;'total_note',&lt;BR /&gt;],&lt;BR /&gt;false&lt;BR /&gt;);&lt;BR /&gt;//return count_fs&lt;/P&gt;&lt;P&gt;// load the production fs&lt;BR /&gt;var production_fs = FeatureSetByPortalItem(&lt;BR /&gt;portal,&lt;BR /&gt;'ZZZZZZZZZZZZ',&lt;BR /&gt;0,&lt;BR /&gt;[&lt;BR /&gt;'datetime_',&lt;BR /&gt;'depot_',&lt;BR /&gt;'produced_sandbag',&lt;BR /&gt;],&lt;BR /&gt;false&lt;BR /&gt;);&lt;BR /&gt;//return production_fs&lt;/P&gt;&lt;P&gt;// create the output dict&lt;BR /&gt;var out = {&lt;BR /&gt;fields: [&lt;BR /&gt;{name: "DateOfCount", type: "esriFieldTypeDate"},&lt;BR /&gt;{name: "Depot", type: "esriFieldTypeString"},&lt;BR /&gt;{name: "Count", type: "esriFieldTypeInteger"},&lt;BR /&gt;{name: "Taken", type: "esriFieldTypeInteger"},&lt;BR /&gt;{name: "Produced", type: "esriFieldTypeInteger"},&lt;BR /&gt;],&lt;BR /&gt;features: [],&lt;BR /&gt;geometryType: ""&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// loop over depots&lt;BR /&gt;var depots = ["DARRA", "LOTA", "MORNINGSIDE", "NEWMARKET", "ZILLMERE"]&lt;BR /&gt;for(var d in depots) {&lt;BR /&gt;// find all counts of the depot and order by date&lt;BR /&gt;var depot = depots[d]&lt;BR /&gt;var depot_count_fs = Filter(count_fs, "field_11 = @depot")&lt;BR /&gt;depot_count_fs = OrderBy(depot_count_fs, "&lt;EM&gt;datetime_count&lt;/EM&gt;")&lt;BR /&gt;// loop over depot_count_fs&lt;BR /&gt;var previous_depot_count = First(depot_count_fs)&lt;BR /&gt;for(var depot_count in depot_count_fs) {&lt;BR /&gt;// find all entries in the production_fs between now and the previous count date&lt;BR /&gt;var start_date = previous_depot_count.datetime_count&lt;BR /&gt;var end_date = depot_count.datetime_count&lt;BR /&gt;var production_between_dates = Filter(production_fs, "depot_ = @depot AND &lt;EM&gt;datetime_&lt;/EM&gt;&amp;nbsp;&amp;gt; @start_date AND datetime_ &amp;lt;= @end_date")&lt;BR /&gt;// calculate the values&lt;BR /&gt;var current_count = depot_count.total_note&lt;BR /&gt;var produced = Sum(production_between_dates, "produced_sandbag")&lt;BR /&gt;var taken = previous_depot_count.total_note + produced - current_count&lt;BR /&gt;// append new feature&lt;BR /&gt;Push(out.features, {attributes: {DateOfCount: Number(depot_count.datetime_count), Depot: field_11, Count: current_count, Taken: taken, Produced: produced}})&lt;BR /&gt;// set previous&lt;BR /&gt;previous_depot_count = depot_count&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;return Featureset(Text(out))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again, I feel that I am nearly there after a week of trying.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 05:58:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-changes-in-a-feature-over-different/m-p/1238610#M7064</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-12-07T05:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating changes in a feature over different dates</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-changes-in-a-feature-over-different/m-p/1238725#M7066</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;Does '&lt;/SPAN&gt;&lt;EM&gt;Between&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;Date1&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;and&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;Date2' work from an SQL point of view?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;BETWEEN does work, but it includes both the start and end date, so the production values from days where you have a depot count are counted twice: once for the current count feature and once for the next. At least that's with only date values...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;Ironically this is not the first record in the table.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;No, but it is the first record that gets processed, because DARRA is the first depot.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;There shouldn't be problems if there is no previous count, if there are multiple counts on the same day, or if there is time involved. I didn't mean to prove against those cases, but apparently I did...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I think Arcade doesn't like the SQL query. You will probably have to write it yourself, without using the&amp;nbsp;@ notation.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;One of these might work:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Define the sql query (using one of the methods below)

// use string
var df = "Y-MM-DD HH:mm:ss"
var sql_query = `depot_ = '${depot}' AND datetime_ &amp;gt; '${Text(start_date, df)}' AND datetime_ &amp;lt;= '${Text(end_date, df)}'`

// convert to sql DATE
var df = "Y-MM-DD HH:mm:ss"
var sql_query = `depot_ = '${depot}' AND datetime_ &amp;gt; date '${Text(start_date, df)}' AND datetime_ &amp;lt;= date '${Text(end_date, df)}'`

// switch to full days, this might lead to small errors, like production only being applied to the next period
var df = "Y-MM-DD"
var sql_query = `depot_ = '${depot}' AND datetime_ &amp;gt; '${Text(start_date, df)}' AND datetime_ &amp;lt;= '${Text(end_date, df)}'`
var sql_query = `depot_ = '${depot}' AND datetime_ &amp;gt; date '${Text(start_date, df)}' AND datetime_ &amp;lt;= date '${Text(end_date, df)}'`


// use it
var production_between_dates = Filter(production_fs, sql_query)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If none of these work, I'd need access to the actual data to help further. Either send a public link to the service or send me the tables in a pm.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 14:29:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-changes-in-a-feature-over-different/m-p/1238725#M7066</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-12-07T14:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating changes in a feature over different dates</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-changes-in-a-feature-over-different/m-p/1238952#M7071</link>
      <description>&lt;P&gt;Thanks so much for all your invaluable advice. I will give it a go and let you know how I get on.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 22:47:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/calculating-changes-in-a-feature-over-different/m-p/1238952#M7071</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-12-07T22:47:33Z</dc:date>
    </item>
  </channel>
</rss>

