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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Super User
Super User

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
Super User
Super User

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
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors