Select to view content in your preferred language

Trying to create an Arcade Data Expression but is not working properly (Dashboards)

76
1
yesterday
SantiagoMafla
New Contributor

Hi everyone!

I hope anyone reading this is having a great day.

I'm someone that is very new at creating dashboards and using ArcGIS online, so this is one question of many on my journey to learn as mucha as I can.

As mentioned on the tite I'm trying to create an Arcade Data Expression but is not working properly. In the set of data that I'm using there're 3 elements that I'm trying to integrate or make an operation with, these elements are:

  • Dependencies (String)
  • Climate change actions (String)
  • Percentage of advance of each action (Double)

I'm trying with arcade to create a data expression that allows me to know the total of advance of each dependency according to the amount of advance done adding all of the actions like:

  • Total advance of the dependency = sum(advance of each action of the dependency)/sum(number of actions of the dependency)

I'm doing it with this arcade code, but it hasn't worked even after multiple workarounds, any ideas what could be happening?

var portal = Portal('https://www.arcgis.com/');

var fs = FeatureSetByPortalItem(
    portal,
    '5877b34d02574ba1826801c46976e6c0',
    0,
    [
        'dependenciane', //Dependencies
        'accioncc', //Climate change action
        'avancevigencia1' //Percentage of advance of each action
    ],
    false
);

var dependencias = GroupBy(
  fs,
  ['dependenciane'],
  [
    { name: 'sum_avance', expression: 'avancevigencia1', statistic:'SUM' },
    { name: 'count_acciones', expression: 'accioncc', statistic: 'COUNT' },
  ]
);

var promedios = [];

for (var d in dependencias) {
    if (d.count_acciones > 0) {
        Push(promedios, (d.sum_avance / d.count_acciones));
    }
}

var total_promedio = 0;
if (Count(promedios) > 0) {
    total_promedio = Average(promedios);
}

return Round(total_promedio, 2);
Thanks in advance
Tags (3)
0 Kudos
1 Reply
KenBuja
MVP Esteemed Contributor

The first rule of data expressions is they have to return a FeatureSet. Your expression is only returning a number, so the easiest way to make that into a FeatureSet would be using this syntax for the return

return FeatureSet(
  {
    fields: [{ name: "Total", type: "esriFieldTypeSingle" }],
    features: [{ attributes: { Total: Round(total_promedio, 2) } }]
  }
);

 

0 Kudos