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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
AndreeaV
Advocate I
Advocate I

Conditional statement with dynamic dates

Hi,

I would like to create a column based on a conditional statement with dynamic dates like this:

if [Date] is the latest date, "Most recent"

if [Date] is the latest date -1 (day), "One day ago"

if [Date] is the latest date -7 (day), "One week ago"

if [Date] is the latest date -1 (month), "One month ago"

if [Date] is the latest date -1 (quarter), "One quarter ago"

if [Date] is the latest date -1 (year), "One year ago"

Thanks!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@AndreeaV , Try a new column like

 

New column=
Var _max = max(Table[Date]) // or use Today()
return
Switch(True(),
[Date] = _max ,"Most recent",
[Date] = _max-1 , "One day ago",
[Date] = _max -7 , "One week ago",
[Date] = date(year(_max), month(_max) -1, day(_max)), "One month ago",
[Date] = date(year(_max), month(_max) -3, day(_max)), "One quarter ago",
[Date] = date(year(_max)-1, month(_max), day(_max)), "One year ago"
)

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@AndreeaV , Try a new column like

 

New column=
Var _max = max(Table[Date]) // or use Today()
return
Switch(True(),
[Date] = _max ,"Most recent",
[Date] = _max-1 , "One day ago",
[Date] = _max -7 , "One week ago",
[Date] = date(year(_max), month(_max) -1, day(_max)), "One month ago",
[Date] = date(year(_max), month(_max) -3, day(_max)), "One quarter ago",
[Date] = date(year(_max)-1, month(_max), day(_max)), "One year ago"
)

Thanks @amitchandak! It worked.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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