Datetime Bins

Version 13

    Description:

    It is often useful to divide up the members of a datetime dimension into uniformly sized bins. Tableau has built-in support for doing this at the level of common datetime units, ranging from years to seconds. However, it is often convenient to use other bin sizes such as: 10 days, 4 hours, 30 minutes or 15 seconds, for example.

    This calculation supports defining any arbitrary size for a time bin. The most convenient way to use it is to define the bin size as a number of seconds, minutes, hours or days. Both the unit and the number of units per bin may be defined as parameters, allowing the bin sizes to be adjusted dynamically, as demonstrated in the workbook below.

    Example Calculation:

     

    DATETIME(INT(FLOAT([datetime]) * ([Units per Day] / [N])) / ([Units per Day] / [N]))

     

    [datetime] - A datetime (or date) dimension

    [Units per Day] - The number of the chosen unit in a day (i.e. Day = 1, Hour = 24, Minute = 1,440, Second = 86,400)

    [N] - The number of units per bin

    Comments:

    The following example shows the number of active, idle and abandoned sessions on a web server over the course of a day.

    Experiment with changing the parameters [Unit] and [N].

    Note that [Unit] is actually an integer parameter equivalent to [Units per Day] in the calculation above. The values of Day, Hour, Minute and Second are aliases for 1, 24, 1,440 and 86,400.