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.
Hi all,
I am trying to figure out a simple DAX with multiple conditions:
If [Column] contains "This1" then "That1" elseif [Column] contains "This2" then "That2" elseif [Column] contains "This3" then "That3" else null
I know that this could easily be done with conditional or custom column, but for now I need to do it with DAX. Any suggestions How this could be done?
BR,
Jere
Hi @VahidDM & @Tanushree_Kapse
What I meant, is that "This1" is included in the column. For instance, if a column value is "This1is", DAX will return "That1". Similarly, if the value is "This1isnot" it will still return "That1", because the value CONTAINS "This1"
That is what I meant with CONTAINS, not equals (=).
Any suggestions?
Can you share a sample of your table after removing sensitive data here?
Appreciate your Kudo!!
Hi @VahidDM
The table looks similar to this:
The "Country" Column is the one that I am trying to build with DAX. So when [Name] CONTAINS "FIN", it returns "Finland". Same goes with "GER", "Germany" & "RUS", "Russia".
Try this measure :
Country =
VAR _A =
MAX ( 'Table'[Name] )
RETURN
IF (
LEFT ( _A, 3 ) = "FIN",
"Finland",
IF (
LEFT ( _A, 3 ) = "GER",
"Germany",
IF ( LEFT ( _A, 3 ) = "RUS", "Russia", BLANK () )
)
)
Output:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos✌️!!
This worked well! Thanks a lot.
Is there a way to apply similar solution to DAX column? This works in a DAX measure but if I want to use this as a slicer, it must be as a DAX column since DAX measures cannot be used as a slicer.
Try this measure with IF:
Measure =
IF (
[Column] = "This1",
"That1",
IF ( [Column] = "This2", "That2", IF ( [Column] = "This3", "That3", BLANK () ) )
)
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos✌️!!
Hi @jereaallikko ,
Try this DAX:
Measure= IF([Column]="This1","That",IF([Column]="This2","That2",IF([Column]="This3","That3")), BLANK())
Mark this as a solution, if I answered your question.
Kudos are always appreciated.
Thanks!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
47 | |
26 | |
19 | |
14 | |
10 |
User | Count |
---|---|
57 | |
49 | |
44 | |
18 | |
18 |