Last Modified Date: 20 Jul 2023
Environment
Tableau DesktopAnswer
CLICK TO EXPAND SOLUTION
Option 1: Use a Date & Time field and then format the values as time only
In the example workbook, employee work times are recorded as date and timestamps when employees clock in and out. The goal is to show the only the time the employees clock in and out each. These instructions begin from the "Opt 1: original" worksheet. Directions to create "Opt 1: original" are in the workbook.
- Right-click [Shift Start] on the Rows shelf and select Format…
- In the left-hand Format pane, in the dropdown menu for Dates, select custom and type in something like "h:mm AMPM" without quotes
- Repeat steps 1-2 for all Date & Time fields
CLICK TO EXPAND SOLUTION
Option 2: Use the Hour date part
- Right-click [Call Time] on the Rows shelf and select the first More > Hour
Note: There are two sections in the right-click menu for dates that correspond to whether to show the date part, or the whole date truncated up to a particular level. In this example, we want the date part Hour, and not the whole date truncated to the nearest hour. To learn more see Changing Date Levels
- Right-click HOUR(Call Time) on the Rows shelf and select Format…
- In the left-hand Format pane, in the dropdown for Dates, select 12-Hour or the desired format
CLICK TO EXPAND SOLUTION
Option 3: Shift all date & time values to the same date
In the example workbook, calls are recorded at the timestamp they come in as a Date & Time field. The goal is to show the average number of calls per minute regardless of date. These instructions begin from the "Opt 3: original" worksheet. Directions to create "Opt 3: original" are in the workbook.
- Select Analysis > Create Calculated Field
- In the Calculated Field dialog box that opens, do the following, and then click OK:
- Name the calculated field. In this example, the calculated field is named "Call Time w/o Date"
- In the formula field, create a calculation similar to the following:
DATEADD('day', DATEDIFF('day', [Call Time], TODAY()), [Call Time])
- Remove HOUR(Call Time) from the Rows shelf
- Right-click and drag [Call Time w/o Date] to the Rows shelf
- In the Drop Field dialog, select Call Time w/o Date (Continuous) and click OK
CLICK TO EXPAND SOLUTION
Option 4: Append all times to the same date to create a date field
In the example workbook, class times are recorded as just the time without date. The goal is to show a schedule of when classes occur over the week.
- Select Analysis > Create Calculated Field
- In the Calculated Field dialog box that opens, do the following, and then click OK:
- Name the calculated field. In this example, the calculated field is named "Start Date"
- In the formula field, create a calculation similar to the following:
DATETIME( "1/1/19 " + [Start Time] )
Note that there is a space after the date, this will help Tableau Desktop correctly read the date and time.
- Repeat steps 1-2 for any fields with time data stored as text values
- Right-click and drag [Start Date] onto the Columns shelf
- In the Drop Field dialog, select Start Date (Continuous) and click OK
- Drag [Day] to the Rows shelf
- Create a calculated field with a name like "Class Length" with a calculation similar to the following:
DATEDIFF('minute', [Start Date],[End Date])/60/24
Note: elapsed time must be in number of days in order to graph correctly on a Gantt chart. DATEDIFF('day',...) will not return fractional days, therefore we use DATEDIFF('minute',…) and then divide by the appropriate number to get number of days. - Drag [Class Length] to Size on the Marks card
- Drag [Class] to Color and to Text on the Marks card
Additional Information
Tableau requires times in Date & Time fields to be associated with a date. This allows for chronological sorting across days.In order to graph times from different days on top of each other, the times must be shifted to the same day. If the original data does not include a date, then a Date & Time field can be created with an arbitrary date.
Thank you for providing your feedback on the effectiveness of the article.
Open new Case
Continue Searching
Knowledge Base
Community
Product Help
Training and Tutorials