<?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: ArcGIS Dashboard-Arcade Expressions (Math) in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287435#M7783</link>
    <description>&lt;P&gt;I'm not sure how you ended up with that expression. The FeatureSetByPortalItem function requires you to specify the layer index, and it won't get past the second line as its written. Even if it did, it needs to return a FeatureSet object.&lt;/P&gt;&lt;P&gt;The way Data Expressions work is a bit different from other Arcade profiles. If you haven't yet, take a look at some of the expressions here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/arcade-expressions/tree/master/dashboard_data" target="_blank"&gt;https://github.com/Esri/arcade-expressions/tree/master/dashboard_data&lt;/A&gt;&lt;/P&gt;&lt;P&gt;In particular, note how you need to first define a dictionary with the fields defined and an empty array for the features. Then you need to loop through every feature in your FeatureSet to push attributes to that dictionary. It will look very different from what you have posted.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var portal = Portal('https://www.arcgis.com');

var fs = FeatureSetByPortalItem(
    portal,
    'fcb8c011c9f44ad09e735683da808b41',
    0,
    ['some_field'],
    false
);

var out_dict = {
    fields: [
        {name: 'some_field', type: 'esriFieldTypeInteger'},
        {name: 'difference_from_last', type: 'esriFieldTypeInteger'}],
    geometryType: '',
    features: []
}

var prev_val = 0

for (var f in fs) {
    Push(
        out_dict['features'],
        {
            attributes: {
                some_field: f['some_field'],
                difference_from_last: f['some_field'] - prev_val
            }
        }
    )
    
    prev_val = f['some_field']
}

return FeatureSet(Text(out_dict))&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 09 May 2023 20:00:31 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2023-05-09T20:00:31Z</dc:date>
    <item>
      <title>ArcGIS Dashboard-Arcade Expressions (Math)</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287291#M7777</link>
      <description>&lt;P&gt;Can you use data expressions in ArcGIS Dashboards to perform math with a pervious record?&amp;nbsp; The data is stored in ArcGIS Server and pulled into ArcGIS Online .&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 15:30:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287291#M7777</guid>
      <dc:creator>MarlaJohnson</dc:creator>
      <dc:date>2023-05-09T15:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Dashboard-Arcade Expressions (Math)</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287365#M7779</link>
      <description>&lt;P&gt;Yes! Provided you can identify what "previous" means with some record sorting, etc., you can easily write an expression that uses the previous record's value to calculate something else.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 17:51:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287365#M7779</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-05-09T17:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Dashboard-Arcade Expressions (Math)</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287371#M7780</link>
      <description>I am trying to subtract the current day number (chemical reading) from the previous day. It is usually the record right before if sorted by date The issue is Arcade expression is not calling the data, which makes me think I am doing it wrong.&lt;BR /&gt;</description>
      <pubDate>Tue, 09 May 2023 18:09:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287371#M7780</guid>
      <dc:creator>MarlaJohnson</dc:creator>
      <dc:date>2023-05-09T18:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Dashboard-Arcade Expressions (Math)</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287373#M7781</link>
      <description>&lt;P&gt;Can you share the expression?&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 18:10:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287373#M7781</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-05-09T18:10:38Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Dashboard-Arcade Expressions (Math)</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287380#M7782</link>
      <description>I have tried a lot of different things. I do have an empty field I can place the results in. This is for a serial chart.&lt;BR /&gt;&lt;BR /&gt;var portal = Portal('&lt;A href="https://www.arcgis.com" target="_blank"&gt;https://www.arcgis.com&lt;/A&gt;');&lt;BR /&gt;var fs = FeatureSetByPortalItem(portal, 'fcb8c011c9f44ad09e735683da808b41');&lt;BR /&gt;&lt;BR /&gt;var currentIndex = feature['OBJECTID'];&lt;BR /&gt;var previousIndex = currentIndex - 1;&lt;BR /&gt;&lt;BR /&gt;if (previousIndex &amp;gt; 0) {&lt;BR /&gt;var previousRecord = FeatureByIndex(fs, previousIndex);&lt;BR /&gt;&lt;BR /&gt;var previousValue = previousRecord['INSPAnswerNumber'];&lt;BR /&gt;var currentValue = feature['INSPAnswerNumber'];&lt;BR /&gt;&lt;BR /&gt;if (!IsEmpty(currentValue) &amp;amp;&amp;amp; !IsEmpty(previousValue)) {&lt;BR /&gt;return currentValue - previousValue;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;return null;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 09 May 2023 18:21:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287380#M7782</guid>
      <dc:creator>MarlaJohnson</dc:creator>
      <dc:date>2023-05-09T18:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Dashboard-Arcade Expressions (Math)</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287435#M7783</link>
      <description>&lt;P&gt;I'm not sure how you ended up with that expression. The FeatureSetByPortalItem function requires you to specify the layer index, and it won't get past the second line as its written. Even if it did, it needs to return a FeatureSet object.&lt;/P&gt;&lt;P&gt;The way Data Expressions work is a bit different from other Arcade profiles. If you haven't yet, take a look at some of the expressions here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/arcade-expressions/tree/master/dashboard_data" target="_blank"&gt;https://github.com/Esri/arcade-expressions/tree/master/dashboard_data&lt;/A&gt;&lt;/P&gt;&lt;P&gt;In particular, note how you need to first define a dictionary with the fields defined and an empty array for the features. Then you need to loop through every feature in your FeatureSet to push attributes to that dictionary. It will look very different from what you have posted.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var portal = Portal('https://www.arcgis.com');

var fs = FeatureSetByPortalItem(
    portal,
    'fcb8c011c9f44ad09e735683da808b41',
    0,
    ['some_field'],
    false
);

var out_dict = {
    fields: [
        {name: 'some_field', type: 'esriFieldTypeInteger'},
        {name: 'difference_from_last', type: 'esriFieldTypeInteger'}],
    geometryType: '',
    features: []
}

var prev_val = 0

for (var f in fs) {
    Push(
        out_dict['features'],
        {
            attributes: {
                some_field: f['some_field'],
                difference_from_last: f['some_field'] - prev_val
            }
        }
    )
    
    prev_val = f['some_field']
}

return FeatureSet(Text(out_dict))&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 09 May 2023 20:00:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287435#M7783</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-05-09T20:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Dashboard-Arcade Expressions (Math)</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287471#M7785</link>
      <description>I updated it to this but not exactly getting the correct data back. One day someone puts in data, a number. The second day someone puts in data, a number. I need it to look at the second day and subtract it from the first day. It is easy in python.&lt;BR /&gt;var portal = Portal('&lt;A href="https://www.arcgis.com" target="_blank"&gt;https://www.arcgis.com&lt;/A&gt;');&lt;BR /&gt;var fs = FeatureSetByPortalItem(portal, 'fcb8c011c9f44ad09e735683da808b41', 0, ['INSPAnswerNumber'], false);&lt;BR /&gt;&lt;BR /&gt;var out_dict = {&lt;BR /&gt;fields: [&lt;BR /&gt;{ name: 'INSPAnswerNumber', type: 'esriFieldTypeInteger' },&lt;BR /&gt;{ name: 'difference_from_last', type: 'esriFieldTypeInteger' }&lt;BR /&gt;],&lt;BR /&gt;geometryType: '',&lt;BR /&gt;features: []&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;var prev_val = 0;&lt;BR /&gt;for (var feature in fs) {&lt;BR /&gt;var current_val = feature['INSPAnswerNumber'];&lt;BR /&gt;Push(out_dict['features'], {&lt;BR /&gt;attributes: {&lt;BR /&gt;INSPAnswerNumber: current_val,&lt;BR /&gt;difference_from_last: current_val - prev_val&lt;BR /&gt;}&lt;BR /&gt;});&lt;BR /&gt;prev_val = current_val;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;return FeatureSet(Text(out_dict));&lt;BR /&gt;</description>
      <pubDate>Tue, 09 May 2023 21:33:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287471#M7785</guid>
      <dc:creator>MarlaJohnson</dc:creator>
      <dc:date>2023-05-09T21:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Dashboard-Arcade Expressions (Math)</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287477#M7786</link>
      <description>&lt;P&gt;Well, that can depend on the data itself. Is the field actually an integer, or does it need to be converted?&lt;/P&gt;&lt;P&gt;Are you records already in the appropriate order? You may need to use &lt;STRONG&gt;Sort &lt;/STRONG&gt;if not.&lt;/P&gt;&lt;P&gt;What &lt;EM&gt;are &lt;/EM&gt;you getting back, if anything?&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 21:37:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287477#M7786</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-05-09T21:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Dashboard-Arcade Expressions (Math)</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287478#M7787</link>
      <description>The data is an interger I am getting back weird numbers that make no sense.&lt;BR /&gt;</description>
      <pubDate>Tue, 09 May 2023 21:42:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287478#M7787</guid>
      <dc:creator>MarlaJohnson</dc:creator>
      <dc:date>2023-05-09T21:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Dashboard-Arcade Expressions (Math)</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287479#M7788</link>
      <description>&lt;P&gt;Can you give some examples? It's hard to know how the expression is failing without knowing what it's actually doing.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 21:46:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287479#M7788</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-05-09T21:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Dashboard-Arcade Expressions (Math)</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287607#M7790</link>
      <description>That is a good point. With he expression I sent I am getting these results. I am using this data in the second screenshot. So the difference form last makes no sense.&lt;BR /&gt;[cid:image001.png@01D98304.2A9B02D0]&lt;BR /&gt;[cid:image002.png@01D98304.2A9B02D0]&lt;BR /&gt;</description>
      <pubDate>Wed, 10 May 2023 09:57:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1287607#M7790</guid>
      <dc:creator>MarlaJohnson</dc:creator>
      <dc:date>2023-05-10T09:57:23Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Dashboard-Arcade Expressions (Math)</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1288406#M7805</link>
      <description>&lt;P&gt;I figured this out. Thanks for the help.&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 21:52:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-expressions-math/m-p/1288406#M7805</guid>
      <dc:creator>MarlaJohnson</dc:creator>
      <dc:date>2023-05-11T21:52:27Z</dc:date>
    </item>
  </channel>
</rss>

