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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Dan27
Regular Visitor

Comparing two dates when one field is text and the other a date

Hello

 

I'm hoping someone can help. In my data I've got two different fields. An opened date and a closed date. My opened date always contains an date so the format is date. The closed date doesn't always contain a closed date so may sometimes contain "NULL".

 

This field is then formatted as text and when I try to work out the difference between the 2 dates I get an error.

 

As this is the way the dat pulls through from the source data I'd ideally not like to have to replace blanks etc.. within PowerBI but put it in the formula.

 

I want to write =IF(opened_date)=(closed_date),1,0)

 

Please help

 

Thanks

4 REPLIES 4
v-micsh-msft
Employee
Employee

For the NUll, we have a function IsBlank() could be used.

You could first check if the closed date is blank first.

The formula should be changed as below:

IF(Or(!(opened_date)=(closed_date), IsBlank(closed_date)),0,1)

Regards,

Michael

Thanks Michael, however when I try this I still get the error below

 

The syntax for '!' is incorrect. (DAX(IF(Or(!(opened_date)=(closed_date), IsBlank(closed_date)),0,1))).

My bad.

 

Try the following:

IF(Or(not((opened_date)=(closed_date)), IsBlank(closed_date)),0,1)

Regards,

Michael

Thanks Michael. That cleared that error but I still get the following:

 

DAX comparison operations do not support comparing values of type Date with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.