Select to view content in your preferred language

Arcade issue within dashboard

220
13
Tuesday
Labels (1)
MicBry
by
Emerging Contributor

Hi!

I have an issue connected to my dashboard and its widgets. I am currently using enterprise 11.3. In short, my dashboard uses a category selector and an indicator. The widgets have different data, but are connected through similar fields. 

My indicator uses a datapoint and a redference value. Both use the same data source, however they are filtered in different ways. My first value (datapoint) shows land (m2) that our municipal landlort taker care of. The seconf value shows land that the residents themselves takes care of. The third value is a grouping of the other to. In short:

Datapoint = Area m2

Reference value = other areas m2

Own value = Area + other areas m2 

 

So, to the issue. I have certain areas where the reference value is non existent, i.e. areas where no land is to be taken care of by the residents. This makes the arcade script fail behind the scenes. The indicator returns no data even when an area containt datapoint but not reference value.I would like the reference value to be treated as 0 so that i always get a result. 

 

Down below is a basic interpretation of my script:

var allmannaytor = $datapoint["sum_SHAPE.STArea()"]
var hyresgastskottaytor = $reference["sum_SHAPE.STArea()"]
var total = allmannaytor + hyresgastskottaytor

return {
  //textColor:'',
  //backgroundColor:'',
  topText: 'Allmänna ytor: ' + Text(Round(allmannaytor, 0), "#,###") + ' m²',
  topTextColor: '',
  topTextOutlineColor: '',
  topTextMaxSize: 'medium',
  middleText: 'Hyresgästskötta ytor:  ' + Text(Round(hyresgastskottaytor, 0), "#,###") + ' m²',
  middleTextColor: '',
  middleTextOutlineColor: '',
  middleTextMaxSize: 'medium',
  bottomText: 'Totala ytor: ' + Text(Round(total, 0), "#,###") + ' m²',
  bottomTextColor: '',
  bottomTextOutlineColor: '',
  bottomTextMaxSize: 'x-small',
  //iconName:'',
  //iconAlign:'left',
  //iconColor:'',
  //iconOutlineColor:'',
  //noValue:false,
  //attributes: {
    // attribute1: '',
    // attribute2: ''
  // }
}
 
I have tried to adjust this script adding if-statements, isempty and so on. Nothing is working for me. I need something that tells the dashboard to check for reference value first. If the value is non existing (not 0) it needs to be interpreted as 0. If a value exists this function can be ignored. 
 
Any suggestions? 
0 Kudos
13 Replies
AustinAverill
Frequent Contributor

Since your `total` variable, and the rich text you are constructing at the end both reference this possibly invalid value, you are likely running into issues of referencing an unassigned variable at some point if you try to bypass that single variable.

Instead, your if statement should look something like below. I have also made the variable assignment as the entire string that you are inserting into your values later. So you would need to change that portion to reflect that if you wanted to use this.

if(isEmpty($reference["sum_SHAPE.STArea()"]) || isNan($reference["sum_SHAPE.STArea()"])){
  var hyresgastskottaytor = 'No Available Data'
  var allmannaytor = 'Allmänna ytor: ' + Text(Round($datapoint["sum_SHAPE.STArea()"], 0), "#,###") + ' m²'
  var total = 'Totala ytor: ' + Text(Round($reference["sum_SHAPE.STArea()"] + $datapoint["sum_SHAPE.STArea()"], 0), "#,###") + ' m²'
}else{
  var hyresgastskottaytor = 'Hyresgästskötta ytor:  ' + Text(Round($reference["sum_SHAPE.STArea()"], 0), "#,###") + ' m²'
  var allmannaytor = 'Allmänna ytor: ' + Text(Round($datapoint["sum_SHAPE.STArea()"], 0), "#,###") + ' m²'
  var total = 'Totala ytor: ' + Text(Round($reference["sum_SHAPE.STArea()"], 0), "#,###") + ' m²'
}

 

0 Kudos
Neal_t_k
Frequent Contributor

Would something like this work?

var hyresgastskottaytor = $reference["sum_SHAPE.STArea()"]

var hyresgastskottaytor_fix = iif(hyresgastskottaytor == '',0, hyresgastskottaytor)

var total = allmannaytor + hyresgastskottaytor_fix

https://community.esri.com/t5/arcgis-dashboards-questions/create-an-if-or-iif-statement-for-details-...

0 Kudos
AustinAverill
Frequent Contributor

This would not work since you are checking to see if a numeric value is an empty string. This condition will always evaluate to the field value. You would need to use: 

var hyresgastskottaytor_fix = iif(isEmpty(hyresgastskottaytor) || isNan(hyresgastskottaytor),0, hyresgastskottaytor)

If for some reason your data set has empty strings, you could add an additional condition to evaluate for ''. But it shouldn't be necessary. 

MicBry
by
Emerging Contributor

Hi!

I changed the script to this:


var hyresgastskottaytor = $reference["sum_SHAPE.STArea()"]

var hyresgastskottaytor_fix = iif(isEmpty(hyresgastskottaytor) || isNan(hyresgastskottaytor),0, hyresgastskottaytor)

var allmannaytor = $datapoint["sum_SHAPE.STArea()"]

var total = allmannaytor + hyresgastskottaytor_fix


return {
  //textColor:'',
  //backgroundColor:'',
  topText: 'Allmänna ytor: ' + Text(Round(allmannaytor, 0), "#,###") + ' m²',
  topTextColor: '',
  topTextOutlineColor: '',
  topTextMaxSize: 'medium',
  middleText: 'Hyresgästskötta ytor:  ' + Text(Round(hyresgastskottaytor_fix, 0), "#,###") + ' m²',
  middleTextColor: '',
  middleTextOutlineColor: '',
  middleTextMaxSize: 'medium',
  bottomText: 'Totala ytor: ' + Text(Round(total, 0), "#,###") + ' m²',
  bottomTextColor: '',
  bottomTextOutlineColor: '',
  bottomTextMaxSize: 'x-small',
  //iconName:'',
  //iconAlign:'left',
  //iconColor:'',
  //iconOutlineColor:'',
  //noValue:false,
  //attributes: {
    // attribute1: '',
    // attribute2: ''
  // }
}
 
I'm getting the same result. Did i missunderstand your suggestion? Thank you so much for taking the time to answer me, appriciate it!
 
Best, Michaela
0 Kudos
AustinAverill
Frequent Contributor

If that is producing an error at that data point specifically, I would recommend looking at the value in that field specifically. If it is null or nan, it should be evaluating to zero and function as intended. If the value is something other than these two, you would need to add additional logic to handle the data.

0 Kudos
MicBry
by
Emerging Contributor

Hi!

The issue is that i have neither 0 nor null. The referencepoint does not exist for certain selections. I would like to check if the referencevalue exists, not what it contains. I'm not great with arcade so maybe that is what your script was supposed to check(?). 

 

Best,

Michaela

0 Kudos
Neal_t_k
Frequent Contributor

@MicBry couldn't hurt to try this:

var hyresgastskottaytor_fix = iif(isEmpty(hyresgastskottaytor) || isNan(hyresgastskottaytor || hyresgastskottaytor==''),0hyresgastskottaytor)

could also try:

var hyresgastskottaytor_fix = DefaultValue(hyresgastskottaytor, 0)

0 Kudos
MicBry
by
Emerging Contributor

Thanks again Neal! 

The first one made the script fail. The second one worked but the issue with no data remained. Thanks though!!

0 Kudos
AustinAverill
Frequent Contributor

Got it! In this case it sounds like we are checking whether the profile variable `$reference` has been defined with a feature/data.

I am not sure if this will work since $reference is not being defined... But you could try: 

if(HasKey($reference, 'sum_SHAPE.STArea()')){
  var hyresgastskottaytor = $reference["sum_SHAPE.STArea()"]
}else{
  var hyresgastskottaytor = 0
}

var hyresgastskottaytor_fix = iif(isEmpty(hyresgastskottaytor) || isNan(hyresgastskottaytor),0, hyresgastskottaytor)

var allmannaytor = $datapoint["sum_SHAPE.STArea()"]

var total = allmannaytor + hyresgastskottaytor_fix
0 Kudos