Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

Reply
Anonymous
Not applicable

Nested IF with Dates

Hi Trying to get quick answer my apologies. Have three dates, ClosedDate, HireDate., OpenDate

 

I need to create a column where if ClosedDate is null then "Open" or if Open date is before today then open or if hire date is after today then open else everything else "Closed".

 

Thanks in advance.  And side note how do i put in today date in Power Query. 

 

1 ACCEPTED SOLUTION

@Anonymous 

 

No problem, try this instead with the conditions declared more explicitly:

if [ClosedDate] = null then "Open"
else if [OpenDate] < Date.Today then "Open"
else if [HireDate] > Date.Today then "Open"
else "Closed"

 

As before, if you didn't declare the Date.Today variable, you can swap 'Date.Today' in the above for 'Date.From(DateTime.LocalNow())'.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

3 REPLIES 3
BA_Pete
Super User
Super User

Hi @Anonymous ,

 

To have today's date easily accessible to your query, you can just add a line within your query (using Advanced Editor) like this:

Date.Today = Date.From(DateTime.LocalNow()),

 

Once you have this, you would create your new column like this:

if [ClosedDate] = null or [OpenDate] < Date.Today or [HireDate] > Date.Today then "Open"
else "Closed"

 

You could, of course, not bother declaring the Date.Today line, and just replace it in the above with Date.From(DateTime.LocalNow()).

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Anonymous
Not applicable

Thanks Pete, I am following, I may need help with logic because it shows when my opendate is after today  it shows open but I need it to say closed

@Anonymous 

 

No problem, try this instead with the conditions declared more explicitly:

if [ClosedDate] = null then "Open"
else if [OpenDate] < Date.Today then "Open"
else if [HireDate] > Date.Today then "Open"
else "Closed"

 

As before, if you didn't declare the Date.Today variable, you can swap 'Date.Today' in the above for 'Date.From(DateTime.LocalNow())'.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.