Forum Discussion
IF Statement using Power Query
- 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
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
- Phil_Seamark9 years ago
Microsoft Employee
Perhaps the millions of rows are in Power Pivot??
In anycase, if you have millions of rows, perhaps it's a good time to get a database. :)
- DMPBR6 years agoFrequent Visitor
I signed up purely to give you kudos for this bit:
MarcelBeug wrote:PQ is case sensitive and if...then...else is all lower case, just like null.
My logic was right but turns out I had capitalised the THEN statement which threw an unexpected tag error.
- mdrammeh9 years ago
Helper III
I miss spoke Marcel. It's the database that has millions of queries and that's where am going in to filter by date range. You filter worked perfectly. THANK YOU, YOU GUYS ARE AWESOME!!
- Mo_157972 years agoFrequent Visitor
Hello, how can I use the IF function to return the value of column X if date in Column X is greater than Column Y, and if it's not greater for it to return the value of Column Y.
Thanks,