Hi ButterfieldLECP ,
Find below the expression that was used to get a list of organizations per venue and sum the number of participants. The "CorrectValue" function was written to translate the text field with the number of participants to a numeric value and accounts for a couple of known situations. This however, is no guarantee that in the future other exceptions will be handled correctly.
Function CorrectValue(participants) {
Console(participants);
if (IsEmpty(participants)) {
Console("case IsEmpty");
return 0;
}
if (IsNan(participants)) {
Console("case IsNan");
return 0;
}
participants = Upper(participants);
Console(participants);
if (Left(participants, 3) == "N/A") {
Console("case N/A");
return 0;
}
if (Left(participants, 3) == "MIN") {
Console("case Min...");
return 250;
}
participants = Replace(participants, "+", "");
Console(participants);
participants = Replace(participants, ",", "");
Console(participants);
if (Find(" TO ", participants) > -1) {
Console("case to");
var arr = Split(participants, " ");
return (Number(arr[0]) + Number(arr[2]))/2;
}
if (Find("ANNUALLY", participants) > -1) {
Console("case annually");
var arr = Split(participants, " ");
return Number(arr[0]);
}
if (Find("-", participants) > -1) {
Console("case -");
var arr = Split(participants, "-");
return (Number(arr[0]) + Number(arr[1]))/2;
}
return Number(participants);
}
var venname = $feature["org_venue"];
var fsorgs = FeatureSetByName($map,"Organization Info", ["org_name", "org_type", "org_address", "org_number_participants"], False);
var sql = "org_venue = @venname";
var orgs = Filter(fsorgs, sql);
var cnt = Count(orgs);
var result = "";
var tot_part = 0;
if (cnt > 0) {
result = cnt + " organization(s) found:"
for (var org in orgs) {
var participants = CorrectValue(org["org_number_participants"]);
tot_part += participants;
result += TextFormatting.NewLine + TextFormatting.NewLine + org["org_name"];
result += TextFormatting.NewLine + org["org_type"];
result += TextFormatting.NewLine + org["org_address"];
result += TextFormatting.NewLine + "participants: " + participants;
}
result += TextFormatting.NewLine + TextFormatting.NewLine + "Total participants: " + tot_part;
} else {
result = "no organizations found...";
}
return result;