0
votes

I have a calculated field called Booking_Size with formula:

IF RANK_PERCENTILE(SUM(BK_Total)) >= 0 AND RANK_PERCENTILE(SUM(BK_Total)) < .5 THEN 'Small'

ELSEIF RANK_PERCENTILE(SUM([BK_Total])) >= .5 AND RANK_PERCENTILE(SUM([BK_Total)) < .7 THEN 'Medium Small'

ELSEIF RANK_PERCENTILE(SUM([BK_Total])) >= .7 AND RANK_PERCENTILE(SUM([BK_Total])) < .9 THEN 'Medium'

ELSEIF RANK_PERCENTILE(SUM([BK_Total])) >= .9 AND RANK_PERCENTILE(SUM([BK_Total)) < .95 THEN 'Medium Large'

ELSE 'Large' END

I want to make this a context filter because if I use any other filter on top of the above filter the RANK PERCENTILE function in the above filter(Booking_Size filter) is recomputing the already filtered table.

1

1 Answers

1
votes

You can't make table calculation filters into context filters.

Context filters are evaluated very early in the operation pipeline at the data source (aka database server). Table calculations are computed very late in the operation pipeline by Tableau (aka client).

So you asking why something that happens late on one computer by definition can't be set to happen early on a different computer. The reason is that the table calculation functions, like rank_percentile, are implemented by Tableau itself acting upon the aggregate query results returned by the database or data source.

If you want to push that functionality early in the pipeline, it needs to use functions provided by the original data source. So if your database supports features like rank_percentile, you can put them into the underlying query, say with custom sql, or pass through SQL calls, or by defining a view in the database.

BTW, Your calculated field unnecessarily repeats comparison tests

if you define a calculated field called rk as RANK_PERCENTILE(SUM(BK_Total))

Then your field can be defined more efficiently as below since each test can assume the prior tests failed.

if rk < .5 then
  'Small'
elseif rk < .7 then 
  'Medium Small'
elseif rk < .9 then
  'Medium'
elseif rk < .95 then
  'Medium Large'
else
  'Large'
end