We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
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
Solved! Go to Solution.
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"
)
Proud to be a Super User!
On how to ask a technical question, if you really want an answer (courtesy of SQLBI)
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.
Proud to be a Super User!
On how to ask a technical question, if you really want an answer (courtesy of SQLBI)
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"
)
Proud to be a Super User!
On how to ask a technical question, if you really want an answer (courtesy of SQLBI)
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.
Proud to be a Super User!
On how to ask a technical question, if you really want an answer (courtesy of SQLBI)
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 57 | |
| 38 | |
| 32 | |
| 18 | |
| 16 |
| User | Count |
|---|---|
| 66 | |
| 66 | |
| 39 | |
| 34 | |
| 25 |