What exactly do you want to have as a result? As pointed out by others before, you cannot use the SUM expression the way you do in the second load, and that is why you get the error. So it is not the code under the 'resident' that poses the problem, but the code above.
You could use Temp1 to calculate the sums, or you could use a mapping and then map the totals in the Temp1. It depends on your aim.
I have a subclassification field and bucket field with values 1 week, 2week, 1month, 2months, >3months
I want to insert a new bucket value "Total" which has a value of amount for that particular classification or subclassification field.
and the requirement is as
I can calculate this total by using an expression in pivot table but the thing is bucket if a field which is pivoted to be on top as shown in picture. and If I use an expression in chart, it gives total column for each of bucketvalue. but that is not required actually. the requirement is as above.