<?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: How to return distinct values from a related table? in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/how-to-return-distinct-values-from-a-related-table/m-p/1392933#M57972</link>
    <description>&lt;P&gt;There is a &lt;A href="https://developers.arcgis.com/arcade/function-reference/array_functions/#distinct" target="_self"&gt;Distinct&lt;/A&gt; function available in Arcade you can use to do this, however, you need to have an&amp;nbsp;&lt;A href="https://developers.arcgis.com/arcade/function-reference/array_functions/#array" target="_self"&gt;Array&lt;/A&gt;&amp;nbsp;to return the unique values from. If you populate your result values into an array, you can use the Distinct function to return the unique results.&lt;/P&gt;&lt;P&gt;If you are happy with returning an array, then you can use the script below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fs = FeatureSetByName($map, "returnDistinct" , ['*'], false);

var fsArray = Array(1);
var fsCount = Count(fs);

// check for features
if (fsCount &amp;gt; 0) {
    for (var f in fs) {
        // for each feature, add to the array
        Push(fsArray, f.name)
    } 
} else {
    return "No records available";
}

// return distinct values
return Distinct(fsArray);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you prefer to return a text string instead, I modified the script slightly so that you can do that too. Just noting however that the first line returned is a "null" value creating an empty first line, which is why I've also added an Erase function to remove the 0 index.&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 fs = FeatureSetByName($map, "returnDistinct" , ['*'], false);

var fsArray = Array(1);
var fsCount = Count(fs);

// check for features
if (fsCount &amp;gt; 0) {
    for (var f in fs) {
        // for each feature, add to the array
        Push(fsArray, f.name)
    }
} else {
    return "No records available";
}

// return distinct values
// return Distinct(fsArray);

// return distinct values text
Erase(fsArray, 0); // remove 0-index "null" field
return Concatenate(Distinct(fsArray), TextFormatting.NewLine);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope that helps!&lt;/P&gt;</description>
    <pubDate>Thu, 07 Mar 2024 23:20:36 GMT</pubDate>
    <dc:creator>RoryMcPherson</dc:creator>
    <dc:date>2024-03-07T23:20:36Z</dc:date>
    <item>
      <title>How to return distinct values from a related table?</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-return-distinct-values-from-a-related-table/m-p/1391769#M57888</link>
      <description>&lt;P&gt;Hello!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an Arcade expression which returns values from a related table within a popup. It works great except that it returns every value in the 1:M relationship, so there are many duplicates. Is it possible to modify my expression to only return the distinct values from the related records? Any help is appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My expression&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var fs = FeatureSetByName($map, "RELATED TABLE" , ['*'], false);
var result = "";
var cnt = Count(fs);
if (cnt &amp;gt; 0) {
    // start loop through related records
    for (var f in fs) {
        // for each f (=feature) in related features, add attendee to the result
        result += TextFormatting.NewLine + f.FIELDRETURNED;
    }    
} else {
    // overwrite result with text to indicate that there are no attendees
    result = "";
}

return result;&lt;/LI-CODE&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 13:00:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-return-distinct-values-from-a-related-table/m-p/1391769#M57888</guid>
      <dc:creator>DaveK</dc:creator>
      <dc:date>2024-03-06T13:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to return distinct values from a related table?</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-return-distinct-values-from-a-related-table/m-p/1392933#M57972</link>
      <description>&lt;P&gt;There is a &lt;A href="https://developers.arcgis.com/arcade/function-reference/array_functions/#distinct" target="_self"&gt;Distinct&lt;/A&gt; function available in Arcade you can use to do this, however, you need to have an&amp;nbsp;&lt;A href="https://developers.arcgis.com/arcade/function-reference/array_functions/#array" target="_self"&gt;Array&lt;/A&gt;&amp;nbsp;to return the unique values from. If you populate your result values into an array, you can use the Distinct function to return the unique results.&lt;/P&gt;&lt;P&gt;If you are happy with returning an array, then you can use the script below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fs = FeatureSetByName($map, "returnDistinct" , ['*'], false);

var fsArray = Array(1);
var fsCount = Count(fs);

// check for features
if (fsCount &amp;gt; 0) {
    for (var f in fs) {
        // for each feature, add to the array
        Push(fsArray, f.name)
    } 
} else {
    return "No records available";
}

// return distinct values
return Distinct(fsArray);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you prefer to return a text string instead, I modified the script slightly so that you can do that too. Just noting however that the first line returned is a "null" value creating an empty first line, which is why I've also added an Erase function to remove the 0 index.&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 fs = FeatureSetByName($map, "returnDistinct" , ['*'], false);

var fsArray = Array(1);
var fsCount = Count(fs);

// check for features
if (fsCount &amp;gt; 0) {
    for (var f in fs) {
        // for each feature, add to the array
        Push(fsArray, f.name)
    }
} else {
    return "No records available";
}

// return distinct values
// return Distinct(fsArray);

// return distinct values text
Erase(fsArray, 0); // remove 0-index "null" field
return Concatenate(Distinct(fsArray), TextFormatting.NewLine);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope that helps!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 23:20:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-return-distinct-values-from-a-related-table/m-p/1392933#M57972</guid>
      <dc:creator>RoryMcPherson</dc:creator>
      <dc:date>2024-03-07T23:20:36Z</dc:date>
    </item>
  </channel>
</rss>

