Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Dax Expression for Tagging Date Ranges in Date Table

Hi folks,

 

What is the best way to create custom tags for dates in a date table? I have the following example dax statement, which I need for creating specified/dynamic date range groupings for a bar chart (bar labels along the X-axis):

 

Example Date Grouping Column = if(DATESINPERIOD('My Date Table'[Example Date Grouping Column], TODAY(), -7, DAY), "Within the Last Week",  if(DATESINPERIOD('My Date Table'[Example Date Grouping Column], TODAY(), -14, DAY), "Last 14 Days",  if(DATESINPERIOD('My Date Table'[Example Date Grouping Column], TODAY(), -30, DAY), "Last 30 Days",  "Greater Than 30 Days")))
 
Thank you!
 
pbrenneise

 

  • hi Anonymous 

    try like:

    TagColumn =
    VAR _datediff = 
    DATEDIFF(DateTable[Date], TODAY(), DAY)
    RETURN
    SWITCH(
        TRUE(),
        _datediff>30, "Greater Than 30 Days",
        _datediff>14, "Last 30 Days",
        _datediff>7, "Last 14 Days", 
        "Within the Last Week"
    )

1 Reply

  • hi Anonymous 

    try like:

    TagColumn =
    VAR _datediff = 
    DATEDIFF(DateTable[Date], TODAY(), DAY)
    RETURN
    SWITCH(
        TRUE(),
        _datediff>30, "Greater Than 30 Days",
        _datediff>14, "Last 30 Days",
        _datediff>7, "Last 14 Days", 
        "Within the Last Week"
    )