Convert a FeatureSet to an array

253
4
Jump to solution
11-23-2021 03:19 AM
Labels (1)
AbidHiraSaath
New Contributor III

Dear All,

I am trying to figure out a way to display popups in a feature class based on data available in a related table. I can use FeatureSetByRelationshipName to return a feature class, but I am very confused about how to access the specific values within the feature set. For example, I have the following table where pkida is a field related to the feature class which is a point layer. I want to program a field in the point feature class to return a specific value if pkida "1" has a savings account.

AbidHiraSaath_0-1637665973031.png

@XanderBakkerI have looked at several posts where people are trying to do similar things and you have been able to clarify things, but it is proving a bit difficult to understand. I would be grateful for any help here.

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Regular Contributor
var fs = FeatureSetByRelationshipName(...)
// if you clicked on a feature where pkida == 1, then only the first 3 entries
// of your example table will be in fs.

// you can do various things with that feature set:

// return the number of saving accounts
var fs_savings = Filter(fs, "Service = 'Savings'")
return Count(fs_savings)

// just return "Yes" if there is at least one "Savings" entry, "No" otherwise
if(Count(fs_savings) > 0) { return "Yes" }
return "No"

// return the sum of all savings accounts
return Sum(fs_savings, "Balance")

// return a total balance
fs_loans = Filter(fs, "Service = 'Loan'")
fs_shares = Filter(fs, "Service = 'Shares'")
return Sum(fs_savings, "Balance") + Sum(fs_shares, "Balance") - Sum(fs_loans, "Balance")

Have a great day!
Johannes

View solution in original post

4 Replies
JohannesLindner
MVP Regular Contributor
var fs = FeatureSetByRelationshipName(...)
// if you clicked on a feature where pkida == 1, then only the first 3 entries
// of your example table will be in fs.

// you can do various things with that feature set:

// return the number of saving accounts
var fs_savings = Filter(fs, "Service = 'Savings'")
return Count(fs_savings)

// just return "Yes" if there is at least one "Savings" entry, "No" otherwise
if(Count(fs_savings) > 0) { return "Yes" }
return "No"

// return the sum of all savings accounts
return Sum(fs_savings, "Balance")

// return a total balance
fs_loans = Filter(fs, "Service = 'Loan'")
fs_shares = Filter(fs, "Service = 'Shares'")
return Sum(fs_savings, "Balance") + Sum(fs_shares, "Balance") - Sum(fs_loans, "Balance")

Have a great day!
Johannes
AbidHiraSaath
New Contributor III

@JohannesLindner @XanderBakker 

This solution did work, though now we have run into a different but related issue. We are working with data that is in 3 layers, i.e. there is a related table to the feature class, and then another related table to the first related table, via a different ID field. It looks like this:

AbidHiraSaath_0-1639899273437.png

The original point table

AbidHiraSaath_1-1639899312867.png

the first related table, related through stopNo

AbidHiraSaath_2-1639899354640.png

The second related table, related to the first table through busNo

What we want to understand is, how can run a calculation on the second realted table through the original point layer? For example, if we wanted to know the sum of all the passengers in the buses that went through point A01, how would we do that?

When we use featuresetbyrelationshipname, using the name of the second relationship class, it reruns an empty featureset.

Can you please help me out regarding this?

 

 

 

0 Kudos
JohannesLindner
MVP Regular Contributor

In this case you have to call FeatureSetByRelationShip multiple times:

  • to get the busses at the stop
  • for each bus to get the passengers
var busses_at_stop = FeatureSetByRelationshipName($feature, "BussesAtStop") // first related table
var total_passengers_at_stop = 0
for(var bus in busses_at_stop) {
  var passengers_in_bus = FeatureSetByRelationshipName(bus, "PassengersInBus") // second related table
  total_passengers_at_stop += Sum(passengers_in_bus, "Numpass")
}
return total_passengers_at_stop

Have a great day!
Johannes
AbidHiraSaath
New Contributor III

@JohannesLindnerThanks for the reply! I will try this out for sure.

0 Kudos