You can try the YearToDate() function. Your example is complex, so it might not work out of the box.
You might have to create a metric after doing all the preparation work you describe. This metric would carry the number you want, and then can turn it into a YTD value, or display both:


You can certainly create a new metric, be it monthly or YTD.
(Apologies if I'm stating the obvious :-O)