Forum Discussion

deb_power123's avatar
deb_power123
Icon for Helper V rankHelper V
5 years ago
Solved

Getting DAX error: DAX doesn't support comparing values of type Text with type Date

Hi All,

 

I have a Student table with columns:-

StudentIDStudentNameAdmissionDateLastAttendanceDateDateLeftLocationStudenttype

I have a calendar table connected to student table by 1:n relation.

 

I want to exclude all the rows when the Maxiumum selected value of [Datescolumn of the calendar table]in the date slicer is greater than the Date Left column of the student Table.

 
My DAX measure is as below :-
Visual exclude =
IF(
SELECTEDVALUE('student'[DateLeft])<MAX('Calendar'[Dates]),
1,0
)
 
But when I select this DAX measure it resolves into an error message in powerBI desktop as below.
 
Expected output: This should show the flag set to 1 or 0 in the table matrix column for the "visual exclusion". I can then add this measure in the visual filter to remove all rows from table visualization which fall under the given condition.
 
My input data is as below :-
 
StudentIDStudentNameAdmissionDateLastAttendanceDateDateLeftLocationStudenttype
100Harry01-02-201010-05-2011 10:4501-06-2011LondonFullTime
101Sally01-02-201001-05-2011 16:45 LondonFullTime
103Mary01-02-201002-05-2011 12:45 LondonFullTime
104John01-02-201107-05-2011 09:4531-09-2011ParisFullTime
105Geeta01-04-201113-05-2011 12:45 AthensFullTime
106James01-02-201102-05-2011 12:45 AthensFullTime
107Marc01-02-201011-05-2011 12:4514-05-2011AthensPartTime
108Sam01-04-201102-05-2011 14:4502-10-2011TorontoPartTime
109Ravi01-04-201004-05-2011 12:45 TorontoPartTime
110Jose01-02-201108-05-2011 15:4503-08-2011TokyoFullTime
 
I used CALENDARAUTO() function for calendar table to generate date range :-
 

How can I modify the DAX to handle the above error-message or please suggest any other approach to achieve the expected output?
 
Appreciate for all your inputs.
 
Regards
Sameer
  • deb_power123 

    It looks like your field 'student'[DateLeft] is set as type text. Select the field in the fields bucket and under "Column Tools" in the ribbon, set the field type to type Date:

     

3 Replies

  • PaulDBrown's avatar
    PaulDBrown
    Icon for Community Champion rankCommunity Champion

    deb_power123 

    It looks like your field 'student'[DateLeft] is set as type text. Select the field in the fields bucket and under "Column Tools" in the ribbon, set the field type to type Date:

     

    • deb_power123's avatar
      deb_power123
      Icon for Helper V rankHelper V

      Thankyou, yes it was a miss from my end.It automatically became text, not sure how.The forumla now works fine

      • PaulDBrown's avatar
        PaulDBrown
        Icon for Community Champion rankCommunity Champion

        deb_power123 

        It was propably formatted as text in the import phase. Power Query has a habit of establishing field data types automatically, but doesn't always get it right.

        you can check by opening the query and checking the code in the "Changed type" step, and edit accordingly if need be)