The part of your expression "'M3SK_HA_Lov'/'M3SK_HA'" is the issue. Your expression is just taking those as literal strings, and it has no way of knowing that those correspond to fields in your FeatureSet. You'd need to tell your expression how it is to be accessing the attributes.
In order to correct this, can you clarify what the intended output is? Do you mean to "combine two columns" into a single statistic? The way it's written, your expression will have a single feature in it. And if that's the case, what you're trying to accomplish can be done more directly in other widgets.
If, however, you want to create a new field that has the dividend per feature, you'll need to use a loop to populate the features array. However! If your output FeatureSet is going to be the same shape as the input, you can actually do this in a much easier way.
var fs = FeatureSetByPortalItem(
Portal('https://www.arcgis.com'),
'1db5c1db1d2d44a985b2a2144f6c663f', 0,
["M3SK_HA", "M3SK_HA_Lov"],
false
)
return GroupBy(
fs,
'OBJECTID', // or whatever unique ID field your layer has
{
name: 'Lovpercent',
expression: 'M3SK_HA_Lov / M3SK_HA',
statistic: 'SUM'
}
)
The GroupBy function gives us the ability to create a new field using a SQL expression. By "grouping" the layer by its unique identifier, you'll get every row back out, and by "summing" the single values for each ID, you get the values themselves.
This would output the number, not text, but most Dashboard widgets can handle value formatting to make things look nice.
Speaking of which: what widget are you intending to use this with? If it's a widget that has access to Arcade-based formatting, you could calculate the dividend directly off of the source layer, no need for Data Expressions at all.
- Josh Carlson
Kendall County GIS