It would help if you would include a packaged workbook with your post, but I'll take a stab based on the information you provided. Try the following:
SUM(ZN([Measure 1])) - SUM(ZN([Measure 2]))
Sometimes there are NULL values in one or the other measure that cause the whole calculated field to compute to NULL. Putting a ZN around it will return 0 for NULL rows, so it shouldn't affect your calculation.
If this doesn't work, please post a book,
You'll most likely want to wrap the ZN function around the aggregate function.
I'm assuming you are working with sparse data, in some form or another. So your individual values are not what is causing this to be NULL (Aggregates ignore individual NULL records much like a DB), but the Values of the aggregate in relation to your vizLoD.
ZN(SUM([Measure 1])) - ZN(SUM([Measure 2]))
Depending on your situation, pill arrangement, you may need to enforce Densification in order for the marks to properly show.
If you can share an example workbook, that would be very helpful.
I often need to do this kind of calculation, although I haven't attempted it using a parameter to select whether I'm comparing months, years, etc.
I think the trick is to look at your column header... how are you telling Tableau to distinguish the current period vs the prior period?
In my case, I use a calculated field "CYPY" that tells Tableau if the date is less than a year ago it's "CY", and if it's more than a year ago but less than 2, it's "PY". (I use a parameter to set the relative end date, since you can't use MAX([Date]) in calculated fields.)
So when I make my table calculation to determine the difference, I have to set it to calculated using "CYPY" relative to "PY". Then I can either hide the PY column altogether or just know that the % difference for PY will always be zero.
I've attached a workbook to show you what I mean.
YoY.twbx 333.1 KB