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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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