Well, right away, I see that you have My Loads as the subordinate, linked library, which it's not. It is the primary library, so this can never work. I wish we had your library structure field definitions.
You could try screenshots, but they are often partial. I think the easiest way would be to just go into (in mobile) Edit library in each library and doing an export, which will result in a template file. If you send those (zipped or not) to us, we'll be able not only to see your definitions, but to create the libraries in our To/From Others groups and work with them if needed. That would be great.
Well, I don't have any idea what your Link to Entry fields look like or what library each is aimed at, but I'm surprised the script even worked, as My Loads seems to be linked to itself. If lineHaulMiles is defined in My Loads, it can't be the detailed, individual, maybe dated mileages, because there's only one of them, and if there are many of them, you seem to have just as many sums; it's very confusing. So, I think we need to (1) understand better what you're trying to do & what your trying to do it with and (2) reorganize your database structure before spending much time scrutinizing the current structure.
So, if you can help us get #1 & #2 and the template files, I think we can help you get this done.
Maybe instead of the above, let me take a shot at imagining what you're trying to do, and you can correct that to whatever you like. This will make sense to me, at least...
My Time Periods...
Interval as Date field (month, year, whatever)
TotalMiles as JavaScript field
Trips as Link to Entry field, many-to-many, aimed at the Trips library
Trips...
Date as Date field
MilesThisTrip as Integer field
(Maybe also destinations, client, etc)
Other libraries good to know about, but not detailed
Given this definition, here would be the script for the TotalMiles JavaScript field...
var trips = field("Trips");
var numTrips = linkedEntries.length;
for (var lex = 0, result = 0; lex < numTrips; lex++)
result += field("MilesThisTrip");
result; // The result is the SUM of all miles
We're down to 4 statements now (5 lines, because I indented). I have not tested this code; I haven't even constructed the imaginary libraries. I hope I haven't included any errors.
If My Loads is supposed to be equal to Trips (Is a load a trip?), then maybe all you need is a single mileage library with an aggregation to show the Total Miles in the bottom bar.