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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.