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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors