Search code examples
tableau-apitableau-desktop

looking to create dynamic date buckets in tableau


I am looking to create the table below, trying to figure out the if statement with dates and buckets and need assistance. note the dates I have do not include days, just mm/yy.

enter image description here


Solution

  • Make a date field by string concatenation to add in a day value.

    date('01/'+[your_mm/yyyy_field])
    

    Then create a date bucket field with the newly created [date] calc and comparing to today's date.

    if datediff('month',[date],TODAY()) > 1 then 'In past'
    elseif datediff('month',[date],TODAY()) = 1 then 'Last Month'
    elseif datediff('month',[date],TODAY()) = 0 then 'Current Month'
    elseif datediff('month',[date],TODAY()) = -1 then 'Next Month'
    else 'Future'
    end