Is there a simple change I can make to this formula in order to still get full YTD 2021 data for this particular set or will I have to change more in the script itself?
Your formula is still valid for Current YTD, for Previous YTD (PYTD) you need to create a new one:
1. Assuming that the values for Restated POS Year are all years, you will need to decrease in 1 the max year:
$(=Max([Restated POS Year])-1)
2. Optionally In script, create a new Flag IsInPTYD (is in Previous Year To Date) with value 1 for 2021 and 0 for current year and the rest of the years, or just remove that part from Set Analysis formula.