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

Conditional If in DAX didnt work

Hi, 

I am trying to group staff's tenure into 5 main categories : Less than 1 year, Between 1 and 3 years, Between 3 and 5 years and Between 5 and 10 years. To do this, I created a new column and came up with the following DAX formula 

Tenure (Cat.) = if(Stafflist[Tenure]>10,"More than 10 yrs",if(Stafflist[Tenure]>5,"Between 5 and 10 yrs",if(Stafflist[Tenure]>3,"Between 3 and 5 yrs",if(Stafflist[Tenure]>1,"Between 1 and 3 yrs","Less than 1 yr")))) . The formula resulted in the following 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."  Can anyone decode what this error message means and how can I resolve the issue? 
 
 
 
 
4 REPLIES 4
lbendlin
Super User
Super User

Independent of the other replies - check out the SWITCH(TRUE()) syntax sugar that makes your nested IF statements look a bit better

 

SWITCH(TRUE(),Stafflist[Tenure]>10,"More than 10 yrs",Stafflist[Tenure]>5,"Between 5 and 10 yrs",Stafflist[Tenure]>3,"Between 3 and 5 yrs",Stafflist[Tenure]>1,"Between 1 and 3 yrs","Less than 1 yr")

harshnathani
Community Champion
Community Champion

Hi @pauline_teo  ,

 

 

Please check format of Stafflist [Tenure]. 

 

Change it from text to Whole Number.

 

 

1.jpg

 

 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

 

 

Got it. Thanks! 

avatorl
Impactful Individual
Impactful Individual

@pauline_teo 

The message means what it says. You're comparing text value with numeric value. And because all comparisions in your DAX are similar Stafflist[Tenure]>{numeric value}, then the only place in a comparison where for a text value is Stafflist[Tenure] field. Verify the Stafflist[Tenure] column and make sure you changed it's data type to Whole number.



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.

Top Solution Authors