We are exposing header to community/ideas via header endpoint which are on different UI frameworks -->
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 new column to capture all DT_SCHED (date field) prior to June 1, 2017 and return a "Delivery Date of June 1st" and if the DT_SCHED date is greater than June 1st but less than December 31st, I want my IF statement to return "December 1st" delivery date.
Could anyone help me figure this out? I don't have the Power Query Add-In to do a conditional lookup but have attached a screenshot with my first attempt but apparently the formula is VERY WRONG
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
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
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}
Power BI Monthly Update - November 2023
Check out the November 2023 Power BI update to learn about new features.
Fabric Community News unified experience
Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.
The largest Power BI and Fabric virtual conference
130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.
We are exposing header to community/ideas via header endpoint which are on different UI frameworks -->