Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
pbrenneise
Frequent Visitor

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

 

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @pbrenneise 

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"
)

View solution in original post

1 REPLY 1
FreemanZ
Super User
Super User

hi @pbrenneise 

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"
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.