5 Replies Latest reply on Nov 26, 2018 6:29 AM by Jennifer VonHagel

    How can I create a time-only parameter?

    Rafael Benavent

      What I would like to do:

       

      I would like to create a parameter where a user can enter a time such as "17:00" or "19:05".

      The parameter will be used in a calculated field to filter the data:

       

      [Tap-on Time] <= [End Time Control]

      AND

      [Tap-off Time] > [End Time Control]

      (Where End Time Control is the parameter)

       

       

      What I've tried:

       

      - Making an integer parameter and formatting it as "HH:mm".

      Didn't work as it would only display 00:00 no matter what the actual value was. Also the user was required to enter an integer.

       

      - Making a calculated field from the integer parameter and using a calculation to display it as hh:mm.

      Didn't work as the user could only select a single value which was the value the parameter was set to (so if the parameter was set to 36,000 the user could only choose 10:00).

       

      - Making a DateTime parameter and formatting it as "HH:mm".

      Didn't work as the parameter still showed a date and a calendar picker.

       

       

      I'm not sure what else to try. Any help is greatly appreciated.

        • 1. Re: How can I create a time-only parameter?
          Jennifer VonHagel

          HI Rafael,

           

          A couple questions:

          1. What data type is [Tap-on Time]? Is it DateTime, Time Only, Str?
          2. I didn't quite catch how you want to use the time parameter in your filter. This calculation would seem to exclude everything as the Parameter can only give a single time value and Tap-on Time can't be both <= and > than it.

          What I'd do for a time parameter is create a list of strings in the format HH:MM in Excel, then Copy and Paste that list into a String Parameter.

           

          So, using some calculations in Excel I generated this list (Excel workbook is attached, the calculations are in a separate tab).

           

          I copied The Time Strings from Row 2 to the bottom, and Pasted them into a Tableau Parameter:

           

           

          When shown in the view, this can either be a drop-down list, or you can let your users type directly into a box.

          If your Source Data has Time as a String, you can compare it directly to this parameter.  If your Source Data is a DateTime field, you could create a String time to match the parameter:

           

          Hope this helps, feel free to respond with more info if you need help with the filter.

           

          Best,

          Jennifer

          1 of 1 people found this helpful
          • 2. Re: How can I create a time-only parameter?
            Rafael Benavent

            Thanks for your in-depth reply.

             

            A couple questions:

            1. What data type is [Tap-on Time]? Is it DateTime, Time Only, Str?
            2. I didn't quite catch how you want to use the time parameter in your filter. This calculation would seem to exclude everything as the Parameter can only give a single time value and Tap-on Time can't be both <= and > than it.

            1. Right now it is an integer representing the time as seconds but I have another field, "Tap-on Time HHMMSS", which is formatted in the data source as HH:MM:SS (although Tableau insists on prefixing a meaningless date like "31/12/1989" in front of it).

             

            2. So basically in the time parameter you would select a time value in 24 hour format like "10:00" or "22:30". Then, the filter in the OP would only include records were Tap-on Time is less than or equal to the time value of the parameter AND Tap-off Time is greater than the time value of the parameter.

             

            Just wanted to answer your questions ASAP. Will have a look at your post now.

            • 3. Re: How can I create a time-only parameter?
              Jennifer VonHagel

              Ah-ha! Tap-OFF time. I did not read carefully enough!

               

              Hmm, I think you should be able to safely compare the String Parameter HH:MM to the String Calculated Time field HH:MM with > and < operators. Since the Hours and Minutes have leading zeros, the strings should be evaluated as < or > alphabetically in a correct way.

               

               

              Best,

              Jennifer

              • 4. Re: How can I create a time-only parameter?
                Rafael Benavent

                Thank you. Your answer really helped me out. I chose it as the correct answer.