<?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 Dashboard Data Expression Intersects in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1664997#M11596</link>
    <description>&lt;P&gt;I'm trying to set up some data expressions in Dashboards to use with Indictor widgets.&amp;nbsp; I have a tracts layer (322 features) and a lakes layer (11,200 features) and I want to intersect these to get the total number of lakes and a sum of lake acres in the Indicator.&amp;nbsp; Here is the code, which appears to work, but takes about 20 minutes to run.&amp;nbsp; What can I do to speed this up?&amp;nbsp; Can I run an intersection before the loop to filter out most of the lakes?&amp;nbsp; There should only be about 1,020 lakes that actually intersect with the tracts.&amp;nbsp; I only know a little Arcade; most of this was done with the help of CoPilot.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var port = Portal("https://www.arcgis.com");

// Load layers with correct area field name
var tracts = FeatureSetByPortalItem(port, "b9fcbedac0384e32bc3dba6aec1a8cf6", 0, ["OBJECTID"], true);
var lakes = FeatureSetByPortalItem(port, "5564b2e702364aefba08df8c95216a1f", 0, ["OBJECTID", "Shape__Area_2"], true);

var fsDict = {
    fields: [
        { name: "OBJECTID", type: "esriFieldTypeOID" },
        { name: "LakeCount", type: "esriFieldTypeInteger" },
        { name: "Acres", type: "esriFieldTypeDouble" }
    ],
    geometryType: "",
    features: []
};

for (var t in tracts) {
    var tractGeom = Geometry(t);
    var lakeCount = 0;
    var totalAcres = 0;

    for (var lake in lakes) {
        if (Intersects(Geometry(lake), tractGeom)) {
            lakeCount += 1;
            totalAcres += lake["Shape__Area_2"] / 4046.8564224;
        }
    }

    Push(fsDict.features, {
        attributes: {
            OBJECTID: t.OBJECTID,
            LakeCount: lakeCount,
            Acres: Round(totalAcres, 1)
        }
    });
}

return FeatureSet(fsDict)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Nov 2025 21:28:41 GMT</pubDate>
    <dc:creator>LukeGilner1</dc:creator>
    <dc:date>2025-11-11T21:28:41Z</dc:date>
    <item>
      <title>Dashboard Data Expression Intersects</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1664997#M11596</link>
      <description>&lt;P&gt;I'm trying to set up some data expressions in Dashboards to use with Indictor widgets.&amp;nbsp; I have a tracts layer (322 features) and a lakes layer (11,200 features) and I want to intersect these to get the total number of lakes and a sum of lake acres in the Indicator.&amp;nbsp; Here is the code, which appears to work, but takes about 20 minutes to run.&amp;nbsp; What can I do to speed this up?&amp;nbsp; Can I run an intersection before the loop to filter out most of the lakes?&amp;nbsp; There should only be about 1,020 lakes that actually intersect with the tracts.&amp;nbsp; I only know a little Arcade; most of this was done with the help of CoPilot.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var port = Portal("https://www.arcgis.com");

// Load layers with correct area field name
var tracts = FeatureSetByPortalItem(port, "b9fcbedac0384e32bc3dba6aec1a8cf6", 0, ["OBJECTID"], true);
var lakes = FeatureSetByPortalItem(port, "5564b2e702364aefba08df8c95216a1f", 0, ["OBJECTID", "Shape__Area_2"], true);

var fsDict = {
    fields: [
        { name: "OBJECTID", type: "esriFieldTypeOID" },
        { name: "LakeCount", type: "esriFieldTypeInteger" },
        { name: "Acres", type: "esriFieldTypeDouble" }
    ],
    geometryType: "",
    features: []
};

for (var t in tracts) {
    var tractGeom = Geometry(t);
    var lakeCount = 0;
    var totalAcres = 0;

    for (var lake in lakes) {
        if (Intersects(Geometry(lake), tractGeom)) {
            lakeCount += 1;
            totalAcres += lake["Shape__Area_2"] / 4046.8564224;
        }
    }

    Push(fsDict.features, {
        attributes: {
            OBJECTID: t.OBJECTID,
            LakeCount: lakeCount,
            Acres: Round(totalAcres, 1)
        }
    });
}

return FeatureSet(fsDict)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Nov 2025 21:28:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1664997#M11596</guid>
      <dc:creator>LukeGilner1</dc:creator>
      <dc:date>2025-11-11T21:28:41Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard Data Expression Intersects</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665000#M11597</link>
      <description>&lt;P&gt;Doing lots of intersects is a resource hog, since the code has to make external calls for each feature in the loop.&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;wrote a good &lt;A href="https://community.esri.com/t5/developers-questions/trying-to-optimize-arcade-script-to-fix-execution/m-p/1517653" target="_self"&gt;post&lt;/A&gt; about how to store the features in memory (using his Memorize function) to speed up this process. This would be good if you wanted to create a table showing how many lakes are in each tract.&lt;/P&gt;&lt;P&gt;However, since you're looking to just get the sum off all the lakes in all the tracts, you can loop through the tracts FeatureSet to union them into a single feature, then use that feature in your Intersects function. You can get the count of that FeatureSet to see how many lakes there are and use the &lt;A href="https://developers.arcgis.com/arcade/function-reference/featureset_functions/#area" target="_self"&gt;Area&lt;/A&gt; function to get the total area of all the lakes.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var port = Portal("https://www.arcgis.com");

// Load layers with correct area field name
var tracts = FeatureSetByPortalItem(port, "b9fcbedac0384e32bc3dba6aec1a8cf6", 0, ["OBJECTID"], true);
var lakes = FeatureSetByPortalItem(port, "5564b2e702364aefba08df8c95216a1f", 0, ["OBJECTID"], true);

var arrTracts = [];
for (var tract in tracts) {
  Push(arrTracts, tract);
}
var lakesFS = Intersects(lakes, Union(arrTracts));
return FeatureSet(
  {
    fields: [
      { name: "LakeCount", type: "esriFieldTypeSingle" },
      { name: "Acres", type: "esriFieldTypeDouble" }
    ],
    features: [
      {
        attributes:
          {
            LakeCount: Count(lakesFS),
            Acres: Area(lakesFS, "acres")
          }
      }
    ]
  }
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Nov 2025 22:03:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665000#M11597</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-11-11T22:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard Data Expression Intersects</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665200#M11599</link>
      <description>&lt;P&gt;This gives me an "Unknown Error".&amp;nbsp; I've been trying some other things, but can't figure it out.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Nov 2025 17:46:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665200#M11599</guid>
      <dc:creator>LukeGilner1</dc:creator>
      <dc:date>2025-11-12T17:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard Data Expression Intersects</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665364#M11606</link>
      <description>&lt;P&gt;Looping through both layers is what’s slowing it down. Pre-filter the lakes using a spatial query (e.g., Intersects or Within at the feature set level) before looping. This limits iterations to only intersecting features and cuts processing time dramatically.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Nov 2025 05:22:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665364#M11606</guid>
      <dc:creator>MiaWhite34</dc:creator>
      <dc:date>2025-11-13T05:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard Data Expression Intersects</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665546#M11611</link>
      <description>&lt;P&gt;I've tested the code using some of my own data and it returned the expected data. I did make a change to line 17 to use the field type "esriFieldTypeInteger" since Count returns an integer, but keeping it as it is also works.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2025-11-13_11-48-00.PNG" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/143722iB506CD9FD7AF495A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="2025-11-13_11-48-00.PNG" alt="2025-11-13_11-48-00.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The next step would be to put some debugging &lt;A href="https://developers.arcgis.com/arcade/function-reference/debugging_functions/#console" target="_self"&gt;Console&lt;/A&gt; messages in the code at various places (like before and after line 11) and click the Run button in the editor window. This will give you a better idea where the code is crashing.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Nov 2025 16:52:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665546#M11611</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-11-13T16:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard Data Expression Intersects</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665581#M11612</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/2839"&gt;@KenBuja&lt;/a&gt;&amp;nbsp; - I'm not sure what the issue was, but I did change the field type to "esriFieldTypeInteger" for the Count.&amp;nbsp; I also added a Filter to the Lakes layer like&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/947089"&gt;@MiaWhite34&lt;/a&gt;&amp;nbsp;suggested, using an OrgKeyID which is only greater than 0 when it intersects with a tract now.&amp;nbsp; This minimizes the lakes to 997 features instead of over 11,000, and speeds up the process a lot.&lt;/P&gt;&lt;P&gt;However, now the acreage is not calculating correctly.&amp;nbsp; It is calculating the entire acreage of all the lakes, rather than just the intersected areas.&amp;nbsp; The calculation is an even larger number when I use the Area function with acres, so I went back to dividing the Shape__Area_2 field (square meters) by 4046.8564224.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var port = Portal("https://www.arcgis.com");

// Load layers
var tracts = FeatureSetByPortalItem(port, "b9fcbedac0384e32bc3dba6aec1a8cf6", 0, ["OBJECTID"], true);
var lakes = FeatureSetByPortalItem(port, "5564b2e702364aefba08df8c95216a1f", 0, ["OBJECTID", "OrgKeyID","Shape__Area_2"], true);
var lakesfilt = Filter(lakes,'OrgKeyID &amp;gt;0')

var arrTracts = [];
for (var tract in tracts) {
  Push(arrTracts, tract);
}
var lakesFS = Intersects(lakesfilt, Union(arrTracts));
return FeatureSet(
  {
    fields: [
      { name: "LakeCount", type: "esriFieldTypeInteger" },
      { name: "Acres", type: "esriFieldTypeDouble" }
    ],
    features: [
      {
        attributes:
          {
            LakeCount: Count(lakesFS),
            Acres: (Sum(lakesFS,"Shape__Area_2")/4046.8564224)
          }
      }
    ]
  }
);&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 13 Nov 2025 18:00:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665581#M11612</guid>
      <dc:creator>LukeGilner1</dc:creator>
      <dc:date>2025-11-13T18:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard Data Expression Intersects</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665653#M11616</link>
      <description>&lt;P&gt;I guess I'm not clear on the number you're expecting to get for the total area. Do you want to sum up the area of the portion of each lake that intersect the each tract? If so, then you'll have to loop through each tract and each lake to get the &lt;A href="https://developers.arcgis.com/arcade/function-reference/geometry_functions/#intersection" target="_self"&gt;Intersection&lt;/A&gt; geometry and add its area to the total. However, the total count of the lakes will likely be incorrect, since a lake intersecting several tracts will be counted for each tract.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Nov 2025 20:59:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665653#M11616</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-11-13T20:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard Data Expression Intersects</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665657#M11618</link>
      <description>&lt;P&gt;Yes, that's correct.&amp;nbsp; I want the total area of the portion of all lakes that intersect with the tracts.&amp;nbsp; I was hoping the Union on the tracts would solve the issue of double counting a lake, because I have noticed that to be a little off too.&amp;nbsp; The tracts layer has lots of multipart polygons, but this could be all merged into one polygon if that's possible in the code?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Nov 2025 21:10:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665657#M11618</guid>
      <dc:creator>LukeGilner1</dc:creator>
      <dc:date>2025-11-13T21:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard Data Expression Intersects</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665678#M11621</link>
      <description>&lt;P&gt;OK, this should give you what you're trying to do, but I haven't tested it. It loops through each tract, gets the intersecting lakes for that tract, then gets the intersecting area for each lake. Then it gets the total lake count. Note that the area is rounded to two decimal places.&lt;/P&gt;&lt;P&gt;It will take a while to process. You could test whether "Memorizing" the tracts and lakes layers makes it any faster.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var port = Portal("https://www.arcgis.com");

// Load layers
var tracts = FeatureSetByPortalItem(port, "b9fcbedac0384e32bc3dba6aec1a8cf6", 0);
var lakes = FeatureSetByPortalItem(port, "5564b2e702364aefba08df8c95216a1f", 0, ["OrgKeyID"]);
var lakesfilt = Filter(lakes, "OrgKeyID &amp;gt; 0");

var totalAcres = 0;
var arrTracts = [];
for (var tract in tracts) {
  var intersectingLakes = Intersects(lakesfilt, tract);
  Push(arrTracts, tract);
  for (var intersectingLake in intersectingLakes) {
    var lakePart = Intersection(tract, intersectingLake);
    totalAcres += Area(lakePart, "acres");
  }
}

var lakeCount = Count(Intersects(lakesfilt, Union(arrTracts)))

return FeatureSet(
  {
    fields: [
      { name: "LakeCount", type: "esriFieldTypeInteger" },
      { name: "Acres", type: "esriFieldTypeDouble" }
    ],
    features: [
      { attributes: { LakeCount: lakeCount, Acres: Round(totalAcres, 2) } }
    ]
  }
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Nov 2025 21:27:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665678#M11621</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-11-13T21:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard Data Expression Intersects</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665832#M11625</link>
      <description>&lt;P&gt;Awesome, thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/2839"&gt;@KenBuja&lt;/a&gt;.&amp;nbsp; This takes about 1.5 minutes to run, not too bad.&lt;/P&gt;&lt;P&gt;Something strange though.&amp;nbsp; The&amp;nbsp;&lt;SPAN&gt;totalAcres&lt;/SPAN&gt;&lt;SPAN&gt; += &lt;/SPAN&gt;&lt;SPAN&gt;Area&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;lakePart&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"acres"&lt;/SPAN&gt;&lt;SPAN&gt;); returns 3,815.7 acres,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;but&amp;nbsp;changing it to:&amp;nbsp;&lt;SPAN&gt;totalAcres&lt;/SPAN&gt;&lt;SPAN&gt; += &lt;/SPAN&gt;&lt;SPAN&gt;AreaGeodetic&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;lakePart&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"acres"&lt;/SPAN&gt;&lt;SPAN&gt;); correctly returns 1808.9 acres.&amp;nbsp; (ArcPro shows 1807.9).&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Nov 2025 14:34:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1665832#M11625</guid>
      <dc:creator>LukeGilner1</dc:creator>
      <dc:date>2025-11-14T14:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard Data Expression Intersects</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1666638#M11650</link>
      <description>&lt;P&gt;The main slowdown comes from looping all 11,200 lakes for every tract. To speed it up, you can filter lakes first using Intersects with the entire tracts layer or Filter on the lakes FeatureSet. Example:&lt;/P&gt;&lt;P&gt;var intersectingLakes = Filter(lakes, Intersects(lakes, Union(tracts)));&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Then loop over only intersectingLakes, reducing the number of comparisons from 11,200 to ~1,020. Also, use Geometry(lake) once per lake outside inner loops if possible, to avoid repeated geometry calculations.&lt;/P&gt;&lt;P&gt;This approach can cut runtime from 20 minutes to a few seconds.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Nov 2025 10:55:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1666638#M11650</guid>
      <dc:creator>MiaWhite34</dc:creator>
      <dc:date>2025-11-18T10:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard Data Expression Intersects</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1667109#M11652</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/947089"&gt;@MiaWhite34&lt;/a&gt;&amp;nbsp;could you show your recommendation using the code from the post marked as solution?&amp;nbsp; I'm still very new to arcade so the exact code would be helpful.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Nov 2025 13:51:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-intersects/m-p/1667109#M11652</guid>
      <dc:creator>LukeGilner1</dc:creator>
      <dc:date>2025-11-19T13:51:30Z</dc:date>
    </item>
  </channel>
</rss>

