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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
rezaaditia
Helper III
Helper III

to get yesterday date with 2 scenario

Hi All -

 

i am really new in Power BI, even i can say, i just know power BI for 1 week 🙂

 

anyway, i want to create "filter validate date" for my references in query editor.

currently i able (found) to get yesterday date, but i want to have scenario where if today is monday then it will get Friday date not sunday,

 

this is to get yesteday date = 

Date.AddDays(Date.From(DateTime.FixedLocalNow()),-1)

 now if today is monday, then the formula should be = 

Date.AddDays(Date.From(DateTime.FixedLocalNow()),-3)

 how to combine this into 1 formula in query editor? 

 

Thanks in advance

1 ACCEPTED SOLUTION

Hi @rezaaditia ,

 

could you please show me the error details?

because it works on my sample.

to get yesterday date with 2 scenario.PNG

 

Aiolos Zhao





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

6 REPLIES 6
AiolosZhao
Memorable Member
Memorable Member

Hi @rezaaditia ,

 

You can use a function called Date.DayOfWeek().

eg.

if Date.DayOfWeek([Date]) = 1 then
adddays(-3)
else adddays(-1)

Please try.

Aiolos Zhao





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @AiolosZhao 

 

i did try, no error in syntax but the result shows error

Capture.JPG

thanks

Hi @rezaaditia ,

 

you need to put your column name into your date.adddays() function,

like :

date.adddays(your_date_column, -3)

please make sure the type of your_date_column is date.

 

Aiolos Zhao





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @AiolosZhao 

 

thank you for your help so far, your formula given is working, but not fit into my dashboard.

i don't want to put specific columns in formula, i want to use general date. can we create it using DateTime.FixedLocalNow()

 

I did try, but shows error... can you please suggest

 

if Date.DayOfWeek([Date]) = 1 then
Date.AddDays(Date.From(DateTime.FixedLocalNow()),-3)
else
Date.AddDays(Date.From(DateTime.FixedLocalNow()),-1)

 

thanks again

Hi @rezaaditia ,

 

could you please show me the error details?

because it works on my sample.

to get yesterday date with 2 scenario.PNG

 

Aiolos Zhao





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @AiolosZhao ,

 

thanks, its working now 🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.