cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
myti Regular Visitor
Regular Visitor

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 Member
Member

Re: Date format problem

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!

myti Regular Visitor
Regular Visitor

Re: Date format problem

Hey @JoHo_BI,

 

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

JoHo_BI Member
Member

Re: Date format problem

Hi @myti,

 

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

myti Regular Visitor
Regular Visitor

Re: Date format problem

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

Phil_Seamark Super Contributor
Super Contributor

Re: Date format problem

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!

Super User
Super User

Re: Date format problem

@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





Did I answer your question? Mark my post as a solution.

Proud to be a Datanaut! Kudos Help Smiley Happy
Connect with me on Linkedin. Feel free to email me with any of your BI needs.




 




myti Regular Visitor
Regular Visitor

Re: Date format problem

@Phil_Seamark

 

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

myti Regular Visitor
Regular Visitor

Re: Date format problem

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

Moderator v-sihou-msft
Moderator

Re: Date format problem

@myti

 

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

 

6.PNG

 

Regards,