How to calculate current-1 year in tableau

旧街凉风 提交于 2019-12-13 18:34:14

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!