Post

1 follower Follow
0
Avatar

Calculation gives the wrong result on some records

Is there a reason why a calculation would give the correct result for most records, but a wrong answer for some?

For example, I have a calculation which takes the planned hours for a specific employer (work placement), and totals them. Of the 29 records which the calculation runs on, 7 of these have the wrong results when compared to the actual timetable.

The code is: 

var hours = @All of Planned hours (auto calc);
var emp = @All of Emp-Cal;
var sum= 0;

for (var i = 0; i < hours.length; i++) {
if (emp[i] == @All of Employer) {
sum += Number(hours[i]) || 0;
}
}
sum

Emp-Cal is a calculation field used to turn the Relationship of Employer from the Timetable into a field I can access (a tip I found in another post in this forum). Employer is linked to the specific record in the app this calculation is in.

This screenshot is the result I get for the calculation, for one specific person / employer:

And this screenshot is the total according to the timetable app, for the same person / employer:

As far as I can tell, the report and the timetable should have the same result - it does for most records, but not all. Given that it seems the calculation must work correctly, what am I missing for why some results are wrong? The timetable is filtered to show the specific student, activity is work placement - why would this be different to the report?

Of the 7 which are wrong, 6 show lower figures in the timetable, 1 shows higher in the timetable. I suspect that I'm missing something in the timetable app rather than the calculation being off, but can't think what. I'd be grateful for any assistance!

Susan Warren

Please sign in to leave a comment.

1 comment

0
Avatar

Ah - OK. I was missing the check that activity == work placement from the IF statement. It should read

if ((emp[i] == @All of Employer) && (act[i] == "Work Placement")) 

This is now rectified, and all except one record is correct.

I still can't work out why the one record has the wrong figure, though!

Timetable is filtered to Student [name], Activity = Work Placement, Employer = [her employer] - and the total number of Planned hours does not match the report app.

However, it is only 1 student so it's likely to be something in her records rather than an error in the coding, so I will do some digging and find it.

Susan Warren 0 votes
Comment actions Permalink