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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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
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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.