Forum Discussion
mdrammeh
Helper III
9 years agoIF 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 ne...
- 9 years ago
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
dkay84_PowerBI
Microsoft Employee
9 years agoThe syntax for date values in Power Query is #date(year,month,day).
Thus, your if then statement would say if [Date] <= #date(2017,6,1) then ...
Thus, your if then statement would say if [Date] <= #date(2017,6,1) then ...
Phil_Seamark
Microsoft Employee
9 years agoAgreed, the Syntax of your IF statement is good.
Here is a nice breakdown on the subtle differences betwen the Excel IF and the Power BI IF
http://www.excelguru.ca/blog/2014/08/27/the-if-function-in-power-query/