Hello,
I’m trying to add two different layers but without success. Any suggestions?
The problem is right here:
for (var set in fsets) {
running_sum += Sum(set, 'n_lobitos')
}
When you iterate over an array, that nested var is the index, not the item. If you included the line Console(set) in the loop, you'd see it return 0 and 1. That means your Sum expressions are:
Sum(0, 'n_lobitos')
and
Sum(1, 'n_lobitos')
Which of course, won't return anything.
The way to get each item of an array is to call the original array and then use the index variable to access it. Try using these lines in replacement of the ones quoted earlier:
for (var set in fsets) {
running_sum += Sum(fsets[set], 'n_lobitos')
}
Hello Josh,
Thank you for your attention,
However I changed as suggested but still keeps the error.
Do you have any other suggestions?
Thanks,
Sprinkle some Console functions in there to see how far it gets. When you test the expression, the Console tab will show you the output of those functions.
For instance, you could try this for the for loop:
for (var set in fsets) {
var set_sum = Sum(fsets[set], 'n_lobitos')
Console('featureset sum:', set_sum)
running_sum += set_sum
Console('running sum:', running_sum)
}
This will output what the individual FeatureSet's sum is, as well as the running sum for that iteration of the loop.
You might also try outputting information about the FeatureSets themselves, to see if your FeatureSetByPortalItem functions are returning legitimate sets.
for (var set in fsets) {
Console(Count(fset))
}
Hello,
I’m trying to write an expression in the dashboard to add two layers in a certain field (n_lobitos in both)
I’m not getting it. Any help?
I’ve seen the sample below but it’s different.
https://github.com/Esri/arcade-expressions/blob/master/dashboard_data/CalculationAcrossFields.md
----------------------------------------------------------------------------------