Good morning,
I have 3 different yes/no fields from a customer's dataset verifying if different cable providers exist along a particular roadway with another double field capturing length of the roadway in miles (Image 1 and Data Sample 1). They are curious what percentage of surveyed roadways has each provider. There are often multiple providers on the same segment, and plenty of roads have yet to be populated since surveying is still underway, so I'm trying to leverage this into a single bar chart rather than pie chart via an arcade data expression. However, I'm ignorant of how to leverage data in the dashboard profile since I'm unsure how to get around not being able to use profile variables like $feature or $datastore.
Here is my expression so far. It seems to accurately collect total length of the surveyed roads, but the amount per each provider comes out as zero across the board. I'm pretty confident my issue is where I'm calling feature['provider'] but I can't wrap my head around how to call a specific field without using profile variables.
Ultimately, I'm trying to show the customer that Comcast, Cox, and Verizon make up xy% of the roadways that have been surveyed. Appreciate any help on this.
// Get my layer
var fs = FeatureSetByPortalItem(
Portal('{insertPortal}'),
'{insertLayer}',
0,
['Miles', 'Cox', 'Comcast', 'Verizon', 'Inspector'],
false
);
// Placeholder variables for total length and provider-specific lengths
var totalMiles = 0;
var providerA_Length = 0;
var providerB_Length = 0;
var providerC_Length = 0;
// Iterate through features, only include features that have been surveyed
for (var feature in fs) {
// Skip road segments where the "Inspector" field is null
if (IsEmpty(feature['Inspector'])) {
continue;
}
// Extract field values
var miles = feature['Miles']; // Length field
var isProviderA = feature['Comcast'];
var isProviderB = feature['Cox'];
var isProviderC = feature['Verizon'];
// Total length calculation for percentages
totalMiles += miles;
// Provider-specific length calculations
if (isProviderA == 'Yes') {providerA_Length += miles}
if (isProviderB == 'Yes') {providerB_Length += miles}
if (isProviderC == 'Yes') {providerC_Length += miles}
}
// Calculate percentages for each provider
var providerA_Percentage = (providerA_Length / totalMiles) * 100;
var providerB_Percentage = (providerB_Length / totalMiles) * 100;
var providerC_Percentage = (providerC_Length / totalMiles) * 100;
// Return results as an array
return [providerA_Percentage, providerB_Percentage, providerC_Percentage, totalMiles]