Select to view content in your preferred language

Arcade expression to count related table

570
2
Jump to solution
10-29-2024 05:41 AM
Labels (1)
TKSHEP
by
Frequent Contributor

I am looking for help on creating an expression to count the number of related features using (example) 1 of # number of related to feature. ex 1 of 3 (next feature shows) 2of 3 and then 3 of 3.  

Any help would be greatly appreciated. 

Thank you!

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Knowing what the data looks like would help, but using FeatureSetByRelationshipName is the best way to quickly grab related records, if there's a legitimate relationship between the tables.

Is this for a popup? Field calculation? Dashboard?

var rel = FeatureSetByRelationshipName($feature, 'relationshipname', ['field1', 'field2', 'field3'], false)

// count of related features
var the_count = Count(rel)

// build a popup out of related feature info
var popup_arr = []
var feat_idx = 1

for (var r in rel) {
  Push(popup_arr, `Feature ${feat_idx} of ${the_count}:
    Field One: ${r['field1']}
    Field Two: ${r['field2']}
    Field Three: ${r['field3']}`
  )
  feat_idx += 1
}

return Concatenate(popup_arr, '\n\n')

Depending on where you're trying to use this expression, you may need HTML line breaks instead of \n, but try this out and see how it works.

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

Knowing what the data looks like would help, but using FeatureSetByRelationshipName is the best way to quickly grab related records, if there's a legitimate relationship between the tables.

Is this for a popup? Field calculation? Dashboard?

var rel = FeatureSetByRelationshipName($feature, 'relationshipname', ['field1', 'field2', 'field3'], false)

// count of related features
var the_count = Count(rel)

// build a popup out of related feature info
var popup_arr = []
var feat_idx = 1

for (var r in rel) {
  Push(popup_arr, `Feature ${feat_idx} of ${the_count}:
    Field One: ${r['field1']}
    Field Two: ${r['field2']}
    Field Three: ${r['field3']}`
  )
  feat_idx += 1
}

return Concatenate(popup_arr, '\n\n')

Depending on where you're trying to use this expression, you may need HTML line breaks instead of \n, but try this out and see how it works.

- Josh Carlson
Kendall County GIS
TKSHEP
by
Frequent Contributor

@jcarlson My apologies, it is for a popup.

0 Kudos