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
rosamhernandez1
Regular Visitor

Help with Switch Error

Working on getting a traffic light set up, have a column set up to determine the date difference between two dates. Now need to convert that number into a color, this is what I had set up but getting error message. ("DAX comparison operations do not support comparing values of type Text with values of type Integer. Consider using the VALUE or FORMAT function to convert one of the values.")

 

This is the data: 

Project NameApproved ISDProjected ISDSchedNumDaysSchedHealth
112/31/202512/31/20250Green
2 2/28/2025 Green
33/31/20253/31/2026365Red
49/30/20259/30/20250Green
53/31/20263/31/20260Green
6 12/31/2026 Green
79/30/20259/30/20250Green
812/31/20242/15/202546Yellow
99/30/20259/30/20250Green
1012/31/202412/31/20240Green
119/30/20259/30/20250Green
12 12/31/2026 Green
13 3/1/2027 Green
148/30/20241/21/2025144Red
159/30/20249/30/20240Green
 
and here is my SWITCH statement:
SchedHealth = SWITCH(True(),
'Active Projects'[SchedNumDays]="","Green",
'Active Projects'[SchedNumDays]>90,"Red",
'Active Projects'[SchedNumDays]<=0,"Green",
'Active Projects'[SchedNumDays]<90,"Yellow")
1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

I'm confused by the first sentence.

It looks to me that you want to treat it as a number, so it should be a number datatype.  However, the error is caused by using two different types of comparison: one string comparison and one number comparison.

'Active Projects'[SchedNumDays] = ""
'Active Projects'[SchedNumDays] > 90

--

I think if I was you I would convert the datatype to number and alter the switch statement to test for BLANK or null or whatever these empty values get converted to.

View solution in original post

6 REPLIES 6
HotChilli
Super User
Super User

I'm confused by the first sentence.

It looks to me that you want to treat it as a number, so it should be a number datatype.  However, the error is caused by using two different types of comparison: one string comparison and one number comparison.

'Active Projects'[SchedNumDays] = ""
'Active Projects'[SchedNumDays] > 90

--

I think if I was you I would convert the datatype to number and alter the switch statement to test for BLANK or null or whatever these empty values get converted to.

thank you! that worked, apologies on being confusing. 

HotChilli
Super User
Super User

I'm talking about the DAX code. There is a difference on one of the comparison cases.

The error message is giving you the solution to deal with it.

got it, the column was not created with the incoming data so I can't find it in the query. I have to recreate the columns in the query so that I can set them to the correct data type, correct?

HotChilli
Super User
Super User

Look at the values you are comparing in each case. Are they the same datatype or are they different datatypes?

both columns are Text data type

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.