Forum Discussion
Need help with an If statement
I have a matrix, and for one of the columns I would like to use either of two fields, whichever is not blank. Is there a way to do that?
- Anonymous1 year ago
Hi Rnaval ,
Thanks for reaching out to the Microsoft Fabric Community.
Since you're working with a matrix visual and want to show the value from either Field1 or Field2 (whichever is not blank), the approach shared by pankajnamekar25 is correct and best suited for this scenario.
You can use the following measure:
Display Value = COALESCE( SELECTEDVALUE(Table[Field1]), SELECTEDVALUE(Table[Field2]) )To use this:
- Go to Modeling > New Measure, paste the formula, and add the measure to your matrix.
This will display Field1 when available, and fall back to Field2 when it’s blank exactly as intended.
If this post helps, then please give us Kudos and consider Accept it as a solution to help the other members find it more quickly.
Thankyou.
7 Replies
- pankajnamekar25Super User
Hello Rnaval
use below code dax
Display Value =
COALESCE(
SELECTEDVALUE(Table[Field1]),
SELECTEDVALUE(Table[Field2])
)Thanks,
Pankaj Namekar | LinkedInIf this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.
- RnavalPost Partisan
Where would I enter this code?
- bhanu_gautamSuper User
You can create a new column with the following DAX formula:
NewColumn = IF(NOT(ISBLANK([Field1])), [Field1], [Field2])
- RnavalPost Partisan
I get an error message regarding the "IF" expression
- AnonymousNot applicable
Hi Rnaval ,
Thanks for reaching out to the Microsoft Fabric Community.
Since you're working with a matrix visual and want to show the value from either Field1 or Field2 (whichever is not blank), the approach shared by pankajnamekar25 is correct and best suited for this scenario.
You can use the following measure:
Display Value = COALESCE( SELECTEDVALUE(Table[Field1]), SELECTEDVALUE(Table[Field2]) )To use this:
- Go to Modeling > New Measure, paste the formula, and add the measure to your matrix.
This will display Field1 when available, and fall back to Field2 when it’s blank exactly as intended.
If this post helps, then please give us Kudos and consider Accept it as a solution to help the other members find it more quickly.
Thankyou.