I am new to Arcade and have found myself stuck. I am writing a data expression for dashboard and I can't figure out how to write a calculation. I get an error with everything I've tried.
I also tried to create a dictionary, and use that but I couldn't get that to work either 🙂
My end goal is to multiply the 'Tally' field for each 'Stand_No' by 50 or 100 (as determined by 'Plot_Sizes' of 0.02 and 0.01). I then need to find the average for those new (Tally*50 and Tally*100) numbers for each 'Stand_No'.
var p = 'https://maps.arcgis.com'
var itemId = 'a8af124e92af44579e3fd07bb59ebb4c'
var fs = FeatureSetByPortalItem(Portal(p), itemId, 0, ['Stand_No', 'Tally', 'Plot_Configuration', 'Plot_Name', 'Plot_Status', 'Plot_Size', 'DBH', 'Height', 'Cruiser_Name', 'Exit_Plot_Time'], false)
//Separate Plot Size into 2 groups for planting
var plot50 = Filter(fs, 'Plot_Size = (0.02)');
var plot100 = Filter(fs, 'Plot_Size = (0.01)');
var TPS = 0
//Multiply the plot size in plot50 by 2,500, multiply the plot size in plot100 by 10,000)
var plot_exp = [{name: 'TPS', expression: '(Tally * 2500)', statistic: 'MAX'}]
//return plot_exp
var summary = GroupBy(fs,['Stand_No','Plot_Configuration','Plot_Size', 'Cruiser_Name'],
[{name: 'TallySum', expression: 'Tally', statistic: 'SUM'},
{name: 'TCount', expression: '1', statistic: 'COUNT'},
{name: 'AvgDBH', expression: 'DBH', statistic: 'AVG'},
{name: 'AvgHeight', expression: 'Height', statistic: 'AVG'},
{name: '50TPS', expression: '(@plot50 * 2500)', statistic: 'AVG'}])
Console(summary)
return summary
//Goal is to obtain the Trees per Acre per Stand for each Stand
Solved! Go to Solution.
The SQL expressions used in GroupBy will recognize numeric and text data, but not objects like FeatureSets. If you need to apply a different calculation based on a field's value, you can do that in the SQL expression using CASE.
var plot_exp = `CASE
WHEN Plot_Size = 0.02 THEN Tally * 0.02
WHEN Plot_Size = 0.01 THEN Tally * 0.01
ELSE Tally -- or some other default value
END`
Just swap that in as one of the expressions in your GroupBy function, and you should get results like you expect.
The SQL expressions used in GroupBy will recognize numeric and text data, but not objects like FeatureSets. If you need to apply a different calculation based on a field's value, you can do that in the SQL expression using CASE.
var plot_exp = `CASE
WHEN Plot_Size = 0.02 THEN Tally * 0.02
WHEN Plot_Size = 0.01 THEN Tally * 0.01
ELSE Tally -- or some other default value
END`
Just swap that in as one of the expressions in your GroupBy function, and you should get results like you expect.
That works perfectly, thank you so much!! I really appreciate the help! 🙂