<?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 - Filtering Two Layers Before Merging them into a Single FeatureSet in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-filtering-two-layers-before/m-p/1262755#M7422</link>
    <description>&lt;P&gt;You can apply the &lt;STRONG&gt;Filter&lt;/STRONG&gt; function to each. The second parameter in a Filter is a SQL expression.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var PrelimPlans = Filter(
    FeatureSetByPortalItem(Portal('https://www.arcgis.com/'),'2a7c6c6f86b14253b1ecf079e3f4e6dd',1,['*'],false),
    "some_field = 'a value' OR another_field &amp;lt; 12"
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;And just a couple notes on the rest of the expression. If the appended features have the same fields for both input layers, you could do it all with a nested loop and keep your code shorter. And if you're on AGOL or a more recent version of Portal, there's no need for setting an index variable and incrementing, that's an outdated method. &lt;STRONG&gt;Push&lt;/STRONG&gt; can take care of it for you.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var sets = [
    Filter(FeatureSetByPortalItem(Portal('https://www.arcgis.com/'),'2a7c6c6f86b14253b1ecf079e3f4e6dd',1,['*'],false), 'some SQL expression'),
    Filter(FeatureSetByPortalItem(Portal('https://www.arcgis.com/'),'33c2a66277c34153907ba5d14484a24b',3,['*'],false), 'some SQL expression')
]

var combinedDict = { 
  'fields': [ 
    {name: "APNO", type:"esriFieldTypeString" },
    {name: "PROJNAME", type: "esriFieldTypeString" },
    {name: "LOC", type: "esriFieldTypeString" },
    {name: "CBPTEAM", type: "esriFieldTypeString" },
    {name: "PBDATE", type: "esriFieldTypeDate" },
    {name: "PENDING", type: "esriFieldTypeString" },
    {name: "DECISIONTYPE", type: "esriFieldTypeString" },
    {name: "STANDALONE", type: "esriFieldTypeString" },
    {name: "APPR_DU_TOT", type: "esriFieldTypeDouble" },
    {name: "APPR_DU_SF", type: "esriFieldTypeDouble" }, 
    {name: "APPR_DU_MF", type: "esriFieldTypeDouble" },
    {name: "APPR_SQFT_TOT", type: "esriFieldTypeDouble" },
    {name: "APPR_SQFT_OFF", type: "esriFieldTypeDouble" },
    {name: "APPR_SQFT_RET", type: "esriFieldTypeDouble" },
    {name: "APPR_SQFT_IND", type: "esriFieldTypeDouble" },
    {name: "APPR_SQFT_OTH", type: "esriFieldTypeDouble" },

  ], 
  geometryType: "", 
  features: [], 
};

for (var set in sets) {
    for (var feat in sets[set]) {
        Push(
            combinedDict['features'],
            {attributes: {
                APNO: feat["APNO"],
                PROJNAME: feat["PROJNAME"],
                CBPTEAM: feat["CBPTEAM"],
                PBDATE: Number(feat["PBDATE"]),
                PENDING: feat["PENDING"],
                DECISIONTYPE: feat["DECISIONTYPE"],
                APPR_DU_TOT: feat["APPR_DU_TOT"],
                APPR_DU_SF: feat["APPR_DU_SF"], 
                APPR_DU_MF: feat["APPR_DU_MF"],
                APPR_SQFT_TOT: feat["APPR_SQFT_TOT"],
                APPR_SQFT_OFF: feat["APPR_SQFT_OFF"],
                APPR_SQFT_RET: feat["APPR_SQFT_RET"],
                APPR_SQFT_IND: feat["APPR_SQFT_IND"],
                APPR_SQFT_OTH: feat["APPR_SQFT_OTH"],
            }}
        )
    }
}

return FeatureSet(Text(combinedDict))&lt;/LI-CODE&gt;&lt;P&gt;Also, if the output fields are coming wholesale from the input FeatureSets, you can use the &lt;STRONG&gt;Schema&lt;/STRONG&gt; function to help with that as well.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var combinedDict = {
    fields: Schema(some_FeatureSet)['fields'],
    geometryType: '',
    features: []
}&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 28 Feb 2023 21:46:28 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2023-02-28T21:46:28Z</dc:date>
    <item>
      <title>Arcade Data Expression - Filtering Two Layers Before Merging them into a Single FeatureSet</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-filtering-two-layers-before/m-p/1262748#M7421</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I am trying to filter two separate datasets before combining them into a single FeatureSet to be used in a dashboard but I am cannot seem to figure out how to filter these items correctly. I am able to filter these items in Insights and Pro but I don't seem to get the syntax right in arcade.&lt;/P&gt;&lt;P&gt;Below are two images from Insights with the correct Advanced Filters:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Prelim Advanced Filter.PNG" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/63945i3C08D165242D3933/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Prelim Advanced Filter.PNG" alt="Prelim Advanced Filter.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Siteplan - Advanced Filter.PNG" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/63946i1EA1C615D9519192/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Siteplan - Advanced Filter.PNG" alt="Siteplan - Advanced Filter.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea how to filter my datasets according to this query before I merge them together? Below is my current arcade script for combining these datasets.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var PrelimPlans = FeatureSetByPortalItem(Portal('https://www.arcgis.com/'),'2a7c6c6f86b14253b1ecf079e3f4e6dd',1,['*'],false);
var SitePlan = FeatureSetByPortalItem(Portal('https://www.arcgis.com/'),'33c2a66277c34153907ba5d14484a24b',3,['*'],false);

var combinedDict = { 
  'fields': [ 
    {name: "APNO", type:"esriFieldTypeString" },
    {name: "PROJNAME", type: "esriFieldTypeString" },
    {name: "LOC", type: "esriFieldTypeString" },
    {name: "CBPTEAM", type: "esriFieldTypeString" },
    {name: "PBDATE", type: "esriFieldTypeDate" },
    {name: "PENDING", type: "esriFieldTypeString" },
    {name: "DECISIONTYPE", type: "esriFieldTypeString" },
    {name: "STANDALONE", type: "esriFieldTypeString" },
    {name: "APPR_DU_TOT", type: "esriFieldTypeDouble" },
    {name: "APPR_DU_SF", type: "esriFieldTypeDouble" }, 
    {name: "APPR_DU_MF", type: "esriFieldTypeDouble" },
    {name: "APPR_SQFT_TOT", type: "esriFieldTypeDouble" },
    {name: "APPR_SQFT_OFF", type: "esriFieldTypeDouble" },
    {name: "APPR_SQFT_RET", type: "esriFieldTypeDouble" },
    {name: "APPR_SQFT_IND", type: "esriFieldTypeDouble" },
    {name: "APPR_SQFT_OTH", type: "esriFieldTypeDouble" },

  ], 
  geometryType: "", 
  features: [], 
};

var i = 0; 
// Loop through each FeatureSet and store its attributes 
for (var t in PrelimPlans) { 
  combinedDict.features[i++] = { 
    attributes: {
      APNO: t["APNO"],
      PROJNAME: t["PROJNAME"],
      CBPTEAM: t["CBPTEAM"],
      PBDATE: Number(t["PBDATE"]),
      PENDING: t["PENDING"],
      DECISIONTYPE: t["DECISIONTYPE"],
      APPR_DU_TOT: t["APPR_DU_TOT"],
      APPR_DU_SF: t["APPR_DU_SF"], 
      APPR_DU_MF: t["APPR_DU_MF"],
      APPR_SQFT_TOT: t["APPR_SQFT_TOT"],
      APPR_SQFT_OFF: t["APPR_SQFT_OFF"],
      APPR_SQFT_RET: t["APPR_SQFT_RET"],
      APPR_SQFT_IND: t["APPR_SQFT_IND"],
      APPR_SQFT_OTH: t["APPR_SQFT_OTH"],
    }, 
  }; 
} 

for (var m in SitePlan) { 
  combinedDict.features[i++] = { 
    attributes: { 
      APNO: m["APNO"],
      PROJNAME: m["PROJNAME"],
      CBPTEAM: m["CBPTEAM"],
      PBDATE: Number(m["PBDATE"]),
      PENDING: m["PENDING"],
      DECISIONTYPE: m["DECISIONTYPE"],
      STANDALONE: m["STANDALONE"],
      APPR_DU_TOT: m["APPR_DU_TOT"],
      APPR_DU_SF: m["APPR_DU_SF"], 
      APPR_DU_MF: m["APPR_DU_MF"],
      APPR_SQFT_TOT: m["APPR_SQFT_TOT"],
      APPR_SQFT_OFF: m["APPR_SQFT_OFF"],
      APPR_SQFT_RET: m["APPR_SQFT_RET"],
      APPR_SQFT_IND: m["APPR_SQFT_IND"],
      APPR_SQFT_OTH: m["APPR_SQFT_OTH"],
    }, 
  }; 
}
return FeatureSet(Text(combinedDict))&lt;/LI-CODE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;&lt;P&gt;All the best,&lt;/P&gt;&lt;P&gt;Colin&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 21:26:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-filtering-two-layers-before/m-p/1262748#M7421</guid>
      <dc:creator>C_McNamara</dc:creator>
      <dc:date>2023-02-28T21:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression - Filtering Two Layers Before Merging them into a Single FeatureSet</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-filtering-two-layers-before/m-p/1262755#M7422</link>
      <description>&lt;P&gt;You can apply the &lt;STRONG&gt;Filter&lt;/STRONG&gt; function to each. The second parameter in a Filter is a SQL expression.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var PrelimPlans = Filter(
    FeatureSetByPortalItem(Portal('https://www.arcgis.com/'),'2a7c6c6f86b14253b1ecf079e3f4e6dd',1,['*'],false),
    "some_field = 'a value' OR another_field &amp;lt; 12"
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;And just a couple notes on the rest of the expression. If the appended features have the same fields for both input layers, you could do it all with a nested loop and keep your code shorter. And if you're on AGOL or a more recent version of Portal, there's no need for setting an index variable and incrementing, that's an outdated method. &lt;STRONG&gt;Push&lt;/STRONG&gt; can take care of it for you.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var sets = [
    Filter(FeatureSetByPortalItem(Portal('https://www.arcgis.com/'),'2a7c6c6f86b14253b1ecf079e3f4e6dd',1,['*'],false), 'some SQL expression'),
    Filter(FeatureSetByPortalItem(Portal('https://www.arcgis.com/'),'33c2a66277c34153907ba5d14484a24b',3,['*'],false), 'some SQL expression')
]

var combinedDict = { 
  'fields': [ 
    {name: "APNO", type:"esriFieldTypeString" },
    {name: "PROJNAME", type: "esriFieldTypeString" },
    {name: "LOC", type: "esriFieldTypeString" },
    {name: "CBPTEAM", type: "esriFieldTypeString" },
    {name: "PBDATE", type: "esriFieldTypeDate" },
    {name: "PENDING", type: "esriFieldTypeString" },
    {name: "DECISIONTYPE", type: "esriFieldTypeString" },
    {name: "STANDALONE", type: "esriFieldTypeString" },
    {name: "APPR_DU_TOT", type: "esriFieldTypeDouble" },
    {name: "APPR_DU_SF", type: "esriFieldTypeDouble" }, 
    {name: "APPR_DU_MF", type: "esriFieldTypeDouble" },
    {name: "APPR_SQFT_TOT", type: "esriFieldTypeDouble" },
    {name: "APPR_SQFT_OFF", type: "esriFieldTypeDouble" },
    {name: "APPR_SQFT_RET", type: "esriFieldTypeDouble" },
    {name: "APPR_SQFT_IND", type: "esriFieldTypeDouble" },
    {name: "APPR_SQFT_OTH", type: "esriFieldTypeDouble" },

  ], 
  geometryType: "", 
  features: [], 
};

for (var set in sets) {
    for (var feat in sets[set]) {
        Push(
            combinedDict['features'],
            {attributes: {
                APNO: feat["APNO"],
                PROJNAME: feat["PROJNAME"],
                CBPTEAM: feat["CBPTEAM"],
                PBDATE: Number(feat["PBDATE"]),
                PENDING: feat["PENDING"],
                DECISIONTYPE: feat["DECISIONTYPE"],
                APPR_DU_TOT: feat["APPR_DU_TOT"],
                APPR_DU_SF: feat["APPR_DU_SF"], 
                APPR_DU_MF: feat["APPR_DU_MF"],
                APPR_SQFT_TOT: feat["APPR_SQFT_TOT"],
                APPR_SQFT_OFF: feat["APPR_SQFT_OFF"],
                APPR_SQFT_RET: feat["APPR_SQFT_RET"],
                APPR_SQFT_IND: feat["APPR_SQFT_IND"],
                APPR_SQFT_OTH: feat["APPR_SQFT_OTH"],
            }}
        )
    }
}

return FeatureSet(Text(combinedDict))&lt;/LI-CODE&gt;&lt;P&gt;Also, if the output fields are coming wholesale from the input FeatureSets, you can use the &lt;STRONG&gt;Schema&lt;/STRONG&gt; function to help with that as well.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var combinedDict = {
    fields: Schema(some_FeatureSet)['fields'],
    geometryType: '',
    features: []
}&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 28 Feb 2023 21:46:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-filtering-two-layers-before/m-p/1262755#M7422</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-02-28T21:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression - Filtering Two Layers Before Merging them into a Single FeatureSet</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-filtering-two-layers-before/m-p/1262991#M7426</link>
      <description>&lt;P&gt;Thank you, Josh &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;. I really appreciate your help!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Enjoy the rest of your week!&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Colin&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 13:32:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-filtering-two-layers-before/m-p/1262991#M7426</guid>
      <dc:creator>C_McNamara</dc:creator>
      <dc:date>2023-03-01T13:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression - Filtering Two Layers Before Merging them into a Single FeatureSet</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-filtering-two-layers-before/m-p/1505205#M9965</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for this code. I have used the same feature ID for the two features and that leads to have double the number of records which doesn't happen. It gives me only the number of records of one feature only.&lt;/P&gt;&lt;P&gt;Hope to hear from you soon.&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Oussama&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jul 2024 21:48:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-filtering-two-layers-before/m-p/1505205#M9965</guid>
      <dc:creator>OussamaMerhi</dc:creator>
      <dc:date>2024-07-14T21:48:28Z</dc:date>
    </item>
  </channel>
</rss>

