Select to view content in your preferred language

No Data return on Indicator - how to ignore empty reference data returned with a selector?

180
4
3 weeks ago
Labels (1)
MaryroseKulick
Occasional Contributor

I am using advanced formatting in an indicator to perform a calculation. 

My $datapoint has a filter where FIELD1 = X

And my $reference refers to the same layer where FIELD1 = Y. 

When using a category selector where the FIELD2 = A, $datapoint is always empty/no values are returned. This is known and expected. I'm trying to set up my Arcade so that it ignores empty values and still runs the calculation on $reference. Is this possible? So far I'm only getting No Data results when FIELD2 = A. 

Here is my code:

var value1 = $reference.SUM_FIELD3 * 25;
 
var value2 = IIF(IsEmpty($datapoint.SUM_FIELD3), 0,$datapoint.SUM_FIELD3);
 
var total = value1 + value2;

 

0 Kudos
4 Replies
DanielFox1
Esri Regular Contributor

Hi @MaryroseKulick 

Could you try the following Arcade code 

// Calculate reference value
var value1 = $reference.SUM_FIELD3 * 25;

// Handle empty datapoint
var value2 = IIF(IsEmpty($datapoint.SUM_FIELD3) || $datapoint.SUM_FIELD3 == null, 0, $datapoint.SUM_FIELD3);

// Final calculation
var total = value1 + value2;

// Format output
return {
topText: "Total: " + Text(total, "#,###.##"),
noValue: false
};

The IsEmpty() may not catch all the null cases but combining it with ==null should help this. Then setting the noValue: false should override the default behaviour that hides the indicator when $datapoint is empty. 

 

I hope this helps you out. 

 

0 Kudos
MaryroseKulick
Occasional Contributor

Thank you for your response and your help! Sadly, I'm getting the same results, where no data returns when the $datapoint is empty. It works perfectly well otherwise!

var value1 = $reference.SUM_FEILD3 * 25;
var value2 = IIF(IsEmpty($datapoint.SUM_FIELD3) || $datapoint.SUM_FIELD3 ==null,0,$datapoint.SUM_FIELD3)
var total = value1 + value2


return {
  //textColor:'',
  //backgroundColor:'',
  topText: 'Total',
  //topTextColor: '',
  //topTextOutlineColor: '',
  //topTextMaxSize: 'medium',
  middleText: Text(total, "#,###.##"),
  middleTextColor: '',
  middleTextOutlineColor: '',
  middleTextMaxSize: 'large',
  //bottomText: '',
  //bottomTextColor: '',
  //bottomTextOutlineColor: '',
  //bottomTextMaxSize: 'medium',
  // iconName:'',
  //iconAlign:'left',
  //iconColor:'',
  //iconOutlineColor:'',
  noValue:false,
  //attributes: {
    // attribute1: '',
    // attribute2: ''
  // }
}
0 Kudos
DanielFox1
Esri Regular Contributor

Even though you are using IIF(IsEmpty(....) ==null, 0, ...) The expression might still fail to evaluate if $datapoint itself is undefined or missing entirely. I have included below a refined approach that adds a defensive check for $datapoint itself before trying to access its fields

var value1 = $reference.SUM_FEILD3 * 25;

var value2 = 0;
if (!IsEmpty($datapoint) && HasKey($datapoint, "SUM_FIELD3") && !IsEmpty($datapoint.SUM_FIELD3)) {
value2 = $datapoint.SUM_FIELD3;
}

var total = value1 + value2;

return {
topText: 'Total',
middleText: Text(total, "#,###.##"),
middleTextMaxSize: 'large',
noValue: false
}

 

There a few reasons this can work better

1. IsEmpty($datapoint) check if the entire object is missing

2. HasKey($datapoint, "SUM_FIELD3") ensures the field exists before accessing it 

3. IsEmpty($datapoint.SUM_FIELD3) handles the actual value check 

 

This should hopefully ensure that your indicator always returns a value even if $datapoint is undefined or partially populated. 

I hope this help in some way.

 

0 Kudos
MaryroseKulick
Occasional Contributor

Alas, same result with that script. Thanks for sticking with me!

I'm exploring using a data expression for the source data. Is there a way I could force it to create a row for each Field1 category and Field2 category combination, but if empty the field3_sum = 0? 

// Connect to the portal
var portal = Portal("URL");

// Access the feature set by Portal Item ID
var fs = FeatureSetByPortalItem(
    portal,
    "ItemID", // Replace with actual Portal Item ID if different
    2, // Layer index
    ["field1", "field2", "field3"], // All fields
    false // Include geometry
);

// Example: return count of features
//return Count(fs);

return GroupBy(fs, ['field1','field2''],  
[{name: 'field3_sum', expression: 'field3', statistic: 'SUM'}])

 

results in:

field1                   field2              field3_sum            ROW__ID
ASite 1535
ASite 11120
ASite 101723
ASite 16721
ASite 10741
ASite 14427
ASite 22731
ASite 256183
ASite 270910
ASite 232163
BSite 2512114
BSite 2587104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0 Kudos