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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
efeurich
Helper I
Helper I

Replacing a value in a column with other value in DAX

So I have looked around on the interweb but can't find what I need.

I need to replace a line of text like "Supermarket jada jada accounting stuff happy day" with the value "Food and Drinks".

The focus here is on supermarket, when this word is in the text it should replace the whole text with the value "Food and Drinks" 

I got it to the point that it replaces the word Supermarket with Food and Drinks. But I need the whole text to be replaced. 

Found some DAX code that uses "using CONTAINSSTRING" but I can't get it to work.

 

Suggestions are very welcome.

1 ACCEPTED SOLUTION
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @efeurich 

 

Please try the following:

 

my sample table created in power query and loaded into the data model:

Mikelytics_0-1668722365195.png

 

Calculated Column:

Mikelytics_1-1668722400959.png

 

Formula to replace the string:

 

ReplaceText = 
IF(
    CONTAINSSTRING([Text],"supermarket") = TRUE(),
    "supermarket",
    [Text]
)

 

Result:

Mikelytics_2-1668722537875.png

 

Best regards

Michael

-----------------------------------------------------

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your thumbs up!

@ me in replies or I'll lose your thread.

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

View solution in original post

3 REPLIES 3
efeurich
Helper I
Helper I

Hi Micheal,

 

Thanks for the clear and effective explanation.

 

Best regards,

 

Eric

Hi Eric,

 

I am happy to help! Thank you for your feedback!

 

Best regards

Michael

-----------------------------------------------------

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your thumbs up!

@ me in replies or I'll lose your thread.

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @efeurich 

 

Please try the following:

 

my sample table created in power query and loaded into the data model:

Mikelytics_0-1668722365195.png

 

Calculated Column:

Mikelytics_1-1668722400959.png

 

Formula to replace the string:

 

ReplaceText = 
IF(
    CONTAINSSTRING([Text],"supermarket") = TRUE(),
    "supermarket",
    [Text]
)

 

Result:

Mikelytics_2-1668722537875.png

 

Best regards

Michael

-----------------------------------------------------

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your thumbs up!

@ me in replies or I'll lose your thread.

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.