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
MarcelBeug​ When utilizing conditional logic in Power Query, the IF statement plays a crucial role in transforming and categorizing data according to defined criteria. In your scenario, where it is necessary to generate a new column that designates a 'Delivery Date of June 1st' for all DT_SCHED values prior to June 1, 2017, and a 'Delivery Date of December 1st' for those falling between June 1 and December 31, you can employ the Add Column feature in Power Query and input a custom formula such as: = if [DT_SCHED] < #date(2017,6,1) then #date(2017,6,1) else if [DT_SCHED] <= #date(2017,12,31) then #date(2017,12,1) else null. This formula evaluates each date value and assigns the appropriate delivery date accordingly. Power Query's M language efficiently manages these conditions, even with extensive datasets, ensuring that your data remains consistent and automated without requiring manual filtering or Excel formulas.