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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
DBC01
Regular Visitor

Switch value between dates

Hi All,

 

I currently have the column Dax script in a custom column. Depending on the date within the 'Service_expiry_date' column it will return the status of the service ("expired", "expiring within 5 months", "test not due").

 

Cert status = 
VAR _today = TODAY()
VAR _date = EDATE(_today, 1) - 1
RETURN
SWITCH(
TRUE(),
[service_expiry_date] <= _today, "Test expired",
[service_expiry_date] <= _date, "Test Expiring within 1 month",
[service_expiry_date] > _date, "Test not yet due",
"Check data" -- This is a catch-all for any unexpected results
)

 
I would like to add a 4th return value, "Expired within last 5 days". I have tried the below but that produced an error. Does anyone have any ideas as to how this could be achieved?

 

Cert status = 
VAR _today = TODAY()
VAR _today5 = TODAY()-1 || -2 || -3 || -4 || -5
VAR _date = EDATE(_today, 1) - 1
RETURN
SWITCH(
TRUE(),
[service_expiry_date] <= _today5, "Test expired within last 5 days",
[service_expiry_date] <= _today, "Test expired",
[service_expiry_date] <= _date, "Test Expiring within 1 month",
[service_expiry_date] > _date, "Test not yet due",
"Check data" -- This is a catch-all for any unexpected result
)

 

Thank you in advance 🙂

1 ACCEPTED SOLUTION
Kedar_Pande
Super User
Super User

@DBC01 
You can try:

Cert status = 
VAR _today = TODAY()
VAR _fiveDaysAgo = _today - 5
VAR _date = EDATE(_today, 1) - 1
RETURN
SWITCH(
TRUE(),
[service_expiry_date] > _fiveDaysAgo && [service_expiry_date] <= _today, "Test expired within last 5 days",
[service_expiry_date] <= _fiveDaysAgo, "Test expired",
[service_expiry_date] <= _date, "Test Expiring within 1 month",
[service_expiry_date] > _date, "Test not yet due",
"Check data" -- This is a catch-all for any unexpected results
)

View solution in original post

2 REPLIES 2
Kedar_Pande
Super User
Super User

@DBC01 
You can try:

Cert status = 
VAR _today = TODAY()
VAR _fiveDaysAgo = _today - 5
VAR _date = EDATE(_today, 1) - 1
RETURN
SWITCH(
TRUE(),
[service_expiry_date] > _fiveDaysAgo && [service_expiry_date] <= _today, "Test expired within last 5 days",
[service_expiry_date] <= _fiveDaysAgo, "Test expired",
[service_expiry_date] <= _date, "Test Expiring within 1 month",
[service_expiry_date] > _date, "Test not yet due",
"Check data" -- This is a catch-all for any unexpected results
)

Thank you Kedar for this, it works exactly as I'd hoped! 🙂

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.