Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 600
stegue88 Avatar asked Mar 15 '23 07:03

stegue88


1 Answers

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.

enter image description here

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

enter image description here

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

like image 170
e h Avatar answered Apr 06 '23 21:04

e h