I don't try to accomplish this with set expressions. I use a data-drive approach. You should be using a time dimension.
RTP stands for Relative Time Periods. This script leverages your existing month dimension to add the following relative time elements to your app:
- To-Date ranges such as YTD and QTD
- Relative time periods such as "Previous Year", "Previous Month", or “same period last year”
- Rolling periods which are used for moving averages. (Ex. "Rolling 3 month average")
- Year-over-Year and MoM growth metrics
Not only that, these RTPs will work for any anchor month! (not just the current period)
This approach greatly simplifies your measures by only requiring two set modifiers.