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:
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²'
}
Would something like this work?
var hyresgastskottaytor = $reference["sum_SHAPE.STArea()"]
var hyresgastskottaytor_fix = iif(hyresgastskottaytor == '',0, hyresgastskottaytor)
var total = allmannaytor + hyresgastskottaytor_fix
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.
Hi!
I changed the script to this:
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.
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
@MicBry couldn't hurt to try this:
var hyresgastskottaytor_fix = iif(isEmpty(hyresgastskottaytor) || isNan(hyresgastskottaytor || hyresgastskottaytor==''),0, hyresgastskottaytor)
could also try:
var hyresgastskottaytor_fix = DefaultValue(hyresgastskottaytor, 0)
Thanks again Neal!
The first one made the script fail. The second one worked but the issue with no data remained. Thanks though!!
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