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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Biko
New Member

API parameter yesterday date (excluding weekends)

Hi all, 

 

I am trying to do something similar with the below Alteryx expression. In the API URL, I want to include the date parameter. So if powerbi refreshes on Monday, it will lookback 3 days before which is friday. Else it will just lookback yesterday's date. My PowerBI advanced editor only can look back to yesterday's date. How can I extend to include the IF THEN ELSE statement?

 

Alteryx:

IF DateTimeFormat(DateTimeToday(),"%A") = "Monday"
THEN [FX URL] + DateTimeFormat(DateTimeAdd(DateTimeToday(),-3,"days"),"%Y%m%d")
ELSE [FX URL]+DateTimeFormat(DateTimeAdd(DateTimeToday(),-1,"days"),"%Y%m%d")

ENDIF

 

PowerBI:

DateTime.ToText(Date.AddDays(DateTime.FixedLocalNow(),-1), "yyyyMMdd")

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

if Date.DayOfWeek(DateTime.FixedLocalNow())=1

then

DateTime.ToText(Date.AddDays(DateTime.FixedLocalNow(),-3), "yyyyMMdd")

else

DateTime.ToText(Date.AddDays(DateTime.FixedLocalNow(),-1), "yyyyMMdd")

 

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

if Date.DayOfWeek(DateTime.FixedLocalNow())=1

then

DateTime.ToText(Date.AddDays(DateTime.FixedLocalNow(),-3), "yyyyMMdd")

else

DateTime.ToText(Date.AddDays(DateTime.FixedLocalNow(),-1), "yyyyMMdd")

 

Didn't realize it is that straightforward as I thought IF THEN ELSE is not accepted in advanced editor. The only thing I added below in red to recognize Monday is 1. 

 

if Date.DayOfWeek(DateTime.FixedLocalNow(), Day.Sunday)=1

then

DateTime.ToText(Date.AddDays(DateTime.FixedLocalNow(),-3), "yyyyMMdd")

else

DateTime.ToText(Date.AddDays(DateTime.FixedLocalNow(),-1), "yyyyMMdd")

 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors