Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
CLANG10
Helper I
Helper I

Write a DAX measure to look for specific text and return a specific value

How do i write a DAX Measure based on specific text in "car sales"column and return a desired value in the "region" column.

e.g. car sales containing italy, france, germany should all return europe in the region column. Thanks in advance 

CLANG10_0-1666256611285.png

 

2 ACCEPTED SOLUTIONS
speedramps
Community Champion
Community Champion

It is easy and best pratice to do it using Power Query

speedramps_0-1666257537963.png

 

 

It can also be done in DAX but is is much harder and slower ... much better to use Power Query

see

https://www.youtube.com/watch?v=Vc7A6WiwLwg

 

 https://community.powerbi.com/t5/DAX-Commands-and-Tips/DAX-extract-text-between-delimiter/m-p/119136...

 

 

Thanks for reaching out for help.

I put in a lot of effort to help you, now please quickly help me by giving kudos.

Remember we are unpaid volunteers and here to coach you with Power BI and DAX skills and techniques, not do the users job for them. So please click the thumbs up and accept as solution button. 

If you give someone a fish then you only give them one meal, but if you teach them how to fish then they can feed themselves and teach others for a lifetime.  I prefer to teach members on this forum techniques rather give full solutions and do their job. You can then adapt the technique for your solution, learn some DAX skills for next time and soon become a Power BI Super User like me. 

One question per ticket please. If you need to extend your request then please raise a new ticket.

You will get a quicker response and each volunteer solver will get the kudos they deserve. Thank you ! 

View solution in original post

JorgePinho
Solution Sage
Solution Sage

@CLANG10  is this going to scale? Like are you going to have more countries?
There is a simple way to do this in dax but you have to write each country individually. It would loke something like this:

 

SWITCH(TRUE(),
CONTAINSSTRING(Table[CAR SALES],"ITALY") || 
CONTAINSSTRING(Table[CAR SALES],"FRANCE") ||
CONTAINSSTRING(Table[CAR SALES],"GERMANY") ,"EUROPE",
CONTAINSSTRING(Table[CAR SALES],"CHINA") ||
CONTAINSSTRING(Table[CAR SALES],"INDIA") ||
CONTAINSSTRING(Table[CAR SALES],"SINGAPORE"), "ASIA",
CONTAINSSTRING(Table[CAR SALES],"USA") ||
CONTAINSSTRING(Table[CAR SALES],"CANADA"), "AMERICA",
"(ELSE VALUE)"
)

View solution in original post

6 REPLIES 6
JorgePinho
Solution Sage
Solution Sage

@CLANG10  is this going to scale? Like are you going to have more countries?
There is a simple way to do this in dax but you have to write each country individually. It would loke something like this:

 

SWITCH(TRUE(),
CONTAINSSTRING(Table[CAR SALES],"ITALY") || 
CONTAINSSTRING(Table[CAR SALES],"FRANCE") ||
CONTAINSSTRING(Table[CAR SALES],"GERMANY") ,"EUROPE",
CONTAINSSTRING(Table[CAR SALES],"CHINA") ||
CONTAINSSTRING(Table[CAR SALES],"INDIA") ||
CONTAINSSTRING(Table[CAR SALES],"SINGAPORE"), "ASIA",
CONTAINSSTRING(Table[CAR SALES],"USA") ||
CONTAINSSTRING(Table[CAR SALES],"CANADA"), "AMERICA",
"(ELSE VALUE)"
)

Thank You! I'll build on from there.

speedramps
Community Champion
Community Champion

It is easy and best pratice to do it using Power Query

speedramps_0-1666257537963.png

 

 

It can also be done in DAX but is is much harder and slower ... much better to use Power Query

see

https://www.youtube.com/watch?v=Vc7A6WiwLwg

 

 https://community.powerbi.com/t5/DAX-Commands-and-Tips/DAX-extract-text-between-delimiter/m-p/119136...

 

 

Thanks for reaching out for help.

I put in a lot of effort to help you, now please quickly help me by giving kudos.

Remember we are unpaid volunteers and here to coach you with Power BI and DAX skills and techniques, not do the users job for them. So please click the thumbs up and accept as solution button. 

If you give someone a fish then you only give them one meal, but if you teach them how to fish then they can feed themselves and teach others for a lifetime.  I prefer to teach members on this forum techniques rather give full solutions and do their job. You can then adapt the technique for your solution, learn some DAX skills for next time and soon become a Power BI Super User like me. 

One question per ticket please. If you need to extend your request then please raise a new ticket.

You will get a quicker response and each volunteer solver will get the kudos they deserve. Thank you ! 

Hi, I got my data from datahub and i'm not able to access to the transform data power query, how to do this using DAX?

CLANG10_0-1666259007733.png

 

See above learning links with examples on how to do it in Dax.

 

I wont build the exact solution for you. I will just provide links how to learn. You need to learn to do your own job.

 

 

Sure Thanks!

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.