Can someone please help me with the following below, I am not sure what I am doing wrong, I have tested this in the arcade playground, but cant get it to work with my data.
I am trying pull data from a table and determine the percentage contacted
VAR Owners = FEATURESETBYNAME($DATASTORE,"Owners",["TractID","Contacted"])
VAR ID = $feature.TractID
VAR OwnerID = Filter(owners,"TractID=@ID")
VAR Cont = 0
VAR NCont =0
FOR(VAR F in OwnerID){
If(OwnerID[F] == 'Yes'){
Cont +=1}
}
FOR(VAR F in OwnerID){
If(OwnerID[F] == 'No'){
NCont +=1}
}
Return CONT/(Cont+NCont)
Solved! Go to Solution.
Your loops (and you only need one instead of two) aren't getting the attribute from the feature correctly. It should be like this
var Owners = FEATURESETBYNAME($DATASTORE,"Owners",["TractID","Contacted"])
var ID = $feature.TractID
var OwnerID = Filter(Owners,"TractID=@ID")
var Cont = 0
var NCont =0
for(var f in OwnerID) {
if(f.Contracted == 'Yes') {
Cont +=1
} else if(f.Contracted == 'No') {
NCont +=1
}
}
if (Cont == 0 && NCont == 0) return null
return Cont/(Cont+NCont)
I also added a check to make sure you're not dividing by zero.
Your loops (and you only need one instead of two) aren't getting the attribute from the feature correctly. It should be like this
var Owners = FEATURESETBYNAME($DATASTORE,"Owners",["TractID","Contacted"])
var ID = $feature.TractID
var OwnerID = Filter(Owners,"TractID=@ID")
var Cont = 0
var NCont =0
for(var f in OwnerID) {
if(f.Contracted == 'Yes') {
Cont +=1
} else if(f.Contracted == 'No') {
NCont +=1
}
}
if (Cont == 0 && NCont == 0) return null
return Cont/(Cont+NCont)
I also added a check to make sure you're not dividing by zero.
Thank you very much!