Question

I have a calculation, and I only want to return the left most value ie, the first time the condition is met.enter image description here

In the images it shows 95% 96% etc etc I only care for the column 5 where the condition of 95 is met.

EDIT(more info)

Ok so the percentages are calculated this way.

ROUND( RUNNING_SUM( SUM( [days_to_close_cnt] ) )/ SUM([newo_dt_cnt]),2 )

Using and the "Days to Close" gives me the column information.

The Line graph looks like this. enter image description here

if [% Completed] >= .98  and  [% Completed] < 1 then INT( 98 )
elseif [% Completed] = 1  then INT(  1 )
elseif  [% Completed] >= .95  and [% Completed] < .98 then INT( 95 )
elseif  [% Completed] < .95 and [% Completed] >= .0 then INT(  0 )
end

Is that calc I am using to color in this case. enter image description here

Was it helpful?

Solution

It looks like you are trying to tell when a running total crosses a threshold. In Tableau, doing that requires table calculations which operate on the aggregated values that have been returned from the data source.

I put together an example viz to illustrate how to approach the issue.

In the live version via the link above, try hovering over some of the data points to see the tooltips for detail, and incrementally increasing the threshold to see how the calculation behaves. You can also click on the table tab to see some of the intermediate results.

Here's a static snapshot in case you can't access the dynamic one linked abovestatic snapshot

In a nutshell, you can define a boolean calculated field to tell whether the running total meets the threshold on a particular day and then use window_min() to calculate the first day that meets the threshold. For more detail, download the workbook and check out the calculated fields to understand how it works.

Table calcs are powerful, but are also the feature in Tableau that takes the most time to get your head around. So break things down and tackle them in small bites instead of trying to write complex table calcs all at once. Luckily, there are short cuts (quick table calcs) for the most common cases. Be aware that specifying the partitioning and addressing fields (i.e., compute using) for a table calc is as important as writing the formula.

Finally as an aside, your calculated field can be written more efficiently as:

if [% Completed] < .95 then 0
elseif [% Completed] < .98 then 95
elseif [% Completed] < 1 then 98
else 1
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top