Good Afternoon, All!
I have a dataset of voting results and I can trying to create a data expression that returns the MAX value of registered voters within each district and then add the total of each MAX value to find the total number of those registered. I have written a data expression using the GoupBy function, however, it is returning a null value. I have provided examples of my data expression and data below.
Solved! Go to Solution.
Since your data is private, I can't test it. However, I was able to test using a public service and it worked as expected, returning two items in the table with the maximum value for each aggregationMethod
var fs = FeatureSetByPortalItem(
Portal("https://www.arcgis.com"),
// portal item id
"7b1fb95ab77f40bf8aa09c8b59045449",
0, // layer id
["*"], // fields to include
false // include or exclude geometry
);
GroupBy(fs, 'aggregationMethod', {name: 'TOTPOP_CY', expression: 'TOTPOP_CY', statistic: "MAX"})
You're using out_dict in the GroupBy, but you haven't assigned any records to it. Why aren't you using fs in the GroupBy?
I thought by using "out_dict", I was assigning a new variable.
The first parameter of the GroupBy function is the FeatureSet that contains the data, which should be fs. The out_dict variable is just an empty FeatureSet you've created.
Thank you, I'll give that try.
When I replaced "out_dict" with fs, I got an error that it could not execute the expression. Do you happen to have any idea of where I am going wrong?
When using variables, don't encase them in quotes.
var maxvotes = GroupBy(fs, 'Precinct_Name', {name: 'Reg_voters', expression: 'Reg_Voters', statistic: "MAX"})
Thank you. I removed the quotes from the variable and the expression was able to run this time. However it returned a "null" value when it should return a table, like the one below.
Do I need to return to the empty FeatureSet?
Since your data is private, I can't test it. However, I was able to test using a public service and it worked as expected, returning two items in the table with the maximum value for each aggregationMethod
var fs = FeatureSetByPortalItem(
Portal("https://www.arcgis.com"),
// portal item id
"7b1fb95ab77f40bf8aa09c8b59045449",
0, // layer id
["*"], // fields to include
false // include or exclude geometry
);
GroupBy(fs, 'aggregationMethod', {name: 'TOTPOP_CY', expression: 'TOTPOP_CY', statistic: "MAX"})
Thank you for your help on this! Your code helped me refine my expression and I also noticed that I had my Item number incorrect in my expression and once that was fixed I was able to apply the correct expression.
Thank you, again!
Best,
Janelle