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
When working with conditional logic in Power Query, the IF statement is essential for transforming and categorizing data based on specific criteria. In your case, where you need to create a new column that assigns a “Delivery Date of June 1st” for all DT_SCHED values before June 1, 2017, and a “Delivery Date of December 1st” for those between June 1 and December 31, you can use the Add Column feature in Power Query and enter 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 checks each date value and assigns the correct delivery date accordingly. Power Query’s M language handles these conditions efficiently, even with millions of records, ensuring that your dataset remains consistent and automated without the need for manual filtering or Excel formulas. desi cinema