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
Atinder
Helper III
Helper III

Add IF date formula in the custom date

Hello, 

I want to add a custom date column in the table by using IF function. 

 

I want to see what items I received today by the posting date. 

 

= Table.AddColumn(#"Expanded PostedPO", "Custom", each if [PostedPO.Posting_Date] >= #date(today()) then "yes" else null)

1 ACCEPTED SOLUTION

My bad, I used the wrong syntax.

 

How about this:

= Table.AddColumn(#"Changed Type", "Custom", each if [PostedPO.Posting_Date] >= Date.AddDays(Date.From(DateTime.LocalNow()), - 1) then "yes" else null)

 

/Tom

https://www.tackytech.blog

https://www.instagram.com/tackytechtom



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

11 REPLIES 11
tackytechtom
Super User
Super User

Hi @Atinder ,

 

Does it work that way?

Table.AddColumn(#"Expanded PostedPO", "Custom", each if [PostedPO.Posting_Date] >= Date.AddDays(DateTime.LocalNow(),-1)) then "yes" else null)

 

Let me know!

 

/Tom

https://www.tackytech.blog

https://www.instagram.com/tackytechtom



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Hi@Tom,

 

No, I am getting this error.

 

Atinder_0-1644256309900.png

 

 

In the 'Custom Column' box you just need to enter this part...

if [PostedPO.Posting_Date] >= Date.AddDays(DateTime.LocalNow(),-1)) then "yes" else null

 

Not from the "Table.AddColumn...."

 

If this works, please accept Tom's answer as the solution, not this one.

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

I am also getting this error

Atinder_0-1644267075509.png

 

Apologies, I copied the wrong text from @tackytechtom's answer. Use the below instead.  

Again, please accept Tom's answer if this solves your problem.

if [PostedPO.Posting_Date] >= Date.AddDays(Date.From(DateTime.LocalNow()), - 1) then "yes" else null

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

hi@KNP

 

i am getting this error.

Atinder_0-1644265919915.png

 

My bad, I used the wrong syntax.

 

How about this:

= Table.AddColumn(#"Changed Type", "Custom", each if [PostedPO.Posting_Date] >= Date.AddDays(Date.From(DateTime.LocalNow()), - 1) then "yes" else null)

 

/Tom

https://www.tackytech.blog

https://www.instagram.com/tackytechtom



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

tackytechtom
Super User
Super User

Hi @Atinder ,

 

how about this:

Date.AddDays(DateTime.LocalNow(),-1)

 

/Tom

https://www.tackytech.blog

https://www.instagram.com/tackytechtom

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Hi@Tom,

 

I am getting error but this message pops up when I put -1. 

 

Atinder_1-1644248359454.png

 

Atinder_0-1644248262692.png

 

tackytechtom
Super User
Super User

Hi @Atinder ,

 

This code snippet might help you:

Table.AddColumn(#"Expanded PostedPO", "Custom", each if [PostedPO.Posting_Date] >= Date.From(DateTime.LocalNow()) then "yes" else null)

 

Let me know!

 

/Tom

https://www.tackytech.blog

https://www.instagram.com/tackytechtom





Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Hi@Tom,

 

Solution works. How can I look yesterday's posting date. I tried to put -1 after now()-1 but it is not working.

 

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.

Top Solution Authors