2 Replies Latest reply on Jun 20, 2016 4:17 PM by Todd Hogarth

# I want to write a tooltip that conditions the plural tense of days, minutes, hours and seconds. I would love a headstart.

I know how to do it, I just don't want to start grinding it out if someone has done some of the work for me.

I used Jonathan Drummey's post about formatting time (http://drawingwithnumbers.artisart.org/formatting-time-durations/) to generate my days, hours, minutes, and seconds to get those respective fields.

Now I want a tooltip to show "Blah blah next thing happens in 0 days, 2 hours, 15 minutes, and 12 seconds.

That looks ok but 1 days, 1 hours, 15 minutes, and 12 seconds doesn't look so great.

Also I do not like  0 days, 0 hours, 0 minutes, and 12 seconds when I could just show 12 seconds.

I've read Format Tooltips for Conditional Dimensions | Tableau Software  and I understand the task before me. What I am hoping is that someone has banged this out already and will share with me!!

• ###### 1. Re: I want to write a tooltip that conditions the plural tense of days, minutes, hours and seconds. I would love a headstart.

You're going to need a series of nested conditional statements, I'll mock

something up here with hours, minutes, and seconds, you'll have to add an

extra level to deal with days. Assuming you have computed Hours, Minutes,

and Seconds as separate calculated fields:

IF  == 0 THEN

IF  == 0 THEN

STR() + ' seconds.'

ELSE

STR() + ' minutes, and ' STR() + ' seconds.'

ELSE

STR() + ' hours, ' + STR() + ' minutes, and '

STR() + ' seconds.'

END

Jonathan

On Thu, Apr 7, 2016 at 1:14 PM, James Keuning <tableaucommunity@tableau.com>

• ###### 2. Re: I want to write a tooltip that conditions the plural tense of days, minutes, hours and seconds. I would love a headstart.

Undoubtedly you have figured something out already, but this is my solution to convert seconds to HMS, which expects the base value to be in seconds.

1. [duration_seconds]
2. [duration_seconds_int] = int([duration_seconds])
3. [hours_whole] = ([duration_seconds_int] / 3600) - (([duration_seconds_int] % 3600)/3600)
4. [hours_remainder_seconds] = [duration_seconds_int] - ([hours_whole] * 3600)
5. [minutes_whole] = ([hours_remainder_seconds] / 60) - (([hours_remainder_seconds] % 60) / 60)
6. [minutes_remainder_seconds] = [hours_remainder_seconds] - ([minutes_whole] * 60)
7. [duration_text] =
if [duration_seconds] < 1 then "< 1s"
else
iif([hours_whole] > 0, str([hours_whole]) + "h" + iif([hours_remainder_seconds] > 0, ", "," ") ,"")
+
iif([minutes_whole] > 0, str([minutes_whole]) + "m" + iif([minutes_remainder_seconds] > 0, ", ",""),"")
+
iif([minutes_remainder_seconds] > 0, str([minutes_remainder_seconds]) + "s","") end

997 seconds would then be represented as "16m, 37s"

This works well with values coming from a data source. Your luck may vary with tableau aggregates.

Would be nice to have this built-in to a future version (https://community.tableau.com/ideas/4826 )