Getting an error on selecting a column in data expression (Arcade)

379
6
Jump to solution
05-07-2021 11:25 AM
Labels (1)
jonasvanduijvenbode
New Contributor II

So I have a dataset that contains a column with dates. I want to create a pie-chart that shows the amount of cells in that column that is empty and the amount that has a value. So I tried to create a data expression. In this data expression I filled in:

 

var feat=FeatureSetByPortalItem(Portal('correctaddress'), '6227a7a523744c978d8fb6280168c119', 0)
return IsEmpty(feat.VerwijderdOp)

Of course the 'correctaddress' is normally filled with the actual link to my organisation. If I just do return(feat) I can see the entire table, which has a column called VerwijderdOp. However, when I try this or even try to access any column, so even something as simple as return feat.OBJECTID, I get the error 

 

Execution Error:Runtime Error: Cannot call member property on object of this type. VerwijderdOp

 

Can anybody help me out?

0 Kudos
1 Solution

Accepted Solutions
DavidPike
MVP Frequent Contributor

There's maybe a much better way of doing it, but I just calculated the total null dates as a variable, the total not null dates as a variable (total count - count null), then created a new feature set containing those values.

I've added your time field as features.verwij...  (Line 8) but I may have spelt it wrong, other than that the only thing you should add is the portal item ID (Line 2).

For the pie chart widget, In 'Data Options' I would probably choose 'Categories from - 'Fields' -> add both Total Null and TotalNotNull fields, and use a statistic of 'Sum'.

 

var portal = Portal('https://www.arcgis.com')
var features = FeatureSetByPortalItem(portal, 'InsertYourItemIDHere')

var featCount = Count(features)

var nullCount = 0
for (var feature in features) {
    if (IsEmpty(feature.VerwijderdOp)) {
        nullCount += 1
    };
}

var notNullCount = featCount - nullCount

var featureDict = {
    'fields': [{'name':'TotalNull', 'type':'esriFieldTypeDouble'},{'name':'TotalNotNull', 'type':'esriFieldTypeDouble'}
        ],
    'geometryType':'',
    'features':

[
  { 
    "attributes" : {
      "TotalNull" : nullCount,
      "TotalNotNull" : notNullCount,

    }
  },

]}
     
return FeatureSet(Text(featureDict));

  

View solution in original post

6 Replies
DavidPike
MVP Frequent Contributor

I'd say IsEmpty() is a logical check against a field value, and you're attempting to input a feature set as an argument.

What do you actually want to do?  Can you not just return your feature set and then use that as the input for the pie chart (classified by Null / Not Null?).

Or use the Count and Filter methods together - described here - Calculating feature count of attribute type using arcade in ArcGIS Online - Geographic Information S... 

jonasvanduijvenbode
New Contributor II

Hi David,

 

thanks for your reply. I am indeed trying to use a column in my feature set as an argument, so any help with that would be great.

Your solution (Null/Not Null) is not possible since the column that I want to use 'called verwijderdop' is a date column which you cannot use in a pie chart. 

The link that you provided would work for pop-ups etc but not for what I am trying to do here.

0 Kudos
DavidPike
MVP Frequent Contributor

There's maybe a much better way of doing it, but I just calculated the total null dates as a variable, the total not null dates as a variable (total count - count null), then created a new feature set containing those values.

I've added your time field as features.verwij...  (Line 8) but I may have spelt it wrong, other than that the only thing you should add is the portal item ID (Line 2).

For the pie chart widget, In 'Data Options' I would probably choose 'Categories from - 'Fields' -> add both Total Null and TotalNotNull fields, and use a statistic of 'Sum'.

 

var portal = Portal('https://www.arcgis.com')
var features = FeatureSetByPortalItem(portal, 'InsertYourItemIDHere')

var featCount = Count(features)

var nullCount = 0
for (var feature in features) {
    if (IsEmpty(feature.VerwijderdOp)) {
        nullCount += 1
    };
}

var notNullCount = featCount - nullCount

var featureDict = {
    'fields': [{'name':'TotalNull', 'type':'esriFieldTypeDouble'},{'name':'TotalNotNull', 'type':'esriFieldTypeDouble'}
        ],
    'geometryType':'',
    'features':

[
  { 
    "attributes" : {
      "TotalNull" : nullCount,
      "TotalNotNull" : notNullCount,

    }
  },

]}
     
return FeatureSet(Text(featureDict));

  

jonasvanduijvenbode
New Contributor II

Hi David,

 

very impressive, thank you so much for this answer! So also if I understand correctly I cannot apply a function on an array but I can apply it item-wise, which is naturally done in a pop-up but requires a for-loop in a data expression. This makes sense and again thank you for the solution.

0 Kudos
DavidPike
MVP Frequent Contributor

No problem.  My Javascript formatting is far from impressive though.

Not exactly, you can perform functions still on any objects which are valid arguments to those functions.  I think the issue is really that the Data Expression always has to return a FeatureSet otherwise it's invalid.

Using Data Expressions to store computed variables/objects I think would be handy and very useful in the future, I can only guess that having only a FeatureSet created at the moment makes it much easier to be an input to the existing dashboard elements.

0 Kudos
DavidPike
MVP Frequent Contributor

I should add that I should have specified the specific columns without geometry to speed it up.

Data Functions | ArcGIS for Developers e.g. insert the additional parameters fieldList = ['Field1', Field2'...] and includeGeometry = False

0 Kudos