<?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: Map Viewer - Styles Data Expression - Return field A,B or C based on Max(X,Y,Z) in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/map-viewer-styles-data-expression-return-field-a-b/m-p/1411329#M58705</link>
    <description>&lt;P&gt;Thanks for your response! Sorry for my slow reply. I'm going to check out your solution as well.&lt;/P&gt;</description>
    <pubDate>Thu, 18 Apr 2024 00:59:13 GMT</pubDate>
    <dc:creator>BlakeMorrison</dc:creator>
    <dc:date>2024-04-18T00:59:13Z</dc:date>
    <item>
      <title>Map Viewer - Styles Data Expression - Return field A,B or C based on Max(X,Y,Z)</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/map-viewer-styles-data-expression-return-field-a-b/m-p/1407843#M58561</link>
      <description>&lt;P&gt;I have 3 editable fields, each of which is related to a 4th, 5th and 6th field. The idea is that field 4,5,6 are the held quantities of fields 1,2,3. I want to base the layer style on the highest held quantity of whatever item.&lt;/P&gt;&lt;P&gt;Eg.&lt;/P&gt;&lt;P&gt;Feature 1: Style based on Grapes=60&lt;/P&gt;&lt;P&gt;Field 1: Oranges ------------ Field 4: 45&lt;/P&gt;&lt;P&gt;Field 2: Apples ------------- Field 5: 10&lt;/P&gt;&lt;P&gt;Field 3: Grapes ------------- Field 6: 60&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Feature 2: Style based on Bananas = 80&lt;/P&gt;&lt;P&gt;Field 1: Apples ------------- Field 4: 15&lt;/P&gt;&lt;P&gt;Field 2: Bananas ------------- Field 5: 80&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've got the following code together which logically functions (finds and returns the appropriate pair of values), but I think I have an incorrect format being returned.&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 fields = [
          { name: $feature.item1 , value: $feature.quantity1 },
          { name: $feature.item2 , value: $feature.quantity2 },
          { name: $feature.item3 , value: $feature.quantity3 },
];

function comparevalue(a,b){
  if (a['value']&amp;gt;b['value'])
    return -1;
  if (a['value']&amp;lt;b['value'])
    return 1;
  return 0;
};

return First(Sort(fields,comparevalue))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above code returns:&lt;/P&gt;&lt;P&gt;dictionary&lt;BR /&gt;name: Grapes&lt;BR /&gt;value: 60&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but this is not usable to set a style apparrently.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2024 04:22:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/map-viewer-styles-data-expression-return-field-a-b/m-p/1407843#M58561</guid>
      <dc:creator>BlakeMorrison</dc:creator>
      <dc:date>2024-04-10T04:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: Map Viewer - Styles Data Expression - Return field A,B or C based on Max(X,Y,Z)</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/map-viewer-styles-data-expression-return-field-a-b/m-p/1408052#M58584</link>
      <description>&lt;P&gt;The &lt;A href="https://developers.arcgis.com/arcade/profiles/visualization/" target="_self"&gt;Arcade visualization profile&lt;/A&gt;, used for styling your data based on an Arcade expression, only accepts a return type of Number or Text. Dictionaries are not a supported return type in this profile.&lt;/P&gt;&lt;P&gt;You could create two separate expressions -- the first which finds the field name, and the second which gets the quantity/value of that field. Basically, you could use the same expression twice but specify either the name or value in the return.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;First(Sort(fields,comparevalue)).name // or value depending on expression&lt;/LI-CODE&gt;&lt;P&gt;Then use that with the "Types and Size" style.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2024 17:03:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/map-viewer-styles-data-expression-return-field-a-b/m-p/1408052#M58584</guid>
      <dc:creator>AnneFitz</dc:creator>
      <dc:date>2024-04-10T17:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: Map Viewer - Styles Data Expression - Return field A,B or C based on Max(X,Y,Z)</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/map-viewer-styles-data-expression-return-field-a-b/m-p/1411327#M58704</link>
      <description>&lt;P&gt;I got what I wanted working like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fields = [
          { alias: $feature.variety1 , value: $feature.var1_perc },
          { alias: $feature.variety2 , value: $feature.var2_perc },
          { alias: $feature.variety3 , value: $feature.var3_perc },
];

function getPredominantCategory(fields){
  var maxValue = null;
  var maxCategory = "";
  for(var k in fields){
    if(fields[k].value &amp;gt; maxValue){
      maxValue = fields[k].value;
      maxCategory = fields[k].alias;
    } else if (fields[k].value == maxValue){
      maxCategory = maxCategory + "/" + fields[k].alias;
    }
  }
  return IIF(maxValue &amp;lt;= 0, null, maxCategory);
}

getPredominantCategory(fields);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2024 00:57:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/map-viewer-styles-data-expression-return-field-a-b/m-p/1411327#M58704</guid>
      <dc:creator>BlakeMorrison</dc:creator>
      <dc:date>2024-04-18T00:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: Map Viewer - Styles Data Expression - Return field A,B or C based on Max(X,Y,Z)</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/map-viewer-styles-data-expression-return-field-a-b/m-p/1411329#M58705</link>
      <description>&lt;P&gt;Thanks for your response! Sorry for my slow reply. I'm going to check out your solution as well.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2024 00:59:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/map-viewer-styles-data-expression-return-field-a-b/m-p/1411329#M58705</guid>
      <dc:creator>BlakeMorrison</dc:creator>
      <dc:date>2024-04-18T00:59:13Z</dc:date>
    </item>
  </channel>
</rss>

