简体   繁体   中英

TABLEAU: calc field to get the last value available

I'm using Tableau Desktop, my data are like this:

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.

[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.

在此输入图像描述

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).

在此输入图像描述

!max date is WINDOW_MAX(ATTR(Date))

!rank is RANK(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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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