Select to view content in your preferred language

GroupBy and FeatureSetByPortalItem for Serial Chart in Dashboard issue with Invalid variable assignment

313
6
Jump to solution
10-08-2024 01:03 PM
Labels (1)
AlexPage
Occasional Contributor

 

My objective is to create a serial chart that SUMs a field called "Miles" by the week it was edited using the "Editor" field, and it does this for all layers in the chart.

These are featuresets from different projects, but the schema is the same. I know haven't addressed the week bracketing at all yet, I'm just trying to get the data coming into the chart.

The only error I'm getting currently is "Invalid variable assignment". It's flagging the first GroupBy(,  there are no other known errors. 

I've been referencing the linked posts. Any help would be most appreciated.

CombineMultipleLayers(SerialChart) Calculate a statistic on a virtual field 

var agol = Portal('https://*********.maps.arcgis.com/');

var fs1 = GroupBy(
    FeatureSetByPortalItem(agol,'****************************',15,['*']false,
    ['Miles'],
    [
        { name:'total_miles1', expression:'Miles', statistic:'SUM'}
    ]
);

var fs2 = GroupBy(
    FeatureSetByPortalItem(agol,'****************************',15,['*']false,
    ['Miles'],
    [
        { name:'total_miles2', expression:'Miles', statistic:'SUM'}
    ]
);

var features = [];
var feat;

for (var w in fs1) {
    feat = {
        attributes: {
            count_the_miles: SUM(w['total_miles1']),
        },
    };
    Push(features, feat);
}

for (var p in fs2) {
    feat = {
        attributes: {
            count_the_miles: SUM(p['total_miles2']),
        },
    };
    Push(features, feat);
}

var combinedDict = {
    fields: [
        { name: 'count_the_miles', type: 'esriFieldTypeInteger'},
    ],
    geometryType: '',
    features: features,
};

return FeatureSet(combinedDict);

 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You were missing a comma and a close parenthesis on lines 4 and 12

FeatureSetByPortalItem(agol,'****************************',15,['*'],false),

View solution in original post

6 Replies
KenBuja
MVP Esteemed Contributor

You were missing a comma and a close parenthesis on lines 4 and 12

FeatureSetByPortalItem(agol,'****************************',15,['*'],false),
AlexPage
Occasional Contributor

Thank you Ken, I had the closed parenthesis in some iterations, but never had the comma.

It's no longer erroring out, but I'm still not summing fields yet, but at least I can save it now. I'll update as soon as I have some results. Much appreciation for spotting that error on my part!

Update: 10/10/24 This is what it's creating. 

AlexPage_0-1728583404572.png

 

0 Kudos
AlexPage
Occasional Contributor

Making progress. I've got data coming into the table now. The next step is figuring out the null in the Work_Line field. This is a domain of about 7 choices. Since the output is a text string I wouldn't think it needs a dictionary would it? Oh and the SUM function doesn't seem to be working yet, but at least it's showing something : D

I checked for nulls and there are none. I've been over and over the syntax, not seeing any typos.

 

var agol = Portal('https://********.maps.arcgis.com/');

var fs1 = GroupBy(
    FeatureSetByPortalItem(agol,'****************************',15,['*'],false),
    [
        'Miles',
        'Editor',
        'EditDate',
        'Work_Line_Mow'
    ],
    [
        { name:'toatlMiles1', expression:'Miles', statistic:'SUM'},
    ]
);

var fs2 = GroupBy(
    FeatureSetByPortalItem(agol,'***************************',15,['*'],false),
    [
        'Miles',
        'Editor',
        'EditDate',
        'Work_Line_Mow'
    ],
    [
        { name:'totalMiles2', expression:'Miles', statistic:'SUM'},
    ]
);

var features = [];
var feat;

// Process fs1
for (var w in fs1) {
    feat = {
        attributes: {
            sum_miles: Round((w['totalMiles1']),3),
            Miles: w['Miles'],
            Editor: w['Editor'],
            EditDate: w['EditDate'],
            WorkLineMow: w['Work_Line_Mow']
        },
    };
    Push(features, feat);
}

// Process fs2
for (var p in fs2) {
    feat = {
        attributes: {
            sum_miles: Round((p['totalMiles2']),3),
            Miles: p['Miles'],
            Editor: p['Editor'],
            EditDate: p['EditDate'],
            WorkLineMow: p['Work_Line_Mow']
        },
    };
    Push(features, feat);
}

var combinedDict = {
    fields: [
        { name: 'sum_miles', type: 'esriFieldTypeDouble'},
        { name: 'Miles', type: 'esriFieldTypeDouble'},
        { name: 'Editor', type: 'esriFieldTypeString'},
        { name: 'EditDate', type: 'esriFieldTypeDate'},
        { name: 'Work_Line_Mow', type: 'esriFieldTypeString'}
    ],
    geometryType: '',
    features: features,
};

return FeatureSet(combinedDict);

 

AlexPage_0-1728600371318.png

 

0 Kudos
KenBuja
MVP Esteemed Contributor

Can you supply screen shots of the two grouped FeatureSets?

0 Kudos
AlexPage
Occasional Contributor

This is all that it's outputting. Here's the way it's coming into a serial chart, keep in mind I'm just doing something with the data to see what's accessible. This is giving me the miles by field Editor, not what I want, just playing with it.

AlexPage_1-1728678191528.png

 

What I'm doing ultimately is calling 20-40 of these same layers from different projects, filtering by the Work_Line_Mow field (below) so that it only includes finished work. I was just trying to use the built in filter, but you can see in the screen shot it said incomplete condition, and it won't pull in the fields, this was surprising because I thought I'd mimicked the other syntax perfectly.

AlexPage_2-1728678439208.png

AlexPage_3-1728679368388.png

 

This is my flow logic, it should ingest the featuresets, filter the features in this layer by the status, then sort the remaining features by week using the EditDate, then sum each week in the Miles field.

So the Category axis is the layer/project, and the Value axis is the week this summed production was completed in.

So that it's like this vaccines per week per vendor chart. Very similar result, I'm just having a hard time duplicating this.

AlexPage_0-1728677984400.png

CombineMultipleLayers(SerialChart) 

Which direction should I go next?

 

0 Kudos
AlexPage
Occasional Contributor

I've working at the week sorting element and had more luck with a real layer than this virtual one.

This is where I'm at now.

var agol = Portal('https://*********.maps.arcgis.com/');

var fs1 = GroupBy(
    FeatureSetByPortalItem(agol,'***********************',15,['*'],false),
    [
        'Miles',
        'Editor',
        'EditDate',
        'Work_Line_Mow'
    ],
    [
        { name: 'ISOWeek1', expression: 'ISOWeek(Date(EditDate))', statistic:''},
        { name:'totalMi1', expression:'Miles', statistic:'SUM'},
    ]
);

var fs2 = GroupBy(
    FeatureSetByPortalItem(agol,'*************************',15,['*'],false),
    [
        'Miles',
        'Editor',
        'EditDate',
        'Work_Line_Mow'
    ],
    [
        { name: 'ISOWeek2', expression: 'ISOWeek(Date(EditDate))', statistic:''},
        { name:'totalMi2', expression:'Miles', statistic:'SUM'},
    ]
);

var features = [];
var feat;

// Process fs1
for (var w in fs1) {
    feat = {
        attributes: {
            sum_miles: Round((w['totalMi1']),3),
            Miles: w['Miles'],
            Editor: w['Editor'],
            EditDate: w['EditDate'],
            ISOWeek: w['ISOWeek1'],
            WorkLineMow: w['Work_Line_Mow']
        },
    };
    Push(features, feat);
}

// Process fs2
for (var p in fs2) {
    feat = {
        attributes: {
            sum_miles: Round((p['totalMi2']),3),
            Miles: p['Miles'],
            Editor: p['Editor'],
            EditDate: p['EditDate'],
            ISOWeek: p['ISOWeek2'],
            WorkLineMow: p['Work_Line_Mow']
        },
    };
    Push(features, feat);
}

var combinedDict = {
    fields: [
        { name: 'sum_miles', type: 'esriFieldTypeDouble'},
        { name: 'Miles', type: 'esriFieldTypeDouble'},
        { name: 'Editor', type: 'esriFieldTypeString'},
        { name: 'EditDate', type: 'esriFieldTypeDate'},
        { name: 'ISOWeek', type: 'esriFieldTypeInteger'},
        { name: 'WorkLineMow', type: 'esriFieldTypeString'}
    ],
    geometryType: '',
    features: features,
};

return FeatureSet(combinedDict);

Results

AlexPage_0-1728693592618.png

Here's the table I had using nearly the same format of script, but I can't seem to use $feature or $datapoint with the virtual data.

Maybe I'm going in the wrong direction, but I keep think I've got to get the data filtered by the status field and then sliced by week.

AlexPage_2-1728694613553.png

 

 

 

 

0 Kudos