<?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 Exp - Joining two Layers for Dashboard Table in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-exp-joining-two-layers-for-dashboard-table/m-p/1599951#M10946</link>
    <description>&lt;P&gt;When posting code, use the &lt;A href="https://community.esri.com/t5/community-help-documents/how-to-insert-code-in-your-post/ta-p/914552" target="_self"&gt;Insert/edit code sample&lt;/A&gt; tool instead of attaching it as a text file.&lt;/P&gt;&lt;P&gt;Give this script a try. It puts null values for the plot attributes in each feature for the grades layer and only fills them in when there is a matching plots feature.&lt;/P&gt;&lt;P&gt;A couple of additional notes about this.&lt;/P&gt;&lt;P&gt;This uses the&amp;nbsp;Arcade variable substitution in the &lt;A href="https://developers.arcgis.com/arcade/function-reference/featureset_functions/#filter" target="_self"&gt;Filter&lt;/A&gt; function in line 38, which means you don't have to worry about whether a value has quotes or not.&lt;/P&gt;&lt;P&gt;Aslo, calling the Filter function many times in a loop is very expensive and will slow your script down. Using &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;'s &lt;A href="https://community.esri.com/t5/developers-questions/trying-to-optimize-arcade-script-to-fix-execution/m-p/1518421/highlight/true#M7196" target="_self"&gt;Memorize&lt;/A&gt; function will drastically reduce the execution time for the script. In my test script using a plots layer of 36 features and a grades feature of 51 features, this reduced the execution time from about 8 seconds to half a second.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function Memorize(fs) {
  var temp_dict = {
    fields: Schema(fs)["fields"],
    geometryType: "",
    features: []
  };
  for (var f in fs) {
    var attrs = {};
    for (var attr in f) {
      attrs[attr] = Iif(TypeOf(f[attr]) == "Date", Number(f[attr]), f[attr]);
    }
    Push(temp_dict["features"], { attributes: attrs });
  }
  return FeatureSet(temp_dict);
}

var portal = Portal("https://xyz.maps.arcgis.com/");
var plots = Memorize(FeatureSetByPortalItem(portal, "xyzx", 0, ["*"], false));
var grades = FeatureSetByPortalItem(portal, "xyzx", 0, ["*"], false);

// Create empty features array
var features = [];

// Populate Feature Array
for (var t in grades) {
  var tableID = t["BlockCode"];
  var feat = {
    attributes:
      {
        BlockCode: tableID,
        FinalGrade: t["FinalGrade"],
        SelectedEURs: t["SelectedEURs"],
        last_name: t["last_name"],
        UCode: null,
        Vineyard_Name: null
      }
  };
  for (var p in Filter(plots, "UCode = @tableID")) {
    feat.attributes.UCode = p["UCode"];
    feat.attributes.Vineyard_Name = p["Vineyard_Name"];
  }
  Push(features, feat);
}

var joinedDict = {
  fields: [
    { name: "BlockCode", type: "esriFieldTypeString" },
    { name: "FinalGrade", type: "esriFieldTypeString" },
    { name: "SelectedEURs", type: "esriFieldTypeString" },
    { name: "last_name", type: "esriFieldTypeString" },
    { name: "UCode", type: "esriFieldTypeString" },
    { name: "Vineyard_Name", type: "esriFieldTypeString" }
  ],
  geometryType: "",
  features: features
};

// Return dictionary cast as a feature set
return FeatureSet(joinedDict);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Mar 2025 15:05:17 GMT</pubDate>
    <dc:creator>KenBuja</dc:creator>
    <dc:date>2025-03-27T15:05:17Z</dc:date>
    <item>
      <title>Arcade Exp - Joining two Layers for Dashboard Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-exp-joining-two-layers-for-dashboard-table/m-p/1599797#M10945</link>
      <description>&lt;P&gt;I'm able to create an Arcade expression to pull attributes from two feature layers to create a dashboard table element.&amp;nbsp; However, I want all of the records from one layer to populate, and then add the attributes from the other layer when there is a matching record from that layer.&amp;nbsp; Attached is my Arcade Expression - How do I pull all of the records from the "plots" layer?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 00:44:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-exp-joining-two-layers-for-dashboard-table/m-p/1599797#M10945</guid>
      <dc:creator>AllisonWebb</dc:creator>
      <dc:date>2025-03-27T00:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Exp - Joining two Layers for Dashboard Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-exp-joining-two-layers-for-dashboard-table/m-p/1599951#M10946</link>
      <description>&lt;P&gt;When posting code, use the &lt;A href="https://community.esri.com/t5/community-help-documents/how-to-insert-code-in-your-post/ta-p/914552" target="_self"&gt;Insert/edit code sample&lt;/A&gt; tool instead of attaching it as a text file.&lt;/P&gt;&lt;P&gt;Give this script a try. It puts null values for the plot attributes in each feature for the grades layer and only fills them in when there is a matching plots feature.&lt;/P&gt;&lt;P&gt;A couple of additional notes about this.&lt;/P&gt;&lt;P&gt;This uses the&amp;nbsp;Arcade variable substitution in the &lt;A href="https://developers.arcgis.com/arcade/function-reference/featureset_functions/#filter" target="_self"&gt;Filter&lt;/A&gt; function in line 38, which means you don't have to worry about whether a value has quotes or not.&lt;/P&gt;&lt;P&gt;Aslo, calling the Filter function many times in a loop is very expensive and will slow your script down. Using &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;'s &lt;A href="https://community.esri.com/t5/developers-questions/trying-to-optimize-arcade-script-to-fix-execution/m-p/1518421/highlight/true#M7196" target="_self"&gt;Memorize&lt;/A&gt; function will drastically reduce the execution time for the script. In my test script using a plots layer of 36 features and a grades feature of 51 features, this reduced the execution time from about 8 seconds to half a second.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function Memorize(fs) {
  var temp_dict = {
    fields: Schema(fs)["fields"],
    geometryType: "",
    features: []
  };
  for (var f in fs) {
    var attrs = {};
    for (var attr in f) {
      attrs[attr] = Iif(TypeOf(f[attr]) == "Date", Number(f[attr]), f[attr]);
    }
    Push(temp_dict["features"], { attributes: attrs });
  }
  return FeatureSet(temp_dict);
}

var portal = Portal("https://xyz.maps.arcgis.com/");
var plots = Memorize(FeatureSetByPortalItem(portal, "xyzx", 0, ["*"], false));
var grades = FeatureSetByPortalItem(portal, "xyzx", 0, ["*"], false);

// Create empty features array
var features = [];

// Populate Feature Array
for (var t in grades) {
  var tableID = t["BlockCode"];
  var feat = {
    attributes:
      {
        BlockCode: tableID,
        FinalGrade: t["FinalGrade"],
        SelectedEURs: t["SelectedEURs"],
        last_name: t["last_name"],
        UCode: null,
        Vineyard_Name: null
      }
  };
  for (var p in Filter(plots, "UCode = @tableID")) {
    feat.attributes.UCode = p["UCode"];
    feat.attributes.Vineyard_Name = p["Vineyard_Name"];
  }
  Push(features, feat);
}

var joinedDict = {
  fields: [
    { name: "BlockCode", type: "esriFieldTypeString" },
    { name: "FinalGrade", type: "esriFieldTypeString" },
    { name: "SelectedEURs", type: "esriFieldTypeString" },
    { name: "last_name", type: "esriFieldTypeString" },
    { name: "UCode", type: "esriFieldTypeString" },
    { name: "Vineyard_Name", type: "esriFieldTypeString" }
  ],
  geometryType: "",
  features: features
};

// Return dictionary cast as a feature set
return FeatureSet(joinedDict);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 15:05:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-exp-joining-two-layers-for-dashboard-table/m-p/1599951#M10946</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-03-27T15:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Exp - Joining two Layers for Dashboard Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-exp-joining-two-layers-for-dashboard-table/m-p/1600061#M10949</link>
      <description>&lt;P&gt;Thank you!&amp;nbsp; This is only pulling the records from the grades layer with the correct attributes from the plots layer.&amp;nbsp; I want all the records from the plots layer.&amp;nbsp; The idea is to be able to filter the table in the dashboard to see the records in the plots layer that don't have a record in the grades feature layer to determine which need to be graded.&amp;nbsp; But also see the scores for those in the plots layer that have a grades.&lt;/P&gt;&lt;P&gt;grades layer BlockCode matches plots layer UCode&lt;/P&gt;&lt;P&gt;plots fields "UCode", "Vineyard_Name"&lt;/P&gt;&lt;P&gt;grades layer "BlockCode", "FinalGrade", "SelectedEURs", "last_name"&lt;/P&gt;&lt;P&gt;I cannot use a joined view because the plots feature layer is overwritten frequently, and I cannot overwrite when there is a joined view.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 18:42:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-exp-joining-two-layers-for-dashboard-table/m-p/1600061#M10949</guid>
      <dc:creator>AllisonWebb</dc:creator>
      <dc:date>2025-03-27T18:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Exp - Joining two Layers for Dashboard Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-exp-joining-two-layers-for-dashboard-table/m-p/1600100#M10950</link>
      <description>&lt;P&gt;It sounds like you just need to reverse the logic&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;for (var p in plots) {
  var tableID = p["UCode"];
  var feat = {
    attributes:
      {
        UCode: tableID,
        Vineyard_Name: p["Vineyard_Name"],
        BlockCode: null,
        FinalGrade: null,
        SelectedEURs: null,
        last_name: null
      }
  };
  for (var g in Filter(grades, "BlockCode = @tableID")) {
    feat.attributes.BlockCode = g["BlockCode"];
    feat.attributes.FinalGrade = g["FinalGrade"];
    feat.attributes.SelectedEURs = g["SelectedEURs"];
    feat.attributes.last_name = g["last_name"];
  }
  Push(features, feat);
}

var joinedDict = {
  fields: [
    { name: "UCode", type: "esriFieldTypeString" },
    { name: "Vineyard_Name", type: "esriFieldTypeString" },
    { name: "BlockCode", type: "esriFieldTypeString" },
    { name: "FinalGrade", type: "esriFieldTypeString" },
    { name: "SelectedEURs", type: "esriFieldTypeString" },
    { name: "last_name", type: "esriFieldTypeString" }
  ],
  geometryType: "",
  features: features
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 19:47:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-exp-joining-two-layers-for-dashboard-table/m-p/1600100#M10950</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-03-27T19:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Exp - Joining two Layers for Dashboard Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-exp-joining-two-layers-for-dashboard-table/m-p/1600175#M10952</link>
      <description>&lt;P&gt;When I use your first expression, it takes a few seconds to save after clicking Done.&amp;nbsp; Then I can add the fields to the table.&amp;nbsp; When I use your second expression, it won't save after clicking Done.&amp;nbsp; If I Cancel and go back to Select a layer, the expression is there with an "unable to execute Arcade script".&amp;nbsp; I appreciate any help you can provide.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;There are 1668 records in plots and 3 records in grades, so not too many.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;function Memorize(fs) {
  var temp_dict = {
    fields: Schema(fs)["fields"],
    geometryType: "",
    features: []
  };
  for (var f in fs) {
    var attrs = {};
    for (var attr in f) {
      attrs[attr] = Iif(TypeOf(f[attr]) == "Date", Number(f[attr]), f[attr]);
    }
    Push(temp_dict["features"], { attributes: attrs });
  }
  return FeatureSet(temp_dict);
}

var portal = Portal("https://xyz.maps.arcgis.com/");
var plots = Memorize(FeatureSetByPortalItem(portal, "xyz", 0, ["*"], false));
var grades = FeatureSetByPortalItem(portal, "xyz", 0, ["*"], false);

// Create empty features array
var features = [];

// Populate Feature Array
for (var p in plots) {
  var tableID = p["UCode"];
  var feat = {
    attributes:
      {
        UCode: tableID,
        Vineyard_Name: p["Vineyard_Name"],
        BlockCode: null,
        FinalGrade: null,
        SelectedEURs: null,
        last_name: null
      }
  };
  for (var g in Filter(grades, "BlockCode = @tableID")) {
    feat.attributes.BlockCode = g["BlockCode"];
    feat.attributes.FinalGrade = g["FinalGrade"];
    feat.attributes.SelectedEURs = g["SelectedEURs"];
    feat.attributes.last_name = g["last_name"];
  }
  Push(features, feat);
}

var joinedDict = {
  fields: [
    { name: "UCode", type: "esriFieldTypeString" },
    { name: "Vineyard_Name", type: "esriFieldTypeString" },
    { name: "BlockCode", type: "esriFieldTypeString" },
    { name: "FinalGrade", type: "esriFieldTypeString" },
    { name: "SelectedEURs", type: "esriFieldTypeString" },
    { name: "last_name", type: "esriFieldTypeString" }
  ],
  geometryType: "",
  features: features
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 21:35:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-exp-joining-two-layers-for-dashboard-table/m-p/1600175#M10952</guid>
      <dc:creator>AllisonWebb</dc:creator>
      <dc:date>2025-03-27T21:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Exp - Joining two Layers for Dashboard Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-exp-joining-two-layers-for-dashboard-table/m-p/1600412#M10953</link>
      <description>&lt;P&gt;I didn't include all the lines of the code in my reply, only the ones that were changed. You didn't return the dictionary as a FeatureSet at the end of the code.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Return dictionary cast as a feature set
return FeatureSet(joinedDict);&lt;/LI-CODE&gt;&lt;P&gt;One other thing. I forgot to switch the FeatureSet to be Memorized&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var plots = FeatureSetByPortalItem(portal, "xyz", 0, ["*"], false);
var grades = Memorize(FeatureSetByPortalItem(portal, "xyz", 0, ["*"], false));&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Mar 2025 14:40:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-exp-joining-two-layers-for-dashboard-table/m-p/1600412#M10953</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-03-28T14:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Exp - Joining two Layers for Dashboard Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-exp-joining-two-layers-for-dashboard-table/m-p/1600434#M10954</link>
      <description>&lt;P&gt;That worked!&amp;nbsp; Thank you so much!!&lt;/P&gt;</description>
      <pubDate>Fri, 28 Mar 2025 15:25:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-exp-joining-two-layers-for-dashboard-table/m-p/1600434#M10954</guid>
      <dc:creator>AllisonWebb</dc:creator>
      <dc:date>2025-03-28T15:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Exp - Joining two Layers for Dashboard Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-exp-joining-two-layers-for-dashboard-table/m-p/1600443#M10956</link>
      <description>&lt;P&gt;Glad to help. Don't forget to click the "Accept as Solution" button on post(s) that answered your question.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Mar 2025 15:34:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-exp-joining-two-layers-for-dashboard-table/m-p/1600443#M10956</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-03-28T15:34:27Z</dc:date>
    </item>
  </channel>
</rss>

