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
johnwedeles
Helper III
Helper III

Replacing text in column with new text based on condition

Hello:

 

I am trying to replace a hyphen ("-") with an en dash in an existing column. I know I'd need to use UNICHAR for this. So, I imagine the formula would be something like this:

 

IF Table Name Column Name contains "-", replace with UNICHAR(8211)

 

I don't mind creating a new column or measure if that is necessary.

 

Thank you!

1 ACCEPTED SOLUTION

@johnwedeles 

if it is a value in a cell, use substitute

Column = SUBSTITUTE('Table'[Column1],"-",UNICHAR(8211))

1.PNG

if it is the name of a measure, you replace the whole measure name

2.PNG

2.PNG

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

12 REPLIES 12
ryan_mayu
Super User
Super User

@johnwedeles 

you can use DAX to create a column

Column = SUBSTITUTE("-",'Table'[Column1],UNICHAR(8211))

1.PNG 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you, @Greg_Deckler  and @ryan_mayu . I tried both the REPLACE and SUBSTITUTE functions, and unfortunately when I try to select the appropriate table and column, the specific column does not show up as an option. Note, it is a string variable. I get an error message saying that "a single value for this column cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."

 

 

@johnwedeles - If you are creating a measure, then you will need to wrap the column reference in an aggregator like MAX, MIN, etc.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thank you, @Greg_Deckler . I am entering this code but it is not working - is the right placement for the MAX function?

 

Measure = SUBSTITUTE(MAX('Performance rates'[New Rate Definition])"-",UNICHAR(8211)))

@johnwedeles 

plesae share the sample data and expected output.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@ryan_mayu the string I am working with appears as follows:

 

Ambulatory Care: Emergency Department (ED) Visits: Ages 0-19 Years

 

This is an example of several (approximately 40) measures that are in the table. What I would like to do is replace the hypen (Ages 0-19 Years) with an en dash, using UNICHAR.

@johnwedeles 

why this is a measure? not a value in a cell? How did you calculate this? you can just paste your sample data here or paste a screenshot





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you, @ryan_mayu . Here are two screenshots.

 

johnwedeles_0-1595605051563.pngjohnwedeles_1-1595605112650.png

 

 

@johnwedeles 

if it is a value in a cell, use substitute

Column = SUBSTITUTE('Table'[Column1],"-",UNICHAR(8211))

1.PNG

if it is the name of a measure, you replace the whole measure name

2.PNG

2.PNG

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you, @ryan_mayu !

Thank you, @ryan_mayu . I don't have the ability to attach a file here. 

 

 

Greg_Deckler
Super User
Super User

To do this in DAX, just use a new calculated column with REPLACE

https://docs.microsoft.com/en-us/dax/replace-function-dax

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.