Hi Kashgar,
If the year-to-date (YTD) calculation uses a parameter like ${AsOfDate}, I’d recommend to add a filter for future completions as well (as a past date could be selected for the ${AsOfDate}). This would then look like this and you should select Sum as aggregate function in the visual:
ifelse(datediff({training_date},${AsOfDate},"YYYY") = 0 AND datediff({training_date},${AsOfDate},"DD") >= 0, 1, 0)
For the YTD calculation for the goal, the logic depends on whether you want to do that on a monthly or daily level. For both, the selected aggregate function in the visual should be Average.
To get the YTD goal on a monthly level, you could use the following calculation, which multiplies the number of month until the selected date with the monthly goal:
extract("MM",${AsOfDate})*{monthly_completions_goal}
To get the YTD goal on a daily level, you could use the following calculation:
(extract("MM",${AsOfDate})-1)*{monthly_completions_goal}+
(dateDiff(truncDate("MM",${AsOfDate}),${AsOfDate},"DD")+1)*{monthly_completions_goal}/dateDiff(truncDate("MM",${AsOfDate}),addDateTime(1, 'MM', truncDate("MM",${AsOfDate})),"DD")
This makes use of the monthly calculation up until the previous month and then prorates the monthly goal based on the number of days that already passed in the current/selected month. It also factors in the number of days the current/selected month has (as it might be 28, 29, 30, or 31).
Did this answer your question? If so, please help the community out by marking the best answer on your questions as "Solution! If you found a different solution in the meanwhile, we would be happy if you could share it with the community as well.