cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors