I have a data set "sourceTable" with RoadNumbers associated for each entry. Each entry has an Individual_Removal_Score. I want to combine all entries based on RoadNumber and SUM the Individual_Removal_Score values to create one record for each RoadNumber with a Total_Score. I then want to filter "stats" to lookup RoadNumbers that match the ID field of the target layer and return the Total_Score. This is being done as an attribute rule in pro for a field in the target dataset.
//Reference Layer and relevant fields
var sourceTable = FeatureSetByName($datastore, "TNF_RoadConditionAssessment", ["RoadNumber", "Individual_Removal_Score"],false);
//key field for target layer
var ID = $feature.ID;
//statistic variable target layer
var Miles = $feature.Total_Miles;
//Group reference layer by RoadNumber and SUM Individual_Removal_Scores for each entry
var stats = groupby(sourceTable, 'RoadNumber',
{name: 'Total_Score', expression: 'Individual_Removal_Score', statistic: 'SUM'})
//Filter Summary table(stats) by RoadNumber where value is equal to the key field "ID"
var Lookup = First(Filter(stats, "RoadNumber = <a href="https://community.esri.com/t5/user/viewprofilepage/user-id/354972">@ID</a>"));
//return Total_Score/Miles if key field has a match
return iif(Lookup == null, null, ((Lookup.Total_Score)/Miles));
Script verifies but won't save because of an error on line 13 "Attribute value lookup error". I have used this exact script without the GroupBy() function just fine so I'm at a loss. I'm assuming the GroupBy() table isn't being returned properly so there is nothing to reference? Wondering if the field "Total_Miles" needs to be created physically somewhere or if it gets created in memory while its running. The way I understand it is the GroupBy() function creates a new temp FeatureSet. I thought I was creating a FeatureSet with RoadNumber and Total_Miles (being a sum of "Individual_Removal_Score") as the fields but my thinking is that it's breaking down because there are multiple entries with the same roadnumber? (Screen shot example of the table I'm attempting to group below)

Thanks for the input!