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
Sean,
Thanks for pointing this out. It seems like it's going to help me but how can I do an AND or an OR to combine conditions? It looks like it only accepts one rule at a time. I'm trying to do something like:
IF <condition1> AND <condition2> THEN <result> ELSE <alternate result>
I hope I don't need to resort to creating multiple conditional columns.
Thanks,
Marcos
hi , when i am trying to get two conditions using and function its throwing an error
- dkay84_PowerBI8 years ago
Microsoft Employee
example:
if 'table'[field] = {condition1} or 'table'[field] = {condition2} then {output1} else {output2}
You can replace the "or" with "and" depending on your logic. Obviously your conditions don't have to be based on "=" either.
Also you can nest ifs:
example:
if 'table'[field] = {condition1} then if 'table'[field] = {condition2} then {output1} else {output2} else {output3}