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
Rup10
Resolver I
Resolver I

Help with switch case

Hi,

 

I have to add one custom column called "different" by using switch case as below : 

CASE

WHEN (diff <= 5) and (diff >= -5) THEN 'direct offset'

WHEN diff < -5 THEN 'overpay offset'

END

I tried below switch case but it is showing error as "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".

Switch case : 

different = SWITCH( TRUE(),

AND([diff] <= -5 , [diff] >= -5 ), "directoffset",
[diff] < -5 ,"overpayoffset"
)

Can someone please help me with this.

Thank you.

1 ACCEPTED SOLUTION
dedelman_clng
Community Champion
Community Champion

Hi @Rup10  - the most likely culprit is that [diff] is formatted as text. Change it to some number format either in Transform Data or in the model itself and it ought to work.

 

(Side note, and this is probably just an error in typing the post, but your first option on switch has "-5" on both inequalities)

 

Hope this helps

David

View solution in original post

3 REPLIES 3
speedramps
Super User
Super User

Please consider this solution and leave kudos

 

Look at the message "DAX comparison operations do not support comparing values of type Text with values of type Integer."

This suggests that [diff] is text.   

 

If [diff] is a column in your query then change the data type from text to numeric>

 

If [diff] is a measure then you can covert it to a number

 

diff_number =
var diff_text = "-5"
RETURN
CONVERT(text1, INTEGER)

 

dedelman_clng
Community Champion
Community Champion

Hi @Rup10  - the most likely culprit is that [diff] is formatted as text. Change it to some number format either in Transform Data or in the model itself and it ought to work.

 

(Side note, and this is probably just an error in typing the post, but your first option on switch has "-5" on both inequalities)

 

Hope this helps

David

Hi @dedelman_clng ,

Thank you so much.It helped me alot.

 

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.