There are a variety of ways to go about this, via table calculations, self-blend, pre-aggregation, or custom calculated fields. Attached is a version of the latter, I used the Superstore Sales sample data with Sales as a standin for expenses and Sub-Category as a stand-in for expense category. here's one where calculated fields are used to identify whether a given row is in YTD or in the prior 2YTD, then additional calculated fields return YTD Sales and the avg of Prior 2 YTD Sales, then the latter measure can be used as a cell-level reference line.
Please pate the Logic in the Forum along with the Workbook, The Users will note down the logic who don't have the Tableau Environment.
It is my Humble request to every one.