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
Anonymous
Not applicable

How to code this in DAX

Hi all, 

 

I am trying to code below in DAX, can someone please help !

 

CASE

WHEN MMIT_MEDICAL.is ='1' AND MMIT_MEDICAL.pa = '0' AND MMIT_MEDICAL.st = '0' THEN 'Covered'

   WHEN MMIT_MEDICAL.is ='1' AND (MMIT_MEDICAL.pa <> '0' OR MMIT_MEDICAL.st <> '0') THEN 'Covere(PA/ST)'

   WHEN (MMIT_MEDICAL.is = '0') THEN 'Not Covered'

     ELSE 'Unknown'

END

 

 

2 ACCEPTED SOLUTIONS
dm-p
Super User
Super User

Something like the following should work (assuming columns in your data model are the same as SQL):

 

SWITCH (
    TRUE (),
    'MMIT_MEDICAL'[is] = "1"
        && 'MMIT_MEDICAL'[pa] = "0"
        && 'MMIT_MEDICAL'[st] = "0", "Covered",
    'MMIT_MEDICAL'[is] = "1"
        && ( 
'MMIT_MEDICAL'[pa] <> "0" || 'MMIT_MEDICAL'[st] <> "0"
), "Covere(PA/ST)", "Unknown" )




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

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




View solution in original post

Hi @Anonymous - as you were using single quotes around your values in your SQL, I assumed you had the same requirement in Power BI, i.e. your fields were text-based. Having seen your error, I suspect that they are being treated as numbers in your data model.

I have amended the formula to treat as numbers (removing the quotation marks around the numbers when comparing). Can you please try the amended one below and see if that works?

SWITCH (
    TRUE (),
    'MMIT_MEDICAL'[is] = 1
        && 'MMIT_MEDICAL'[pa] = 0
        && 'MMIT_MEDICAL'[st] = 0, "Covered",
    'MMIT_MEDICAL'[is] = 1
        && ( 
                'MMIT_MEDICAL'[pa] <> 0
             || 'MMIT_MEDICAL'[st] <> 0 
        ), "Covere(PA/ST)",
    "Unknown"
)

If this doesn't work, then please provide some more information about the fields you're using in this calculation, e.g. data types and we'll see where we can go from there.





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

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




View solution in original post

3 REPLIES 3
dm-p
Super User
Super User

Something like the following should work (assuming columns in your data model are the same as SQL):

 

SWITCH (
    TRUE (),
    'MMIT_MEDICAL'[is] = "1"
        && 'MMIT_MEDICAL'[pa] = "0"
        && 'MMIT_MEDICAL'[st] = "0", "Covered",
    'MMIT_MEDICAL'[is] = "1"
        && ( 
'MMIT_MEDICAL'[pa] <> "0" || 'MMIT_MEDICAL'[st] <> "0"
), "Covere(PA/ST)", "Unknown" )




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

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Anonymous
Not applicable

hi @dm-p

 

I am getting this error when i using the code - 

 

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.

 

What do you suggest ?

Hi @Anonymous - as you were using single quotes around your values in your SQL, I assumed you had the same requirement in Power BI, i.e. your fields were text-based. Having seen your error, I suspect that they are being treated as numbers in your data model.

I have amended the formula to treat as numbers (removing the quotation marks around the numbers when comparing). Can you please try the amended one below and see if that works?

SWITCH (
    TRUE (),
    'MMIT_MEDICAL'[is] = 1
        && 'MMIT_MEDICAL'[pa] = 0
        && 'MMIT_MEDICAL'[st] = 0, "Covered",
    'MMIT_MEDICAL'[is] = 1
        && ( 
                'MMIT_MEDICAL'[pa] <> 0
             || 'MMIT_MEDICAL'[st] <> 0 
        ), "Covere(PA/ST)",
    "Unknown"
)

If this doesn't work, then please provide some more information about the fields you're using in this calculation, e.g. data types and we'll see where we can go from there.





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

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




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.