<?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 ArcGIS dashboards Data Expression including Rank in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboards-data-expression-including-rank/m-p/1541562#M10312</link>
    <description>&lt;P&gt;Hello -&lt;/P&gt;&lt;P&gt;I have created the below data expression in the code box to select the fields I need from the source layer and it works but I want to create a new variable for rank which will rank the field PR_EXHYDPAR (double) after ordering it. I can use the below code in Pro to calculate rank, but cannot figure out how to incorporate it into the Dashboard Data Expression. I would prefer to do this on the fly than add additional fields to my layer which would have to be updated regularly when the data is updated (There are 7 fields I need to create ranks for).&amp;nbsp;Can anyone provide guidance on how to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var setfeatures = FeatureSetByName($datastore, "SNP_Project");&lt;/P&gt;&lt;P&gt;var ordered = OrderBy(setfeatures, 'PR_EXHYPDAR DESC')&lt;/P&gt;&lt;P&gt;var rank = 0&lt;BR /&gt;for(var f in ordered) {&lt;BR /&gt;rank++&lt;BR /&gt;if(f.OBJECTID == $feature.OBJECTID) {&lt;BR /&gt;return rank&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var port = Portal('https://www.arcgis.com');
var fs = filter(FeatureSetByPortalItem(
  port,'01610f3a8912467c8b06f4b223a6b5e1', 0,
  ['PROJECTID', 'PR_PROJNAME', 'PR_STATUS', 'PR_ORIGTOTCOST', 'PR_P6TOTCOST', 'PR_EXHYDPAR', 'PR_EXSTRPAR', 'PR_EXTOTPAR', 'PR_ALTHYDPAR', 'PR_ALTSTRPAR', 'PR_ALTTOTPAR', 'PR_REDHYDPAR', 'PR_REDSTRPAR', 'PR_REDTOTPAR', 'PR_TOTNOMSCORE', 'PR_TOTSCORE',  'PR_WAC', 'PR_SUBWATERSHED', 'PR_COMMUNITY1', 'PR_MODELDATE', 'PR_PARTOOLDATE', 'PR_SWIM_ONLY', 'PR_PART_ONLY', 'PR_NONDISTRICT', 'PR_STRPARDATE'], 
  false),
  "PR_SWIM_ONLY='No' AND PR_PART_ONLY='No' AND  PR_NONDISTRICT='No' AND (PR_STATUS='01. Submitted – Pending Review/Scoring' OR PR_STATUS='02. Scored' OR PR_STATUS='03. Advanced SW Planning' OR PR_STATUS='04. Design' OR PR_STATUS='05. Construction' OR PR_STATUS='07. Completed')"
);

var out_dict = {
    fields: [
        {name: 'projectid', type: 'esriFieldTypeString'},
        {name: 'projname', type: 'esriFieldTypeString'},
        {name: 'status', type: 'esriFieldTypeString'},
        {name: 'origtotcost', type: 'esriFieldTypeDouble'},
        {name: 'P6totcost', type: 'esriFieldTypeDouble'},
        {name: 'exhydpar', type: 'esriFieldTypeDouble'},
        {name: 'exstrpar', type: 'esriFieldTypeDouble'},
        {name: 'extotpar', type: 'esriFieldTypeDouble'},
        {name: 'althydpar', type: 'esriFieldTypeDouble'},
        {name: 'altstrpar', type: 'esriFieldTypeDouble'},
        {name: 'alttotpar', type: 'esriFieldTypeDouble'},
        {name: 'redhydpar', type: 'esriFieldTypeDouble'},
        {name: 'redstrpar', type: 'esriFieldTypeDouble'},
        {name: 'redtotpar', type: 'esriFieldTypeDouble'},
        {name: 'totnomscore', type: 'esriFieldTypeInteger'},
        {name: 'totscore', type: 'esriFieldTypeDouble'},        
        {name: 'wac', type: 'esriFieldTypeString'},
        {name: 'subwatershed', type: 'esriFieldTypeString'},
        {name: 'community1', type: 'esriFieldTypeString'},
        {name: 'modeldate', type: 'esriFieldTypeDate'},
        {name: 'partooldate', type: 'esriFieldTypeDate'},
        {name: 'strpardate', type: 'esriFieldTypeDate'},        
        {name: 'swimonly', type: 'esriFieldTypeString'},
        {name: 'partonly', type: 'esriFieldTypeString'},
        {name: 'nondistr', type: 'esriFieldTypeString'},
     ],
    geometryType: '',
    features: []
}

// Iterate over each feature in the layer
for (var f in fs){
    
    Push(
        out_dict['features'],
        {attributes:
            {
                projectid: Text(f['PROJECTID']),
                projname: Text(f['PR_PROJNAME']),
                status: Text(f['PR_STATUS']),
                origtotcost: Number(f['PR_ORIGTOTCOST']),
                P6totcost: Number(f['PR_P6TOTCOST']),
                exhydpars: Number(f['PR_EXHYDPAR']),
                exstrpar: Number(f['PR_EXSTRPAR']),
                extotpar: Number(f['PR_EXTOTPAR']),
                althydpar: Number(f['PR_ALTHYDPAR']),
                altstrpar: Number(f['PR_ALTSTRPAR']),
                alttotpar: Number(f['PR_ALTTOTPAR']),
                redhydpar: Number(f['PR_REDHYDPAR']),
                redstrpar: Number(f['PR_REDSTRPAR']),
                redtotpar: Number(f['PR_REDTOTPAR']),
                totnomscore: Number(f['PR_TOTNOMSCORE']),
                totscore: Number(f['PR_TOTSCORE']),
                wac: Text(f['PR_WAC']),
                subwatershed: Text(f['PR_SUBWATERSHED']),
                community1: Text(f['PR_COMMUNITY1']),
                modeldate: Date(f['PR_MODELDATE']),
                partooldate: Date(f['PR_PARTOOLDATE']),
                strpardate: Date(f['PR_STRPARDATE']),
                swimonly: Text(f['PR_SWIM_ONLY']),
                partonly: Text(f['PR_PART_ONLY']),
                nondistr: Text(f['PR_NONDISTRICT']),
                            }
        }
    )
}

//Return populated out_dict as FeatureSet
var par = FeatureSet(Text(out_dict))

return par&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 23 Sep 2024 18:06:06 GMT</pubDate>
    <dc:creator>LJackson29</dc:creator>
    <dc:date>2024-09-23T18:06:06Z</dc:date>
    <item>
      <title>ArcGIS dashboards Data Expression including Rank</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboards-data-expression-including-rank/m-p/1541562#M10312</link>
      <description>&lt;P&gt;Hello -&lt;/P&gt;&lt;P&gt;I have created the below data expression in the code box to select the fields I need from the source layer and it works but I want to create a new variable for rank which will rank the field PR_EXHYDPAR (double) after ordering it. I can use the below code in Pro to calculate rank, but cannot figure out how to incorporate it into the Dashboard Data Expression. I would prefer to do this on the fly than add additional fields to my layer which would have to be updated regularly when the data is updated (There are 7 fields I need to create ranks for).&amp;nbsp;Can anyone provide guidance on how to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var setfeatures = FeatureSetByName($datastore, "SNP_Project");&lt;/P&gt;&lt;P&gt;var ordered = OrderBy(setfeatures, 'PR_EXHYPDAR DESC')&lt;/P&gt;&lt;P&gt;var rank = 0&lt;BR /&gt;for(var f in ordered) {&lt;BR /&gt;rank++&lt;BR /&gt;if(f.OBJECTID == $feature.OBJECTID) {&lt;BR /&gt;return rank&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var port = Portal('https://www.arcgis.com');
var fs = filter(FeatureSetByPortalItem(
  port,'01610f3a8912467c8b06f4b223a6b5e1', 0,
  ['PROJECTID', 'PR_PROJNAME', 'PR_STATUS', 'PR_ORIGTOTCOST', 'PR_P6TOTCOST', 'PR_EXHYDPAR', 'PR_EXSTRPAR', 'PR_EXTOTPAR', 'PR_ALTHYDPAR', 'PR_ALTSTRPAR', 'PR_ALTTOTPAR', 'PR_REDHYDPAR', 'PR_REDSTRPAR', 'PR_REDTOTPAR', 'PR_TOTNOMSCORE', 'PR_TOTSCORE',  'PR_WAC', 'PR_SUBWATERSHED', 'PR_COMMUNITY1', 'PR_MODELDATE', 'PR_PARTOOLDATE', 'PR_SWIM_ONLY', 'PR_PART_ONLY', 'PR_NONDISTRICT', 'PR_STRPARDATE'], 
  false),
  "PR_SWIM_ONLY='No' AND PR_PART_ONLY='No' AND  PR_NONDISTRICT='No' AND (PR_STATUS='01. Submitted – Pending Review/Scoring' OR PR_STATUS='02. Scored' OR PR_STATUS='03. Advanced SW Planning' OR PR_STATUS='04. Design' OR PR_STATUS='05. Construction' OR PR_STATUS='07. Completed')"
);

var out_dict = {
    fields: [
        {name: 'projectid', type: 'esriFieldTypeString'},
        {name: 'projname', type: 'esriFieldTypeString'},
        {name: 'status', type: 'esriFieldTypeString'},
        {name: 'origtotcost', type: 'esriFieldTypeDouble'},
        {name: 'P6totcost', type: 'esriFieldTypeDouble'},
        {name: 'exhydpar', type: 'esriFieldTypeDouble'},
        {name: 'exstrpar', type: 'esriFieldTypeDouble'},
        {name: 'extotpar', type: 'esriFieldTypeDouble'},
        {name: 'althydpar', type: 'esriFieldTypeDouble'},
        {name: 'altstrpar', type: 'esriFieldTypeDouble'},
        {name: 'alttotpar', type: 'esriFieldTypeDouble'},
        {name: 'redhydpar', type: 'esriFieldTypeDouble'},
        {name: 'redstrpar', type: 'esriFieldTypeDouble'},
        {name: 'redtotpar', type: 'esriFieldTypeDouble'},
        {name: 'totnomscore', type: 'esriFieldTypeInteger'},
        {name: 'totscore', type: 'esriFieldTypeDouble'},        
        {name: 'wac', type: 'esriFieldTypeString'},
        {name: 'subwatershed', type: 'esriFieldTypeString'},
        {name: 'community1', type: 'esriFieldTypeString'},
        {name: 'modeldate', type: 'esriFieldTypeDate'},
        {name: 'partooldate', type: 'esriFieldTypeDate'},
        {name: 'strpardate', type: 'esriFieldTypeDate'},        
        {name: 'swimonly', type: 'esriFieldTypeString'},
        {name: 'partonly', type: 'esriFieldTypeString'},
        {name: 'nondistr', type: 'esriFieldTypeString'},
     ],
    geometryType: '',
    features: []
}

// Iterate over each feature in the layer
for (var f in fs){
    
    Push(
        out_dict['features'],
        {attributes:
            {
                projectid: Text(f['PROJECTID']),
                projname: Text(f['PR_PROJNAME']),
                status: Text(f['PR_STATUS']),
                origtotcost: Number(f['PR_ORIGTOTCOST']),
                P6totcost: Number(f['PR_P6TOTCOST']),
                exhydpars: Number(f['PR_EXHYDPAR']),
                exstrpar: Number(f['PR_EXSTRPAR']),
                extotpar: Number(f['PR_EXTOTPAR']),
                althydpar: Number(f['PR_ALTHYDPAR']),
                altstrpar: Number(f['PR_ALTSTRPAR']),
                alttotpar: Number(f['PR_ALTTOTPAR']),
                redhydpar: Number(f['PR_REDHYDPAR']),
                redstrpar: Number(f['PR_REDSTRPAR']),
                redtotpar: Number(f['PR_REDTOTPAR']),
                totnomscore: Number(f['PR_TOTNOMSCORE']),
                totscore: Number(f['PR_TOTSCORE']),
                wac: Text(f['PR_WAC']),
                subwatershed: Text(f['PR_SUBWATERSHED']),
                community1: Text(f['PR_COMMUNITY1']),
                modeldate: Date(f['PR_MODELDATE']),
                partooldate: Date(f['PR_PARTOOLDATE']),
                strpardate: Date(f['PR_STRPARDATE']),
                swimonly: Text(f['PR_SWIM_ONLY']),
                partonly: Text(f['PR_PART_ONLY']),
                nondistr: Text(f['PR_NONDISTRICT']),
                            }
        }
    )
}

//Return populated out_dict as FeatureSet
var par = FeatureSet(Text(out_dict))

return par&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2024 18:06:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboards-data-expression-including-rank/m-p/1541562#M10312</guid>
      <dc:creator>LJackson29</dc:creator>
      <dc:date>2024-09-23T18:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS dashboards Data Expression including Rank</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboards-data-expression-including-rank/m-p/1541617#M10314</link>
      <description>&lt;P&gt;Sorting and looping through would work with a single field, but even that can take a while to execute. Adding multiple fields, well, that will be a really long-running expression.&lt;/P&gt;&lt;P&gt;There may be a better way to approach this, but it will still result in tons of queries to the server. You could try using a custom function to "memorize" the FeatureSet first, which will speed things up a lot. (&lt;A href="https://www.jcarlson.page/posts/dashboards-memorize/" target="_blank"&gt;https://www.jcarlson.page/posts/dashboards-memorize/&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;To get the rank of each field in a single loop, we just need some filtering. You can do a filter and see how many features are greater/less than the current feature, and that's basically the rank. Maybe add 1 to it? The smallest value in a field will have no features less than it, so the filtered count + 1 = 1, that's it's rank.&lt;/P&gt;&lt;P&gt;Since we're doing this repeatedly for multiple fields we could use another custom function for the rank.&lt;/P&gt;&lt;P&gt;Here's an example, just swap in your values as needed:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function Memorize(fs) {
  var temp_dict = {
    fields: Schema(fs)['fields'],
    geometryType: '',
    features: []
  }

  for (var f in fs) {
    var attrs = {}

    for (var attr in f) {
      attrs[attr] = Iif(TypeOf(f[attr]) == 'Date', Number(f[attr]), f[attr])
    }

    Push(
      temp_dict['features'],
      {attributes: attrs}
    )
  }

  return FeatureSet(Text(temp_dict))
}

function getRank(feat, field, set){
  var filt_val = feat[field]
  var filt_set = Filter(set, `${field} &amp;lt; @filt_val`)
  return Count(filt_set)
}

var fs = Memorize(Filter(FeatureSetByPortalItem(
  Portal("https://www.arcgis.com"),
  "6200db0b80de4341ae8ee2b62d606e67",
  0,
  ["*"],
  false
), 'OBJECTID &amp;lt; 100'))

// ranks to add to the output
var rank_fields = [
  {name: 'objectid_rank', type:'esriFieldTypeInteger'},
  {name: 'eaveheight_rank', type:'esriFieldTypeInteger'},
  {name: 'area_rank', type:'esriFieldTypeInteger'}
]

var out_dict = {
  fields: Splice(Schema(fs)['fields'], rank_fields),
  geometryType: '',
  features: []
}

var full_count = Count(fs)

for (var f in fs) {
  // convert feature to dict
  var feat_dict = FromJSON(Text(f))

  // calculate ranks
  feat_dict['attributes']['objectid_rank'] = getRank(f, 'OBJECTID', fs)
  feat_dict['attributes']['eaveheight_rank'] = getRank(f, 'EAVEHEIGHT', fs)
  feat_dict['attributes']['area_rank'] = getRank(f, 'SHAPE__Area', fs)

  // convert back to feature, push into output
  Push(out_dict['features'], Feature(feat_dict))
}

return FeatureSet(Text(out_dict))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1727120394987.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/115709iEC5519E56265DE66/image-size/large?v=v2&amp;amp;px=999" role="button" title="jcarlson_0-1727120394987.png" alt="jcarlson_0-1727120394987.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2024 19:40:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboards-data-expression-including-rank/m-p/1541617#M10314</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-09-23T19:40:07Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS dashboards Data Expression including Rank</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboards-data-expression-including-rank/m-p/1541618#M10315</link>
      <description>&lt;P&gt;I forgot to add 1 to the rank! Just change line 27 to be &lt;STRONG&gt;return Count(filt_set)+1&lt;/STRONG&gt; if you want that. I don't really mind it being zero-indexed, as long as it's correctly calculating the ranks.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2024 19:41:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboards-data-expression-including-rank/m-p/1541618#M10315</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-09-23T19:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS dashboards Data Expression including Rank</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboards-data-expression-including-rank/m-p/1541654#M10318</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;Thanks for your help on this. I can't seem to get it to run - surely user error. See the code in the code block with my questions, and let me know where you think I am going wrong. Many thanks!&lt;/P&gt;&lt;LI-CODE lang="c"&gt;//Memorize function

function Memorize(fs) {

// is this saying use the schema from fs identified below including fields, geometry and features?
  var temp_dict = {
    fields: Schema(fs)['fields'],
    geometryType: '',
    features: []
  }

// what is this section doing?

  for (var f in fs) {
    var attrs = {}

    for (var attr in f) {
      attrs[attr] = Iif(TypeOf(f[attr]) == 'Date', Number(f[attr]), f[attr])
    }

    Push(
      temp_dict['features'],
      {attributes: attrs}
    )
  }

  return FeatureSet(Text(temp_dict))
}

//How does this code identify the lowest value and starts there?
//Rank Function
function getRank(feat, field, set){
  var filt_val = feat[field]
  var filt_set = Filter(set, '${field} &amp;lt; @filt_val')
  return Count(filt_set)+1
}


var fs = Memorize(filter(FeatureSetByPortalItem(
  portal,'01610f3a8912467c8b06f4b223a6b5e1', 0,
  ['PROJECTID', 'PR_PROJNAME', 'PR_STATUS', 'PR_ORIGTOTCOST', 'PR_P6TOTCOST', 'PR_EXHYDPAR', 'PR_EXSTRPAR', 'PR_EXTOTPAR', 'PR_ALTHYDPAR', 'PR_ALTSTRPAR', 'PR_ALTTOTPAR', 'PR_REDHYDPAR', 'PR_REDSTRPAR', 'PR_REDTOTPAR', 'PR_TOTNOMSCORE', 'PR_TOTSCORE',  'PR_WAC', 'PR_SUBWATERSHED', 'PR_COMMUNITY1', 'PR_MODELDATE', 'PR_PARTOOLDATE', 'PR_SWIM_ONLY', 'PR_PART_ONLY', 'PR_NONDISTRICT', 'PR_STRPARDATE'], 
  false),
  ("PR_SWIM_ONLY='No' AND PR_PART_ONLY='No' AND  PR_NONDISTRICT='No' AND (PR_STATUS='01. Submitted – Pending Review/Scoring' OR PR_STATUS='02. Scored' OR PR_STATUS='03. Advanced SW Planning' OR PR_STATUS='04. Design' OR PR_STATUS='05. Construction' OR PR_STATUS='07. Completed')"
  )))


// ranks to add to the output
var rank_fields = [
  {name: 'exhydpar_rank', type:'esriFieldTypeInteger'},
  {name: 'exstrpar_rank', type:'esriFieldTypeInteger'},
  {name: 'extotpar_rank', type:'esriFieldTypeInteger'}
]

var out_dict = {
  fields: Splice(Schema(fs)['fields'], rank_fields),
  geometryType: '',
  features: []
}

// How is full_count used? I am getting a warning that it is not used
var full_count = Count(fs)

for (var f in fs) {
  // convert feature to dict
  var feat_dict = FromJSON(Text(f))

  // calculate ranks
  feat_dict['attributes']['exhydpar_rank'] = getRank(f, 'PR_EXHYDPAR', fs)
  feat_dict['attributes']['exstrpar_rank'] = getRank(f, 'PR_EXSTRPAR', fs)
  feat_dict['attributes']['extotpar_rank'] = getRank(f, 'PR_EXTOTPAR', fs)

  // convert back to feature, push into output
  Push(out_dict['features'], Feature(feat_dict))
}

return FeatureSet(Text(out_dict))
&lt;/LI-CODE&gt;&lt;P&gt;you!&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2024 21:06:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboards-data-expression-including-rank/m-p/1541654#M10318</guid>
      <dc:creator>LJackson29</dc:creator>
      <dc:date>2024-09-23T21:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS dashboards Data Expression including Rank</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboards-data-expression-including-rank/m-p/1541677#M10321</link>
      <description>&lt;P&gt;The error is in the getRank function. The SQL statement should be a backtick string, sorry!&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;`${field} &amp;lt; @filt_val`&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;To answer your questions:&lt;/P&gt;&lt;P&gt;The entire "Memorize" function is just taking your FeatureSet and pushing it into a &lt;EM&gt;new &lt;/EM&gt;FeatureSet that is held in your browser's memory. That way future requests for information (like the Filter and Count functions) work with local data. Normally, your expression would have to wait for queries to be sent to the feature service each time.&lt;/P&gt;&lt;P&gt;On "GetRank", it &lt;EM&gt;doesn't&lt;/EM&gt; identify the smallest feature. One of the parameters is "feat", and the function can be called on any individual feature. Since we're just &lt;EM&gt;defining &lt;/EM&gt;the function, it's not being used in any particular order.&lt;/P&gt;&lt;P&gt;To explain it again, imagine you have 8 values. If you simply take each value and count the number of features that are smaller than it, &lt;EM&gt;that is the rank&lt;/EM&gt;. You don't actually need to go through each feature counting by ones.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1727128432060.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/115719i3C52436715956DF3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1727128432060.png" alt="jcarlson_0-1727128432060.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Full count isn't being used, it was an earlier idea I forgot to remove. You can delete it!&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2024 21:54:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboards-data-expression-including-rank/m-p/1541677#M10321</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-09-23T21:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS dashboards Data Expression including Rank</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboards-data-expression-including-rank/m-p/1541691#M10322</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;&amp;nbsp;Sorry - I changed the backticks to single quotes because I was getting an error that "&lt;SPAN&gt;'filt_val' is assigned but never used." However, when I changed it back to the backticks, it still isn't working. I get the following error when I run the code "Test execution error: Execution error - Portal is required. Verify test data."&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2024 12:16:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboards-data-expression-including-rank/m-p/1541691#M10322</guid>
      <dc:creator>LJackson29</dc:creator>
      <dc:date>2024-09-24T12:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS dashboards Data Expression including Rank</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboards-data-expression-including-rank/m-p/1541860#M10324</link>
      <description>&lt;P&gt;That's right here:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var fs = Memorize(filter(FeatureSetByPortalItem(
  portal,'01610f3a8912467c8b06f4b223a6b5e1', 0,
  ['PROJECTID', 'PR_PROJNAME', 'PR_STATUS', 'PR_ORIGTOTCOST', 'PR_P6TOTCOST', 'PR_EXHYDPAR', 'PR_EXSTRPAR', 'PR_EXTOTPAR', 'PR_ALTHYDPAR', 'PR_ALTSTRPAR', 'PR_ALTTOTPAR', 'PR_REDHYDPAR', 'PR_REDSTRPAR', 'PR_REDTOTPAR', 'PR_TOTNOMSCORE', 'PR_TOTSCORE',  'PR_WAC', 'PR_SUBWATERSHED', 'PR_COMMUNITY1', 'PR_MODELDATE', 'PR_PARTOOLDATE', 'PR_SWIM_ONLY', 'PR_PART_ONLY', 'PR_NONDISTRICT', 'PR_STRPARDATE'], 
  false),
  ("PR_SWIM_ONLY='No' AND PR_PART_ONLY='No' AND  PR_NONDISTRICT='No' AND (PR_STATUS='01. Submitted – Pending Review/Scoring' OR PR_STATUS='02. Scored' OR PR_STATUS='03. Advanced SW Planning' OR PR_STATUS='04. Design' OR PR_STATUS='05. Construction' OR PR_STATUS='07. Completed')"
  )))&lt;/LI-CODE&gt;&lt;P&gt;You're supplying the variable "portal", but it's not defined. It's also the name of a function, which is why it doesn't immediately get flagged as an issue. (In your original expression, it was "port".)&lt;/P&gt;&lt;P&gt;Personally, I don't really find it worth it to establish a separate variable for the portal connection, just use the &lt;STRONG&gt;Portal&lt;/STRONG&gt; function directly in your FeatureSet function.&lt;/P&gt;&lt;P&gt;Some other notes:&lt;/P&gt;&lt;P&gt;It looks like you had an extra set of parentheses in your expression. You don't need to put parentheses around your filter statement.&lt;/P&gt;&lt;P&gt;In your filter statement, you've got a lot of "OR" conditions strung together. Since they're all checking the same field, you can use the SQL operator &lt;STRONG&gt;IN&lt;/STRONG&gt; to check for any of a series of values.&lt;/P&gt;&lt;P&gt;The expression "some_field = 'A' OR some_field = 'B' OR some_field = 'C'" is equivalent to "some_field IN('A', 'B', 'C')".&lt;/P&gt;&lt;P&gt;Try using this to replace your "var fs = …" section:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fs = Memorize(
  Filter(
    FeatureSetByPortalItem(
      Portal('https://arcgis.com'),
      0,
      ['PROJECTID', 'PR_PROJNAME', 'PR_STATUS', 'PR_ORIGTOTCOST', 'PR_P6TOTCOST', 'PR_EXHYDPAR', 'PR_EXSTRPAR', 'PR_EXTOTPAR', 'PR_ALTHYDPAR', 'PR_ALTSTRPAR', 'PR_ALTTOTPAR', 'PR_REDHYDPAR', 'PR_REDSTRPAR', 'PR_REDTOTPAR', 'PR_TOTNOMSCORE', 'PR_TOTSCORE',  'PR_WAC', 'PR_SUBWATERSHED', 'PR_COMMUNITY1', 'PR_MODELDATE', 'PR_PARTOOLDATE', 'PR_SWIM_ONLY', 'PR_PART_ONLY', 'PR_NONDISTRICT', 'PR_STRPARDATE'],
      false
    ),
    "PR_SWIM_ONLY='No' AND PR_PART_ONLY='No' AND  PR_NONDISTRICT='No' AND PR_STATUS IN('01. Submitted – Pending Review/Scoring', '02. Scored', '03. Advanced SW Planning', '04. Design', '05. Construction', '07. Completed')"
  )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2024 12:51:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboards-data-expression-including-rank/m-p/1541860#M10324</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-09-24T12:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS dashboards Data Expression including Rank</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboards-data-expression-including-rank/m-p/1541961#M10326</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;So sorry, I am still running into issues. I am now getting an error "&lt;SPAN&gt;Cannot read properties of null (reading 'toString'). Verify test data." I updated the code as you suggested (and added the item id). I am not getting any errors in the code, just the warning&amp;nbsp;"'filt_val' is assigned but never used."&amp;nbsp;Console(Count(fs)) - returns the correct number of records.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;function Memorize(fs) {
  var temp_dict = {
    fields: Schema(fs)['fields'],
    geometryType: '',
    features: []
  }

  for (var f in fs) {
    var attrs = {}

    for (var attr in f) {
      attrs[attr] = Iif(TypeOf(f[attr]) == 'Date', Number(f[attr]), f[attr])
    }

    Push(
      temp_dict['features'],
      {attributes: attrs}
    )
  }

  return FeatureSet(Text(temp_dict))
}


function getRank(feat, field, set){
  var filt_val = feat[field]
  var filt_set = Filter(set, `${field} &amp;lt; @filt_val`)
  return Count(filt_set)+1
}

var fs = Memorize(
  Filter(
    FeatureSetByPortalItem(
      Portal('https://arcgis.com'),
      '01610f3a8912467c8b06f4b223a6b5e1', 0,
      ['PROJECTID', 'PR_PROJNAME', 'PR_STATUS', 'PR_ORIGTOTCOST', 'PR_P6TOTCOST', 'PR_EXHYDPAR', 'PR_EXSTRPAR', 'PR_EXTOTPAR', 'PR_ALTHYDPAR', 'PR_ALTSTRPAR', 'PR_ALTTOTPAR', 'PR_REDHYDPAR', 'PR_REDSTRPAR', 'PR_REDTOTPAR', 'PR_TOTNOMSCORE', 'PR_TOTSCORE',  'PR_WAC', 'PR_SUBWATERSHED', 'PR_COMMUNITY1', 'PR_MODELDATE', 'PR_PARTOOLDATE', 'PR_SWIM_ONLY', 'PR_PART_ONLY', 'PR_NONDISTRICT', 'PR_STRPARDATE'],
      false
    ),
    "PR_SWIM_ONLY='No' AND PR_PART_ONLY='No' AND  PR_NONDISTRICT='No' AND PR_STATUS IN('01. Submitted – Pending Review/Scoring', '02. Scored', '03. Advanced SW Planning', '04. Design', '05. Construction', '07. Completed')"
  )
)

Console(Count(fs));
Console(fs);

// ranks to add to the output
var rank_fields =[
  {name: 'exhydpar_rank', type:'esriFieldTypeInteger'},
  {name: 'exstrpar_rank', type:'esriFieldTypeInteger'},
  {name: 'extotpar_rank', type:'esriFieldTypeInteger'}
]

var out_dict = {
  fields: Splice(Schema(fs)['fields'], rank_fields),
  geometryType: '',
  features: []
}

for (var f in fs) {
  // convert feature to dict
  var feat_dict = FromJSON(Text(f))

  // calculate ranks
  feat_dict['attributes']['exhydpar_rank'] = getRank(f, 'PR_EXHYDPAR', fs)
  feat_dict['attributes']['exstrpar_rank'] = getRank(f, 'PR_EXSTRPAR', fs)
  feat_dict['attributes']['extotpar_rank'] = getRank(f, 'PR_EXTOTPAR', fs)

  // convert back to feature, push into output
  Push(out_dict['features'], Feature(feat_dict))
}

return FeatureSet(Text(out_dict))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2024 15:06:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboards-data-expression-including-rank/m-p/1541961#M10326</guid>
      <dc:creator>LJackson29</dc:creator>
      <dc:date>2024-09-24T15:06:54Z</dc:date>
    </item>
  </channel>
</rss>

