问题
I am using Tableau 8.2,I want to show calculations for current as well as previous year,how to apply this dynamically? it is getting possible if the year is written manually but it will be only temporary solution, how to do that dynamically? i.e on applying filter Year=2013 then sales and orders value of current-1 year should be displayed I have sales and orders On the Columns.
回答1:
A quick solution to this would be to create a new calculated field for previous year sales by using the Lookup function.
For example:
LOOKUP(SUM([SALES]),-1)
回答2:
You can simply introduce two calculated fields which will give you the current and previous year. These can be used on the rows and columns shelves or any where else depending on whether your aiming for chart, text table or any other viz.
Calculated field 1 = Current Filter if datediff('year',[Date],TODAY() )=0 then 1 ELSE 0 END
Calculated field 2 = Previous Filter if datediff('year',[Date],TODAY() )=1 then 1 ELSE 0 END
The formulas above can be used if the required measure is just a count otherwise you could replace: then 1 with then [Amount] or whatever measure this applies to.
来源:https://stackoverflow.com/questions/27008303/how-to-calculate-current-1-year-in-tableau