<?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 Data Expression- Related Table in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128106#M5537</link>
    <description>&lt;P&gt;Realized there was a missing comma in the code, it works now. My only question now is how to highlight these features on the map?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much!&lt;/P&gt;</description>
    <pubDate>Tue, 21 Dec 2021 18:29:11 GMT</pubDate>
    <dc:creator>TSmith</dc:creator>
    <dc:date>2021-12-21T18:29:11Z</dc:date>
    <item>
      <title>Arcade Data Expression- Related Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1127987#M5522</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am relatively new to arcade, and attempting to figure out how to use a data expression to feed indicators/gauges based on an inspection date field in a related table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I currently have a pop-up within the map that uses this expression:&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; var BlowoffHistory= FeatureSetByRelationshipName($feature,"Blowoff_Flushing_Inspection")var LatestDate = Max(BlowoffHistory,"flushingdate") var FormatDate = Date(LatestDate) return FormatDate &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my goal is to reference related data and check to see if the most recent inspection date occurred within the last year. If it did not, the feature should be passed through to an indicator widget, displaying the assets that are overdue for inspection. Any pointers/tips on how to accomplish this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 13:55:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1127987#M5522</guid>
      <dc:creator>TSmith</dc:creator>
      <dc:date>2021-12-21T13:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression- Related Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128019#M5526</link>
      <description>&lt;P&gt;So, the difference between the popup and the dashboard widgets is that the dashboard can potentially reference all features at once, whereas the popup is specific to a single feature.&lt;/P&gt;&lt;P&gt;There are a few ways you can do this, but it depends on what you want the output to look like. Do you want a list of just those features which are overdue? That might look like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Set portal and layers

var portal = Portal('your portal URL');
var fs = FeatureSetByPortalItem(
    portal,
    'itemID of service',
    layer index, // Probably 0, but maybe different if you have multiple layers/tables in the service
    ['list', 'of', 'fields'],
    false
);

// Empty feature array and feat object to populate output
var features = [];
var feat;

// Set "one year ago" date
var year_ago = DateAdd(Now(), -1, 'years');

// Iterate over features in main layer
for (var f in fs){
    
    // Get related records
    var rel_fs = FeatureSetByRelationshipName(
        $feature,
        "Blowoff_Flushing_Inspection"
        ['flushingdate'],
        false
    );

    // Get most recent date from related records
    var latest = Max(rel_fs, 'flushingdate');

    // If latest date not within a year, add feature to output array
    if (latest &amp;lt; year_ago) {
        var feat = {
            attributes: {
                'some_id': f['id_field'],
                'last_inspection: latest
            }
        }
        
        Push(features, feat);
    };
    
// Create output dictionary
var outdict = {
    fields: [
        { name: 'some_id', type: 'esriFieldTypeString'},
        { name: 'last_inspection', type: 'esriFieldTypeDate'}
    ],
    geometryType: '',
    features: features
};

return FeatureSet(Text(outdict))&lt;/LI-CODE&gt;&lt;P&gt;It's hard to say for certain if this is what you want, lacking more information about your dashboard and not having a live layer to test this against, but this should at least get you a list of overdue inspection features.&lt;/P&gt;&lt;P&gt;If you wanted to add a spatial component to this list, say, have the list items zoom to a location on a map, the expression would need to be altered, but not much.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 15:09:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128019#M5526</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-12-21T15:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression- Related Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128024#M5527</link>
      <description>&lt;P&gt;Yes, this is very helpful. I was trying to wrap my head around how the $feature argument works, as trying to use the FeatureSetByRelationshipName function kept giving me an error of "invalid identifier $feature"&amp;nbsp;&lt;/P&gt;&lt;P&gt;It would be cool to zoom to the features on the map! I believe that can be set as an "action" within the list element itself. Thanks so much for your reply!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 15:23:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128024#M5527</guid>
      <dc:creator>TSmith</dc:creator>
      <dc:date>2021-12-21T15:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression- Related Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128029#M5528</link>
      <description>&lt;P&gt;Ah, my mistake. Since that's happening in the for loop, you need to put "f", instead of "$feature".&lt;/P&gt;&lt;P&gt;You &lt;EM&gt;can &lt;/EM&gt;set that zoom action on the list, but only if the list is looking at a spatial layer. We're working with a &lt;STRONG&gt;Data Expression&lt;/STRONG&gt;, which synthesizes layers on the fly; the expression I posted, even though it pulls its data from a spatial layer, does not have a spatial component included in the output.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 15:32:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128029#M5528</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-12-21T15:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression- Related Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128038#M5529</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Set "one year ago" date
var year_ago = DateAdd(Now(), -1, 'years');

// Iterate over features in main layer
for (var f in fs){
    
    // Get related records
    var rel_fs = FeatureSetByRelationshipName(
        f,
        "Blowoff_Flushing_Inspection"
        ['flushingdate'],
        false
    );

    // Get most recent date from related records
    var latest = Max(rel_fs, 'flushingdate');

    // If latest date not within a year, add feature to output array
    if (latest &amp;lt; year_ago) {
        var feat = {
            attributes: {
                'some_id': f['assetid'],
                'last_inspection': latest
            }
        }
        
        Push(features, feat);
    };
};
// Create output dictionary
var outdict = {
    fields: [
        { name: 'some_id', type: 'esriFieldTypeString'},
        { name: 'last_inspection', type: 'esriFieldTypeDate'}
    ],
    geometryType: '',
    features: features
    
};
return FeatureSet(Text(outdict))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get a "&lt;SPAN class=""&gt;Execution Error:&lt;/SPAN&gt;&lt;SPAN&gt;Runtime Error: Cannot call member property on object of this type" when I test this expression. Any ideas?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 15:52:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128038#M5529</guid>
      <dc:creator>TSmith</dc:creator>
      <dc:date>2021-12-21T15:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression- Related Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128048#M5530</link>
      <description>&lt;P&gt;Looks like &lt;STRONG&gt;Max&lt;/STRONG&gt; returns a number, so we've got to change that. Instead, we'll sort the related records by date, then return the first record in the set. Replace the "var latest" line with these:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var recent_record = First(OrderBy(rel_fs, 'last_inspection DESC'))

var latest = recent_record['flushingdate']&lt;/LI-CODE&gt;&lt;P&gt;Any chance these layers are public? It's &lt;EM&gt;much &lt;/EM&gt;easier to troubleshoot if I can test this against real data.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 16:32:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128048#M5530</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-12-21T16:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression- Related Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128055#M5531</link>
      <description>&lt;P&gt;Unfortunately, no. I still run into the same error here, and unfortunately arcade isn't highlighting which line has the issue. Just a general runtime error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The layer is Flushing and Blowoff, the relationship is AssetID to BlowoffID in the related table, and it is worth noting the parent table does not have the most recent inspection date populated. Flushingdate only exists in the related table&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 16:45:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128055#M5531</guid>
      <dc:creator>TSmith</dc:creator>
      <dc:date>2021-12-21T16:45:20Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression- Related Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128056#M5532</link>
      <description>&lt;P&gt;Yes, I assumed the attribute was only on the related records.&lt;/P&gt;&lt;P&gt;That error usually means we're trying to pull an attribute from something that won't allow it.&lt;/P&gt;&lt;P&gt;Try commenting out the line "'some_id': f['assetid'],". That's the only place we're attempting to grab an attribute.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 16:53:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128056#M5532</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-12-21T16:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression- Related Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128059#M5533</link>
      <description>&lt;LI-CODE lang="javascript"&gt;// Empty feature array and feat object to populate output
var features = [];
var feat;

// Set "one year ago" date
var year_ago = DateAdd(Now(), -1, 'years');

// Iterate over features in main layer
for (var f in fs){
    
    // Get related records
    var rel_fs = FeatureSetByRelationshipName(
        f,
        "Blowoff_Flushing_Inspection"
        ['flushingdate'],
        false
    );

    // Get most recent date from related records
    var recent_record = First(OrderBy(rel_fs, 'flushingdate DESC'))

    var latest = recent_record['flushingdate']

    // If latest date not within a year, add feature to output array
    if (latest &amp;lt; year_ago) {
        var feat = {
            attributes: {
                //'assetid': f['assetid'],
                'flushingdate': latest
            }
        }
        
        Push(features, feat);
    }};
    
// Create output dictionary
var outdict = {
    fields: [
        { name: 'assetid', type: 'esriFieldTypeString'},
        { name: 'flushingdate', type: 'esriFieldTypeDate'}
    ],
    geometryType: '',
    features: features
};

return FeatureSet(Text(outdict))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Still a runtime cannot call member property error. This code and your workflow is definitely what I'm trying to do. I guess if I can't figure this out, I could always just write a python script to populate most recent inspection dates in the parent table.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 16:58:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128059#M5533</guid>
      <dc:creator>TSmith</dc:creator>
      <dc:date>2021-12-21T16:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression- Related Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128065#M5534</link>
      <description>&lt;P&gt;Very strange. You might look through some of the other Data Expressions for more ideas: &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;</description>
      <pubDate>Tue, 21 Dec 2021 17:01:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128065#M5534</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-12-21T17:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression- Related Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128106#M5537</link>
      <description>&lt;P&gt;Realized there was a missing comma in the code, it works now. My only question now is how to highlight these features on the map?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 18:29:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128106#M5537</guid>
      <dc:creator>TSmith</dc:creator>
      <dc:date>2021-12-21T18:29:11Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression- Related Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128113#M5538</link>
      <description>&lt;P&gt;Glad to hear it! Adding the spatial component is not too difficult.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;In the &lt;STRONG&gt;FeatureSetByPortalItem &lt;/STRONG&gt;function, set the final parameter to "true".&lt;/LI&gt;&lt;LI&gt;In the section when we define the &lt;STRONG&gt;feat&lt;/STRONG&gt; object, we need to include that geometry:&lt;PRE&gt;var feat = {&lt;BR /&gt;    attributes: {&lt;BR /&gt;        assetid: f['assetid'],&lt;BR /&gt;        flushingdate: latest&lt;BR /&gt;    },&lt;BR /&gt;    geometry: Geometry(f)&lt;BR /&gt;}&lt;/PRE&gt;&lt;/LI&gt;&lt;LI&gt;When we establish the &lt;STRONG&gt;outdict&lt;/STRONG&gt; object, put "geometryType: 'esriGeometryPoint'", or whatever geometry type we're dealing with here.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I always default to leaving geometry out of data expressions, as it can make the expression more resource-intensive to evaluate. But once you make those changes, you should be able to use the appropriate &lt;STRONG&gt;Action&lt;/STRONG&gt; to zoom to / filter data in the map.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 18:44:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128113#M5538</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-12-21T18:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression- Related Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128314#M5540</link>
      <description>&lt;P&gt;You have been a tremendous amount of help. Is there any way I could grab data from fields in the related table?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;f (latest &amp;lt; year_ago) {
        var feat = {
            attributes: {
                'valveID': f['assetid'],
                'vcycle' : f['vcycle'],
                'last_inspection': latest,
                'fintorque': rel_fs['fintorque'],
                'turns': rel_fs['turns']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it doesn't like trying to add those fields. Even when I set a variable&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var turns = rel_fs['turns'];
    var fintorque = rel_fs['fintorque'];&lt;/LI-CODE&gt;&lt;P&gt;do I have to call a function like var turns&amp;nbsp; = Text(rel_fs['turns']); or something like that?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 15:15:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1128314#M5540</guid>
      <dc:creator>TSmith</dc:creator>
      <dc:date>2021-12-22T15:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression- Related Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1526551#M10193</link>
      <description>&lt;P&gt;Hi Josh &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;- I use quite a few of your examples that you post in the Community to help us out with data expressions. Thank you so much for generously addressing questions and offering your expertise.&lt;/P&gt;&lt;P&gt;I am currently working on a dashboard that includes the need to use related tables. I'm particularly stumped by the syntax needed in a data expression to use grouped values from a related table that are related to the feature layer by a projectID, and still be able to zoom to the location on the map that corresponds to those projectIDs in the feature layer. The related table is many:1 so the attributes in the table have to be grouped to be useable in a category selector widget or a table widget. When I read your reply, I thought maybe the bit of alteration you mention might be the key: "&lt;SPAN&gt;If you wanted to add a spatial component to this list, say, have the list items zoom to a location on a map, the expression would need to be altered, but not much."&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I updated my expression to include the spatial component, but I am still unable to use the select or zoom action on the feature layer in the map. If you have any additional suggestions, I would appreciate your help. Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2024 18:48:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1526551#M10193</guid>
      <dc:creator>KimberlyK</dc:creator>
      <dc:date>2024-08-26T18:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression- Related Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1527407#M10200</link>
      <description>&lt;P&gt;It would probably be best to post this as its own question, and include the expression you've got so far.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2024 19:48:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-related-table/m-p/1527407#M10200</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-08-26T19:48:15Z</dc:date>
    </item>
  </channel>
</rss>

