Select to view content in your preferred language

Calculate statistics based on multiple fields in same layer

279
3
Jump to solution
10-31-2024 05:01 PM
JanetBrewster1
Occasional Contributor

Hello All,

I'm trying to make a simple algebraic calculation based on multiple fields from the same data layer, specifically, to divide one field by another. A hitch, perhaps, is that I need the input to this calculation to be filterable by multiple selectors from within the Dashboard, i.e. month, year, and/or location, so I don't want to group by any of these options. I need the resulting info to be used in both an indicator and in multiple charts.

I saw something similar on GitHub, https://github.com/Esri/arcade-expressions/blob/master/dashboard/dashboard_data/CalculationAcrossFie... , and mimicked that...but it doesn't work (and I don't quite understand Dictionaries, either, I have to admit). I get "Test execution error: Execution error - Invalid parameter. Verify test data."

Any thoughts would be greatly appreciated. Thank you!

//Divide two fields from the same layer
//Result must be filterable by multiple selectors within the Dashboard
var portal = Portal('https://arcgis.com');

var fs = FeatureSetByPortalItem(
    portal,
    '86ba934a1b4c4ff2ae8188a012256ffc',
    0,
    [
        'TotalSteelhead',
        'TotalTrips'
    ],
    false
);

var ratioDict = {
    'fields': {'name': 'CPUE', 'type': 'esriFieldTypeDouble'},
    'features':
    [{'attributes':
    {'CPUE': Round((SUM(fs,'TotalSteelhead')/SUM(fs,'TotalTrips')),2)}
    }]};

return FeatureSet(ratioDict)

 

0 Kudos
1 Solution

Accepted Solutions
JenniferAcunto
Esri Regular Contributor

You do not need a data expression for this. You can use an Indicator with a reference field. 

Use the sum of TotalSteelhead as the data source for your indicator.

Add a reference with a type of statistic and use the sum of TotalTrips.

On the Indicator tab, remove the value and reference placeholders.

Click on the curly brackets and pick the {ratio}.

For a full walkthrough follow the first method outlined here, except you don't even need to get into Advanced Formatting

- Jen

View solution in original post

3 Replies
JenniferAcunto
Esri Regular Contributor

You do not need a data expression for this. You can use an Indicator with a reference field. 

Use the sum of TotalSteelhead as the data source for your indicator.

Add a reference with a type of statistic and use the sum of TotalTrips.

On the Indicator tab, remove the value and reference placeholders.

Click on the curly brackets and pick the {ratio}.

For a full walkthrough follow the first method outlined here, except you don't even need to get into Advanced Formatting

- Jen
JanetBrewster1
Occasional Contributor

Jen -- this is great!! 

I had not seen your Indicator hack before...I would never have figured this out on my own. It worked perfectly for my indicators, and the results adjusted as I used various selectors within the dashboard. YAHOO!!

However, my charts are the other 50% of this problem. Do you have any thoughts on how I could incorporate this calculation for my charts?

Thank you so much for your help!!

Janet

 

0 Kudos
JenniferAcunto
Esri Regular Contributor

I missed that you need this to work in other charts as well. You can only do something like this without using a Data Expression for elements that allow you to aggregate your data and use Advanced Formatting, so really just Indicators and Table elements. All other elements would require a data expression or a complete overhaul of your data. 

I'm a one trick pony with Arcade so data expressions aren't really in my wheelhouse. 

- Jen
0 Kudos