I think you cannot perform set analysis in script.
Instead do one thing, take the resident of the dimensions you are calculating on do summation in the resident table and try grouping.
if(CanonicalDate <= max(CanonicalDate ), sum(course_completed)) as course_completed
This may be better suited for a Variable defined outside of the data load editor.
The Let command expects whatever is after the = sign to be an expression which can be evaluated, but you are passing it a string. If you were to use the Set command, it expects a string after the = sign, which it will assign to the variable. First suggestion is to test in your application that the expression actually works. Then remove the single quotes (') from around the expression in the Let statement. Finally, if all else fails, define the variable in the application outside of the data load editor (because it may not allow set analysis in the data load editor.