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.
Is there any other easy way to write the following DAX expression...
EthnicitySummarised:=
IF (
FIND ( "Asian", [Ethnicity], 1, BLANK () ),
"Asian",
IF (
FIND ( "Black", [Ethnicity], 1, BLANK () ),
"Black",
IF (
FIND ( "White", [Ethnicity], 1, BLANK () ),
"White",
IF (
FIND ( "Unknown", [Ethnicity], 1, BLANK () ),
"Unknown",
IF ( FIND ( "Chinese", [Ethnicity], 1, BLANK () ), "Chinese", "Other" )
)
)
)
)
Solved! Go to Solution.
@zaforir2002, I think you can make it more clean by using Switch and Search. Search is also case insensitive and I think is a better approach.
Ethnicitycol= switch(
TRUE(),
SEARCH("ASIAN",'Sheet3'[ETHNICITY],1,blank())>0,"ASIAN",
SEARCH("LATINO",'Sheet3'[ETHNICITY],1,blank())>0, "LATINO",
"UNKN0WN"
)
@zaforir2002, I think you can make it more clean by using Switch and Search. Search is also case insensitive and I think is a better approach.
Ethnicitycol= switch(
TRUE(),
SEARCH("ASIAN",'Sheet3'[ETHNICITY],1,blank())>0,"ASIAN",
SEARCH("LATINO",'Sheet3'[ETHNICITY],1,blank())>0, "LATINO",
"UNKN0WN"
)
Hi @zaforir2002, it looks like you are trying to return the [Ethnicity] value if it's part of a certain subset of values, and classify anything outside that subsite as "Other". If that's accurate, then you could use the IN operator:
EthnicitySummarised = IF([Ethnicity] IN {"Asian","Black","White","Unknown","Chinese"}, [Ethnicity], "Other")
Hope that helps! 🙂
I'm wondering the FIND function is being used because he is looking for the existance of that text within a longer string. I think the IN function needs an exact match. Just need @zaforir2002 to confirm.
Did you tried adding conditional column? In that case you don't need to write DAX and it is much cleaner and not messy, as you mentioned.
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Other though, why not add conditional column rather than writing DAX?
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
When I said add conditional column, i mean to add in Power BI using "Edit Queries".
- Click Edit Queries
- Goto Add Columns Tab
- There is option called "Conditional Column" and this is what I'm talking about.
Thanks,
P
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Aha , that make sense, thanks for clarifying. I believe in that case your expression seems to be the way to go.
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
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 |
---|---|
112 | |
97 | |
85 | |
67 | |
59 |
User | Count |
---|---|
150 | |
120 | |
100 | |
87 | |
68 |