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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Kyle_Wolfe_Ohio
Regular Visitor

CASE WHEN Statement Using DAX Comparing a Text AND Number Column

Good morning:
 
I am trying to create a visual that will display the probationary period length for all new starts at my organization.  As you can imagine with multiple labor unions, promotions, demotions, lateral transfers, new hires to the agency, etc. there are quite a few sceanrios. 
 
Furthermore, my comparisons use the future and previous bargaining unit text column and future and previous pay range number.  I am thinking SWITCH would work, but getting an error saying, "DAX comparison operations do not support comparing values of type Integer with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values."  Also, I am not sure if the NULL for new hires is done correctly (I just need new hires to be 365 days)
 
Here is what I am trying to do (NOTE I WILL HAVE A FEW MORE ADDED AT THE END, but this will suffice):
 
 
SWITCH STMT =
SWITCH(TRUE(),
    'New Hire Orientation Dash Dataset'[Previous Pay Range] is null, "365",
    'New Hire Orientation Dash Dataset'[Future Labor Union] = "A" && 'New Hire Orientation Dash Dataset'[Future Pay Range] > 'New Hire Orientation Dash Dataset'[Previous Pay Range], "180",
    'New Hire Orientation Dash Dataset'[Future Labor Union] = "B" && 'New Hire Orientation Dash Dataset'[Future Pay Range] > 'New Hire Orientation Dash Dataset'[Previous Pay Range], "180",
    'New Hire Orientation Dash Dataset'[Future Labor Union] = "C" && 'New Hire Orientation Dash Dataset'[Future Pay Range] > 'New Hire Orientation Dash Dataset'[Previous Pay Range] &&
                'New Hire Orientation Dash Dataset' [Future Pay Range] = 1-7, "120",
    'New Hire Orientation Dash Dataset'[Future Labor Union] = "C" && 'New Hire Orientation Dash Dataset'[Future Pay Range] > 'New Hire Orientation Dash Dataset'[Previous Pay Range] &&
                'New Hire Orientation Dash Dataset' [Future Pay Range] = 23-28, "120",
    'New Hire Orientation Dash Dataset'[Future Labor Union] = "C" && 'New Hire Orientation Dash Dataset'[Future Pay Range] > 'New Hire Orientation Dash Dataset'[Previous Pay Range] &&
                'New Hire Orientation Dash Dataset' [Future Pay Range] = 8-12, "180",
    'New Hire Orientation Dash Dataset'[Future Labor Union] = "C" && 'New Hire Orientation Dash Dataset'[Future Pay Range] > 'New Hire Orientation Dash Dataset'[Previous Pay Range] &&
                'New Hire Orientation Dash Dataset' [Future Pay Range] = 29-36, "180",
    "Look Up in Application")
2 ACCEPTED SOLUTIONS
some_bih
Super User
Super User

Hi @Kyle_Wolfe_Ohio DAX function SWITCH has some remarks, one of them is 

  • All result expressions and the else expression must be of the same data type

 as seems your expression part is not single column (rather multiple columns: 'New Hire Orientation Dash Dataset'[Previous Pay Range], 'New Hire Orientation Dash Dataset'[Future Labor Union]...)

So basically, you should rework your calculation logic for this case, try with multiple IF as your input for SWITCH have different data type.

Link for documentation.





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

Proud to be a Super User!






View solution in original post

v-zhouwen-msft
Community Support
Community Support

Hi @some_bih ,thanks for the quick reply, I'll add further.

Hi @Kyle_Wolfe_Ohio ,

Something like this?

vzhouwenmsft_0-1716444909796.png

The data type of the field 'pay range' should be Text.

vzhouwenmsft_1-1716445007712.png

Try modifying your expression:

vzhouwenmsft_2-1716445092324.png

 

View solution in original post

2 REPLIES 2
v-zhouwen-msft
Community Support
Community Support

Hi @some_bih ,thanks for the quick reply, I'll add further.

Hi @Kyle_Wolfe_Ohio ,

Something like this?

vzhouwenmsft_0-1716444909796.png

The data type of the field 'pay range' should be Text.

vzhouwenmsft_1-1716445007712.png

Try modifying your expression:

vzhouwenmsft_2-1716445092324.png

 

some_bih
Super User
Super User

Hi @Kyle_Wolfe_Ohio DAX function SWITCH has some remarks, one of them is 

  • All result expressions and the else expression must be of the same data type

 as seems your expression part is not single column (rather multiple columns: 'New Hire Orientation Dash Dataset'[Previous Pay Range], 'New Hire Orientation Dash Dataset'[Future Labor Union]...)

So basically, you should rework your calculation logic for this case, try with multiple IF as your input for SWITCH have different data type.

Link for documentation.





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

Proud to be a Super User!






Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.