cancel
Showing results for
Did you mean:

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

2 REPLIES 2
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.

Announcements

#### Join Arun Ulag at MPPC23

Get a sneak peek into this year's Power Platform Conference Keynote.

#### Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

#### Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

#### Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Top Solution Authors
Top Kudoed Authors