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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Kumar_0606
Regular Visitor

How to create Calculated column with both Text and Number comparison

Hello Experts, 

I have a formula like this

IF [Category]='Plan' THEN

IF [year]>=2020 AND [Code]= 'USD123' THEN [Measure]
ELSE

IF [year]<2020 AND [Code]='USD456'

THEN [Measure]
END

END


I tried using IF statement but getting the error " DAX comparison operations do not support comparing values of type text with values of type integer"

Any help would be greatly appreciated.

 

Thanks

 

 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @Kumar_0606 

 

Since you are using several IF the best option is to use a switch statment however your problem saying the it does not allow to compare values it seems to me that one of those columns has the incorrect format, check the format of the Year ccolumn to see if it's a number and try the following measure:

 

SWITCH( TRUE(),
Table[Category]="Plan"  && Table[year]>=2020 && Table[Code]= 'USD123', [Measure],
Table[Category]="Plan"  && Table[year]<2020 && [Code]='USD456', [Measure])

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

3 REPLIES 3
MFelix
Super User
Super User

Hi @Kumar_0606 

 

Since you are using several IF the best option is to use a switch statment however your problem saying the it does not allow to compare values it seems to me that one of those columns has the incorrect format, check the format of the Year ccolumn to see if it's a number and try the following measure:

 

SWITCH( TRUE(),
Table[Category]="Plan"  && Table[year]>=2020 && Table[Code]= 'USD123', [Measure],
Table[Category]="Plan"  && Table[year]<2020 && [Code]='USD456', [Measure])

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Thanks Miguel.

I checked the year column, data type is Text so i enclosed year value in quotes in your formula.

Hi @Kumar_0606 ,

 

Glad it worked, but I suggest that you change the year column to a Number format because it will be more efficient.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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