I think the problem is caused by using the MIN() and MAX() functions in the where clause - I doubt if this is a correct syntax.
What we usually do is calculate MIN and MAX upfront, store them in two variables, and then use the variables in the next LOAD statement.
Also, we don't typically pre-calculate the YTD amounts - instead, we calculate a calendar Flag for Current YTD dates and for Prior YTD dates, and then use the flags in chart expressions - you can either multiply the amounts by the flags, or use Set Analysis to filter by flags.