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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
myti
Helper II
Helper II

Date format problem

Dear Experts,

 

I have a calculated Measure which is  an output in Date format like 1/1/2017. Once I want to use this output in if condition I can not get the correct answer and "if condition" can not recognise it.I dont know how I may have both in the same format to compre them in a if conditon. my current if condition is as below: I expect that the below formulah return 1 once Measure=1/1/2017.however it doesnt recognise them as equal and return 0. any idea how I can fix it?

 

CalculatedColumn=IF([Measure]=DATE(2017,1,1),1,0 )

 

Thank you,

Best Regards

Mehdi

10 REPLIES 10
JoHo_BI
Responsive Resident
Responsive Resident

Hi Myti,

 

Try converting your measure to a date too, such as:

 

CalculatedColumn=IF(DATE(YEAR([Measure]), MONTH([Measure]), DAY([Measure]))=DATE(2017,1,1),1,0

 

Hope that helps!

Hey @JoHo_BI,

 

Thank you for your response.However,It did not work!

JoHo_BI
Responsive Resident
Responsive Resident

Hi @myti,

 

What didn't work about it? What responses/errors did it give? 

I dont receive any error,I dont recieve the answer that is expected. I supposed to receive 1 instead of 0  for column_test. Means that the formulah does not work.

 

Untitled.jpg

Can you please add 3 test columns to your table (to be deleted later)

 

My Year Col = YEAR([Measure])

My Month Col = MONTH([Measure])

My Day Col = DAY([Measure]) 

Just to see if these values are what you would expect


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

@Phil_Seamark

 

I added 3 columns as you mentioned. Unfortunetly, the results for all variables is nan.!

@myti you mentioned it is a calculated measures which is date type?

 

What formula you are using for this calculated measures? 

What is your data source?

What is data type of this new measure?

 

Also as @Phil_Seamark mentioned, create those fields to see what value you are getting?

 

Can you also try this following, assuming your locale setting for date is MM/DD/YYYY, just wondering if your measure is text type and following formula will convert date to text for comparison purpose.

 

CalculatedColumn=IF([Measure]=FORMAT(DATE(2017,1,1), "MM/DD/YYYY"),1,0)

 

Although there are many unknown, once we have reply on above question, it will help to resolve the issue.

 

Thanks,

Parv



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi @parry2k

 

I receive the value for  calculated measure based on the below formula.It get the current value of page level filter which is based on the date format.

Measure = If ( HasOneValue('landing-pages'[ipg:month]) , Values ('landing-pages'[ipg:month]))

 

 

I tried your formulah but I recived error ("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.")

 

Hopefully my information is good enough to find  a solution.

 

Thank you,

Myti

@myti

 

Make sure your [Measure] returns date type. As I tested, it supposes to work with your original formula.

 

6.PNG

 

Regards,

Try this:

 

Measure = If ( HasOneValue('landing-pages'[ipg:month]) , Values ('landing-pages'[ipg:month]), BLANK())

CalculatedColumn=IF([Measure]=BLANK() ||[Measure]<>DATE(2017,1,1),0,1 )

Assuming ipg:month is data type, as @v-sihou-msft suggested, make sure your measure data type is also Date



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.