This is best Fabric, Power BI, SQL and AI community event. How do we know? The last event sold out! Save €200 with code FABCMTY200.
Register nowA new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.
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.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 33 | |
| 25 | |
| 23 | |
| 20 | |
| 15 |
| User | Count |
|---|---|
| 64 | |
| 41 | |
| 27 | |
| 22 | |
| 22 |