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

IF Statement using Power Query

Hello,

 

I am trying to write an IF statement to capture the following dates. I have and excel spreadsheet withs millions of records. For one of the columns in my spreadsheet, I want to create a new column to capture all DT_SCHED (date field) prior to June 1, 2017 and return a "Delivery Date of June 1st" and if the DT_SCHED date is greater than June 1st but less than December 31st, I want my IF statement to return "December 1st" delivery date.  

 

Could anyone help me figure this out? I don't have the Power Query Add-In to do a conditional lookup but have attached a screenshot with my first attempt but apparently the formula is VERY WRONG 🙂DELIVERY DATE.PNG

1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

Try this code:

 

= if [DT_SCHED] < #date(2017,6,1) then "DELIVERY DATE JUNE 1ST" else if [DT_SCHED] < #date(2017,12,31) then "DELIVERY DATE DECEMBER 1ST" else null

 

PQ is case sensitive and if...then...else is all lower case, just like null.

 

Also mind your boundaries: in your information, June 1st is undefined; in the code above it returns December 1.

Likewise, December 31, 2017 will return null, according to the specifications provided.

 

How can you have millions of rows in Excel? As far as I know, Excel has a maximum of 1,048,576 rows

Specializing in Power Query Formula Language (M)

View solution in original post

17 REPLIES 17

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.