<?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: Merge two result sets? in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/merge-two-result-sets/m-p/1126197#M5494</link>
    <description>&lt;LI-CODE lang="javascript"&gt;// summary FeatureSets
var no_loss_type_1 = {"fields":[{"name":"Category","type":"esriFieldTypeString"},{"name":"FeatureCount","type":"esriFieldTypeInteger"}],"geometryType":"","features":[{"attributes":{"Category":"A - No Impact","FeatureCount":35}},{"attributes":{"Category":"B - Material Excavation","FeatureCount":2}},{"attributes":{"Category":"D - Habitat Restoration","FeatureCount":3}},{"attributes":{"Category":"E - Stormwater Excavation","FeatureCount":8}},{"attributes":{"Category":"F - Utilities","FeatureCount":2}},{"attributes":{"Category":"H - Temporary Impact","FeatureCount":14}}]}
var no_loss_type_2 = {"fields":[{"name":"Category","type":"esriFieldTypeString"},{"name":"FeatureCount","type":"esriFieldTypeInteger"}],"geometryType":"","features":[{"attributes":{"Category":"B - Material Excavation","FeatureCount":1}},{"attributes":{"Category":"E - Stormwater Excavation","FeatureCount":3}},{"attributes":{"Category":"F - Utilities","FeatureCount":1}},{"attributes":{"Category":"H - Temporary Impact","FeatureCount":2}}]}
no_loss_type_1 = FeatureSet(Text(no_loss_type_1))
no_loss_type_2 = FeatureSet(Text(no_loss_type_2))

// This is ugly, but it works
var count_dict = {}  // dict of {Category: FeatureCount}
var cat_array = []  // to keep track of the dict keys
var fs_array = [no_loss_type_1, no_loss_type_2]  // FeatureSets to combine
for(var i in fs_array) {
    for(var f in fs_array[i]) {
        // get category and feature count
        var cat = f.Category
        var cnt = f.FeatureCount
        if(Includes(cat_array, cat)) {
            // cat already in dict? -&amp;gt; add the dict's value to cnt
            cnt += count_dict[cat]
        } else {
            // new cat? -&amp;gt; append cat to cat_array
            Push(cat_array, cat)
        }
        // add/update the count in count_dict
        count_dict[cat] = cnt
    }
}

// Create output FeatureSet
var out_fs = {
    "fields":[
        {"name":"Category","type":"esriFieldTypeString"},
        {"name":"FeatureCount","type":"esriFieldTypeInteger"},
        ],
    "geometryType":"",
    "features":[]
    }
// add features
for(var i in cat_array) {
    var cat = cat_array[i]
    var f = {"attributes": {"Category": cat, "FeatureCount": count_dict[cat]}}
    Push(out_fs.features, f)
}

return FeatureSet(Text(out_fs))&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1639557965858.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/29749iB5801E80A995E170/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1639557965858.png" alt="JohannesLindner_0-1639557965858.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Dec 2021 08:47:41 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2021-12-15T08:47:41Z</dc:date>
    <item>
      <title>Merge two result sets?</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/merge-two-result-sets/m-p/1126051#M5490</link>
      <description>&lt;P&gt;Greetings all-&lt;/P&gt;&lt;P&gt;I need to merge two summary results together to use in a serial chart in Dashboard.&amp;nbsp; The summary tables/results look like the following:&lt;/P&gt;&lt;P&gt;Summary 1 - NO_LOSS_TYPE1&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="198.031px" height="25px"&gt;&lt;STRONG&gt;Category&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;&lt;STRONG&gt;FeatureCount&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;&lt;STRONG&gt;FID&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="198.031px" height="25px"&gt;A - No Impact&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;35&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="198.031px" height="25px"&gt;B - Material Excavation&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;2&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="198.031px" height="25px"&gt;D - Habitat Restoration&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;3&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="198.031px" height="25px"&gt;E - Stormwater Excavation&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;8&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="198.031px" height="25px"&gt;F - Utilities&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;2&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="198.031px" height="25px"&gt;H - Temporary Impact&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;14&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Summary 2 - NO_LOSS_TYPE2&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="198.016px" height="24px"&gt;&lt;STRONG&gt;Category&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="111.156px" height="24px"&gt;&lt;STRONG&gt;FeatureCount&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="40px" height="24px"&gt;&lt;STRONG&gt;FID&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="198.016px" height="25px"&gt;B - Material Excavation&lt;/TD&gt;&lt;TD width="111.156px" height="25px"&gt;1&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="198.016px" height="25px"&gt;E - Stormwater Excavation&lt;/TD&gt;&lt;TD width="111.156px" height="25px"&gt;3&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="198.016px" height="25px"&gt;F - Utilities&lt;/TD&gt;&lt;TD width="111.156px" height="25px"&gt;1&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="198.016px" height="25px"&gt;H - Temporary Impact&lt;/TD&gt;&lt;TD width="111.156px" height="25px"&gt;2&lt;/TD&gt;&lt;TD width="40px" height="25px"&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see, sometimes the "Category" value matches.&amp;nbsp; If it matches the two result sets, I want to add the "FeatureCount" values together.&amp;nbsp; If the "Category" value doesn't exist, I want to append/add it to the output results.&lt;/P&gt;&lt;P&gt;So I'd ultimately like to end up with something like the following:&lt;/P&gt;&lt;TABLE border="1" width="75%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="38.225255972696246%"&gt;&lt;STRONG&gt;Category&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="45.39249146757679%"&gt;&lt;STRONG&gt;FeatureCount&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="16.21160409556314%"&gt;&lt;STRONG&gt;FID&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="38.225255972696246%" height="47px"&gt;A - No Impact&lt;/TD&gt;&lt;TD width="45.39249146757679%" height="47px"&gt;35&lt;/TD&gt;&lt;TD width="16.21160409556314%" height="47px"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="38.225255972696246%" height="91px"&gt;B - Material Excavation&lt;/TD&gt;&lt;TD width="45.39249146757679%" height="91px"&gt;3&amp;nbsp; (i.e., 2 + 1)&lt;/TD&gt;&lt;TD width="16.21160409556314%" height="91px"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="38.225255972696246%" height="47px"&gt;D - Habitat Restoration&lt;/TD&gt;&lt;TD width="45.39249146757679%" height="47px"&gt;3&lt;/TD&gt;&lt;TD width="16.21160409556314%" height="47px"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="38.225255972696246%" height="91px"&gt;E - Stormwater Excavation&lt;/TD&gt;&lt;TD width="45.39249146757679%" height="91px"&gt;11 (i.e,. 8 + 3)&lt;/TD&gt;&lt;TD width="16.21160409556314%" height="91px"&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="38.225255972696246%" height="91px"&gt;F - Utilities&lt;/TD&gt;&lt;TD width="45.39249146757679%" height="91px"&gt;3 (i.e., 3 + 1)&lt;/TD&gt;&lt;TD width="16.21160409556314%" height="91px"&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="38.225255972696246%" height="91px"&gt;H - Temporary Impact&lt;/TD&gt;&lt;TD width="45.39249146757679%" height="91px"&gt;16 (i.e., 14 + 2)&lt;/TD&gt;&lt;TD width="16.21160409556314%" height="91px"&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've managed to get the summary results okay, but am struggling with where to go next.&amp;nbsp; I've added those summary results to a dictionary, but then have trouble finding the corresponding keys in either of the dictionaries while trying to "merge" the two of them together.&amp;nbsp; I've been looping through one dictionary and using "HasKey()" to see if it has a corresponding key from the second dictionary, but that hasn't been finding the keys.&amp;nbsp; My "input" dictionaries look like this:&lt;/P&gt;&lt;P&gt;Dictionary 1&lt;/P&gt;&lt;P&gt;{"fields":[{"name":"Category","type":"esriFieldTypeString"},{"name":"FeatureCount","type":"esriFieldTypeInteger"}],"geometryType":"","features":[{"attributes":{"Category":"A - No Impact","FeatureCount":35}},{"attributes":{"Category":"B - Material Excavation","FeatureCount":2}},{"attributes":{"Category":"D - Habitat Restoration","FeatureCount":3}},{"attributes":{"Category":"E - Stormwater Excavation","FeatureCount":8}},{"attributes":{"Category":"F - Utilities","FeatureCount":2}},{"attributes":{"Category":"H - Temporary Impact","FeatureCount":14}}]}&lt;/P&gt;&lt;P&gt;Dictionary 2&lt;/P&gt;&lt;P&gt;{"fields":[{"name":"Category","type":"esriFieldTypeString"},{"name":"FeatureCount","type":"esriFieldTypeInteger"}],"geometryType":"","features":[{"attributes":{"Category":"B - Material Excavation","FeatureCount":1}},{"attributes":{"Category":"E - Stormwater Excavation","FeatureCount":3}},{"attributes":{"Category":"F - Utilities","FeatureCount":1}},{"attributes":{"Category":"H - Temporary Impact","FeatureCount":2}}]}&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 21:15:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/merge-two-result-sets/m-p/1126051#M5490</guid>
      <dc:creator>ToddLusk</dc:creator>
      <dc:date>2021-12-14T21:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two result sets?</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/merge-two-result-sets/m-p/1126197#M5494</link>
      <description>&lt;LI-CODE lang="javascript"&gt;// summary FeatureSets
var no_loss_type_1 = {"fields":[{"name":"Category","type":"esriFieldTypeString"},{"name":"FeatureCount","type":"esriFieldTypeInteger"}],"geometryType":"","features":[{"attributes":{"Category":"A - No Impact","FeatureCount":35}},{"attributes":{"Category":"B - Material Excavation","FeatureCount":2}},{"attributes":{"Category":"D - Habitat Restoration","FeatureCount":3}},{"attributes":{"Category":"E - Stormwater Excavation","FeatureCount":8}},{"attributes":{"Category":"F - Utilities","FeatureCount":2}},{"attributes":{"Category":"H - Temporary Impact","FeatureCount":14}}]}
var no_loss_type_2 = {"fields":[{"name":"Category","type":"esriFieldTypeString"},{"name":"FeatureCount","type":"esriFieldTypeInteger"}],"geometryType":"","features":[{"attributes":{"Category":"B - Material Excavation","FeatureCount":1}},{"attributes":{"Category":"E - Stormwater Excavation","FeatureCount":3}},{"attributes":{"Category":"F - Utilities","FeatureCount":1}},{"attributes":{"Category":"H - Temporary Impact","FeatureCount":2}}]}
no_loss_type_1 = FeatureSet(Text(no_loss_type_1))
no_loss_type_2 = FeatureSet(Text(no_loss_type_2))

// This is ugly, but it works
var count_dict = {}  // dict of {Category: FeatureCount}
var cat_array = []  // to keep track of the dict keys
var fs_array = [no_loss_type_1, no_loss_type_2]  // FeatureSets to combine
for(var i in fs_array) {
    for(var f in fs_array[i]) {
        // get category and feature count
        var cat = f.Category
        var cnt = f.FeatureCount
        if(Includes(cat_array, cat)) {
            // cat already in dict? -&amp;gt; add the dict's value to cnt
            cnt += count_dict[cat]
        } else {
            // new cat? -&amp;gt; append cat to cat_array
            Push(cat_array, cat)
        }
        // add/update the count in count_dict
        count_dict[cat] = cnt
    }
}

// Create output FeatureSet
var out_fs = {
    "fields":[
        {"name":"Category","type":"esriFieldTypeString"},
        {"name":"FeatureCount","type":"esriFieldTypeInteger"},
        ],
    "geometryType":"",
    "features":[]
    }
// add features
for(var i in cat_array) {
    var cat = cat_array[i]
    var f = {"attributes": {"Category": cat, "FeatureCount": count_dict[cat]}}
    Push(out_fs.features, f)
}

return FeatureSet(Text(out_fs))&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1639557965858.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/29749iB5801E80A995E170/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1639557965858.png" alt="JohannesLindner_0-1639557965858.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Dec 2021 08:47:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/merge-two-result-sets/m-p/1126197#M5494</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-12-15T08:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two result sets?</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/merge-two-result-sets/m-p/1126253#M5495</link>
      <description>&lt;P&gt;Thanks so much!&amp;nbsp; That was just about perfect but got me headed in the right direction.&amp;nbsp; Here was is my final implementation:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fs = FeatureSetByPortalItem(
    Portal('https://dakotacounty.maps.arcgis.com'),
    '3f1ab7bbf9674ccc851176de9d922450',
    5,
    ['OBJECTID', 'NO_LOSS_TYPE1', 'NO_LOSS_TYPE2'],
    false
);

// summary FeatureSets
var no_loss_type_1 = Filter(fs, 'NO_LOSS_TYPE1 IS NOT NULL');
var no_loss_type_2 = Filter(fs, 'NO_LOSS_TYPE2 IS NOT NULL');

// Grouped statistics
var group_type_1 = GroupBy(no_loss_type_1,
    [
        {name: 'Category',expression:'NO_LOSS_TYPE1'}
    ],
    [
        { name: 'FeatureCount', expression: 'OBJECTID', statistic: 'COUNT' }
    ]
);
var group_type_2 = GroupBy(no_loss_type_2,
    [
        {name: 'Category', expression:'NO_LOSS_TYPE2'}
    ],
    [
        {name: 'FeatureCount', expression: 'OBJECTID', statistic: 'COUNT' }
    ]
);

// This is ugly, but it works
var count_dict = {}  // dict of {Category: FeatureCount}
var cat_array = []  // to keep track of the dict keys
var fs_array = [group_type_1, group_type_2]  // FeatureSets to combine
for(var i in fs_array) {
    for(var f in fs_array[i]) {
        // get category and feature count
        var cat = f.Category
        var cnt = f.FeatureCount
        if(Includes(cat_array, cat)) {
            // cat already in dict? -&amp;gt; add the dict's value to cnt
            cnt += count_dict[cat]
        } else {
            // new cat? -&amp;gt; append cat to cat_array
            Push(cat_array, cat)
        }
        // add/update the count in count_dict
        count_dict[cat] = cnt
    }
}

// Create output FeatureSet
var out_fs = {
    "fields":[
        {"name":"Category","type":"esriFieldTypeString"},
        {"name":"FeatureCount","type":"esriFieldTypeInteger"},
        ],
    "geometryType":"",
    "features":[]
    }
// add features
for(var i in cat_array) {
    var cat = cat_array[i]
    var f = {"attributes": {"Category": cat, "FeatureCount": count_dict[cat]}}
    Push(out_fs.features, f)
}

return FeatureSet(Text(out_fs))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Dec 2021 14:24:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/merge-two-result-sets/m-p/1126253#M5495</guid>
      <dc:creator>ToddLusk</dc:creator>
      <dc:date>2021-12-15T14:24:45Z</dc:date>
    </item>
  </channel>
</rss>

