How to Split Hours into Half-Hour Intervals for Tableau 

How to Split Hours into Half-Hour Intervals for Tableau 

We often segment data in Tableau into hourly chunks to visualise data across time, say 00:00, 01:00, 15:00, 16:00 and so on. 

I came across a situation last week, where it was needed to break this data down further, it to half hourly, or 30-minute chunks. This can be especially useful for visualising trends by time of day, identifying peak periods, or analysing granular patterns within your data.

Unfortunately, our good friends at Tableau don’t offer a built-in function to split hours into half-hour intervals. So, we need to do it ourselves, here are a couple of ways to do this. 

Method 1: Using Table Calculations

  1. Create a Calculated Field:
    1. Name: Half Hour Interval
    1. IF DATEPART(‘minute’,[timedatefield])<30
      1.  THEN STR(DATEPART(‘hour’,[timedatefield]))+ “:00”
    1.  ELSE STR(DATEPART(‘hour’,[ timedatefield]))+”:30″
    1.  END
  2. Drag and Drop:
    1. Drag the newly created calculated field to the Rows or Columns shelf.
    1. Right-click on the field and select “Discrete”.

Method 2: Using Custom

  1. Create a Field in SQL:

If you don’t to do this directly in Tableau, you can do this directly at the data source before bringing it into Tableau. Here’s an SQL query example (adjust it based on your database):

SELECT DATE_TRUNC(‘hour’, timedatefield) + INTERVAL ’30 minute’ * FLOOR(DATE_PART(‘minute’, timedatefield) / 30) AS HalfHourInterval

  1. Drag and Drop:
    1. Drag the newly created SQL field to the Rows or Columns shelf.
    1. Right-click on the field and select “Discrete”.

That’s about it. Let me know if you stumble across some little useful nuggets like this.

Share this content:

Leave a Reply

Your email address will not be published. Required fields are marked *