简体   繁体   English

TABLEAU:calc字段以获取最后一个可用值

[英]TABLEAU: calc field to get the last value available

I'm using Tableau Desktop, my data are like this: 我正在使用Tableau Desktop,我的数据是这样的:

KPI,date,monthValue
coffee break,01/06/2015,10.50
coffee break,01/07/2015,8.30

and I want to build a table like this 我想建立一个像这样的表

KPI, year(date), last value
coffee time, 2015, 8.30

How can I set a calculated field in order to show me the last value available in that year? 如何设置计算字段以显示该年度的最新值? I tried to do: 我试着这样做:

LOOKUP([MonthValue], LAST())

But it didn't work and tells me 'cannot mix aggregate and non-aggregate', so I did: 但它不起作用并且告诉我'不能混合聚合和非聚合',所以我做了:

LOOKUP(sum([MonthValue]), LAST())

But it didn't work too. 但它也没有用。 How should I proceed? 我该怎么办?

If you are using Tableau 9 then you can do this with an LOD calc that looks for the max value in your date field and then checks if the current date value is the same as the max date value. 如果您使用的是Tableau 9,则可以使用LOD计算来查找日期字段中的最大值,然后检查当前日期值是否与最大日期值相同。

[Date] == {fixed: max([Date])}

As you can see in the example below when you use the calc as a filter you will only get the last row from your example above. 正如您在下面的示例中所看到的,当您使用calc作为过滤器时,您将只从上面的示例中获取最后一行。

在此输入图像描述

UPDATE: to get the values per year you can do something like: 更新:要获得每年的价值,您可以执行以下操作:

Here I am using a table calculation to find the max date per year and then ranking those dates and filtering down to the latest date in each year (which will be the one that has a rank equal to 1). 在这里,我使用表格计算来查找每年的最大日期,然后对这些日期进行排名并过滤到每年的最新日期(这将是排名等于1的日期)。

在此输入图像描述

!max date is WINDOW_MAX(ATTR(Date)) !max dateWINDOW_MAX(ATTR(Date))

!rank is RANK(Date) !rankRANK(Date)

You need to make sure that the table calculations are computer in the correct way (in this case across the values of each year). 您需要确保表计算是以正确的方式计算机(在这种情况下,跨越每年的值)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM