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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Centaur
Helper V
Helper V

If statement Help

Hello, I am getting an error in this IF statement.  I have tried "IF" and "IIF".  Do you happen to see where I am  wrong?  I am wanting to add a custom column to tag rows that are greater than the current date - 8 days.  maybe there is a better way to do this. I do not see how I can filter my [Date] column for the criteria unless I add a helper column as below. 

 

= Table.AddColumn(#"Sorted Rows", "Filter Grtr 8 days", each IIF((NOW()-[Date])<8,"Y","N"))

 

Centaur_0-1649680798329.png

 

1 ACCEPTED SOLUTION

Hi @Centaur ,

 

I already updated my code to correct this when I spotted it.

 

Also, based on your reply to jennratten, I think you will need to add a Date.From function to truncate the datetime value of today:

if Duration.Days(Date.From(DateTime.LocalNow()) - [Date]) < 8 then "Y" else "N"

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

5 REPLIES 5
BA_Pete
Super User
Super User

Hi @Centaur ,

 

The correct IF statement syntax in Power Query is ' if..then..else if..else'.

I think your statement would need to be something like this:

 

if Duration.Days(DateTime.LocalNow() - [Date]) < 8 then "Y" else "N"

 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Hi Pete,

thank you. I get an error though "2 arguments were passed...."?  

 

Centaur_0-1649683136960.png

 

Hi @Centaur ,

 

I already updated my code to correct this when I spotted it.

 

Also, based on your reply to jennratten, I think you will need to add a Date.From function to truncate the datetime value of today:

if Duration.Days(Date.From(DateTime.LocalNow()) - [Date]) < 8 then "Y" else "N"

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




jennratten
Super User
Super User

Here you are (assuming your date field is actually a datetime type.  If it is not, you will need to use Date.From ( DateTime.FixedLocalNow() 😞

= Table.AddColumn(#"Sorted Rows", "Filter Grtr 8 days", each if Duration.Days ( DateTime.FixedLocalNow()-[Date] ) < 8 then "Y" else "N", type text )

 

 

Hi Jenn,

 

I also have an error:

Not sure if I have done somethng wrong on my end. I added a custom column then pasted.  

Centaur_1-1649683226793.png

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.

Top Kudoed Authors