Select to view content in your preferred language

Create indicator that shows value and percentile rank in Dashboards

270
2
09-14-2024 01:36 PM
Labels (1)
LJackson29
Frequent Contributor

Hello -

I am working in ArcGIS Dashboards in ArcGIS online. I want to create an indicator (see example below) that will display the risk value (PR_EXHYDPAR)  stored in the layer as the middle text, and the percentile rank associated with that value which is not stored in the layer as the bottom text. I am trying write arcade code within the Indicator Advanced Formatting option that will order the PR_EXHYDPAR field and create a var for rank, and then calculate percentile rank to use in the bottom text. Below is what I have so far but it says "Unable to execute Arcade script", but is not showing any errors. I am not very familiar with iterate statements so guessing there is an issue there. Thanks in advance for any suggestions.

// order the layer by existing hydraulic risk
var ordered = OrderBy("PR_EXHYDPAR DESC")

//rank projects by existing hydraulic risk
var rank = 0
// iterate over the ordered layer
for(var f in ordered) {
    // increase the rank
    rank++
    }

//calculate percentile rank for existing hydraulic risk
var pctrank = (f.rank-1)/(Count($datapoint.OBJECTID)-1)

return {
  textColor:'black',
  topText: 'Existing Hydraulic Risk',
  topTextMaxSize: 'medium',
  middleText: $datapoint.PR_EXHYDPAR,
  middleTextMaxSize: 'large',
  bottomText: pctrank,
  bottomTextMaxSize: 'medium',

}

 Picture100.png

0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

An indicator's advanced formatting area doesn't have access to the source data in a way to actually execute this expression. What you'd need instead is to use a Data Expression to create an ad-hoc "layer", and calculate your percentiles there.

Is your indicator showing percentiles for a selected feature?

- Josh Carlson
Kendall County GIS
0 Kudos
LJackson29
Frequent Contributor

@jcarlson I was worried about that. I have put together the below data expression in the code box to select the fields I need from the layer and it works. I can use the below code in Pro to calculate rank, but not sure 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 (There are 7 fields I need to create percentile ranks for).

 

var setfeatures = FeatureSetByName($datastore, "SNP_Project");

var ordered = OrderBy(setfeatures, 'PR_EXHYPDAR DESC')

var rank = 0
for(var f in ordered) {
rank++
if(f.OBJECTID == $feature.OBJECTID) {
return rank
}
}

Can anyone provide guidance on how to do this?

 

 

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

 

 

0 Kudos