Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Hi Everyone
I am trying to create a conditional column that checks a number of criteria and, depending on the answer to those queries, gives a result.
To give some info, I have a table containing [column A] and [column B]. I need to ask these if statements:
If [column A] equals "1" or "2" or "3" or "4" and [column B] equals "X" or "Y" I want it to return "OK"
If [column A] equals "1" or "2" or "3" or "4" and [column B] does not equal "X" or "Y" I want it to return "Check".
If [column A] does not equal "1" or "2" or "3" or "4" and [column B] does not equal "X" or "Y" I want it to return "OK"
If [column A] does not equal "1" or "2" or "3" or "4" and [column b] equals "X", or "Y" I want it to return "Check"
I have tried various IF statements with a mixture of && or || but none seem to yield the desired result. I have two questions:
1) Is it possible?
2) How is the best way to do it, without creating other conditional columns before hand?
Solved! Go to Solution.
Hi @JamesBockett ,
You could use " in {1,2,3,4} " instead of using multiple equals.
For example:
column = IF(
([columnA] in {1,2,3,4}&&[columnB] in {"x","y"}) || ([columnA] not in {1,2,3,4}&&[columnB] not in {"x","y"}),
"OK",
if(
([columnA] in {1,2,3,4}&&[columnB] not in {"x","y"}) || ([columnA] not in {1,2,3,4}&&[columnB] in {"x","y"}),
"check") )
Or you could use switch() function.
Switch(true(), conditon, value, conditon, value)
Best Regards,
Jay
Hi @JamesBockett ,
You could use " in {1,2,3,4} " instead of using multiple equals.
For example:
column = IF(
([columnA] in {1,2,3,4}&&[columnB] in {"x","y"}) || ([columnA] not in {1,2,3,4}&&[columnB] not in {"x","y"}),
"OK",
if(
([columnA] in {1,2,3,4}&&[columnB] not in {"x","y"}) || ([columnA] not in {1,2,3,4}&&[columnB] in {"x","y"}),
"check") )
Or you could use switch() function.
Switch(true(), conditon, value, conditon, value)
Best Regards,
Jay
Hi @v-jayw-msft
The in function worked although, not in wasn't a supported operator. Instead, I used
column = IF(
([columnA] in {1,2,3,4}&&[columnB] in {"x","y"}) || not([columnA] in {1,2,3,4}not[columnB] in {"x","y"}),
"OK",
if(
([columnA] in {1,2,3,4}&¬[columnB] in {"x","y"}) || not([columnA] in {1,2,3,4}&&[columnB] in {"x","y"}),
"check") )
Looks like it has had the desired effect though, thanks for your support.
Hi @JamesBockett ,
Can you share what logic you have used in Power BI which is not working?
Thanks,
Pragati
Hi @Pragati11
I've tried a few but to give you an idea, I have tried:
I don't know if it helps but, values 1, 2, 3 and 4 are a variation of the same value. so 1 is "1-a", 2 is "1-b", 3 is "1-c", 3 is "1-d". Values "X" and "Y" are actual X is blank and Y is "NONE"
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
94 | |
92 | |
83 | |
71 | |
49 |
User | Count |
---|---|
143 | |
120 | |
111 | |
59 | |
57 |