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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Anonymous
Not applicable

Change encoding of a specific column

Hi,

I have a column with lots of characters like Ä Â Ñ etcetera. Instead of doing a search and replace for each of these characters, I found this piece of code which changes the encoding from Windows 1251 to Ascii. This gets rids of all 'custom' characters:

 

= Table.AddColumn(source, "Custom Column", each Text.FromBinary(Text.ToBinary([Product Name], 1251), TextEncoding.Ascii))

 

However, I don't want to have another column, I want the encoding to happen directly in my Product Name column. What I'm doing now is deleting my original Product name column and then renaming the new Custom Column. But that's two extra steps.

 

Is there a line of code I can replace this code with so that I do not get an additional column, but instead the encoding gets changed immediately in the Product Name column?

Thank you in advance
Bas

 

1 ACCEPTED SOLUTION

The only advice I would give is to rename the original column BEFORE you add the column. Then you can save the step of renaming the new column because you can use the correct name when you create the custom column.

More steps doesn't necessarily mean slower refresh, depends what you're doing in each step.

If you have lots of steps where you change the data type for example, and change from number to currency then back to number, that should be cleaned up.

Hope that makes sense?

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

9 REPLIES 9
zgraja
New Member

This worked for me:
= Table.TransformColumns(source,{{"Product Name", each Text.FromBinary(Text.ToBinary(_, 1251), TextEncoding.Ascii)}})

Ultramarp09
New Member

Create a custom column in Power query, in your dataset find the special characters you need to replace, according to your post it must be in spanish so there's only 12 special characters 6 for each case
Use this formula for the custom column
=Text.Replace(Text.Replace(Text.Replace(Text.Replace(Text.Replace(Text.Replace(
Text.Replace(Text.Replace(Text.Replace(Text.Replace(Text.Replace(Text.Replace([your_column],
"á", "á"), "Ã", "Á"),
"ã‰", "é"), "É", "É"),
"í", "í"), "Í", "Í"),
"ã“", "ó"), "Ó", "Ó"),
"ú", "ú"), "Ú", "Ú"),
"ñ", "ñ"), "Ñ", "Ñ")

Remember, this special characters i show here could not be the same as yours, i'm only sure about the é and ó.

replace the special characters for the ones in your dataset and that should do the trick, ovbiously the easiest way to do this is to encode the dataset as utf8 friendly and then it should recognize all those special characters.

dstoma
Frequent Visitor

Was there a solution posted?  I clicked on "Go to Solution", but I didn't see it.  Was it deleted at some point?

amitchandak
Super User
Super User

@Anonymous , is it a database source or CSV? I rememember in case of CSV it ask for encoding at time of loading.

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thanks for the fast replies @Greg_Deckler  and @amitchandak .

The data is not a csv, there's many steps before I get into the encoding step, it's a combination of many files and filetypes. 

 

I always assumed that the more steps there are, the slower the refresh time becomes. Hence I'm cleaning up my queries to try and reduce the amount of steps and combining things as much as possible. But if you're saying it doesn't affect load times then I might just leave it like this.

 

In general I have a lot of queries where I first have to create a custom column based on an original column. I then remove the original column and rename the custom column to the same name as the original. If there's an easy way to fix this (perhaps there's a piece of code that should be changed in any step to make the change in the same column instead of in a custom column) I'd love to hear about it!


Thanks

Bas

The only advice I would give is to rename the original column BEFORE you add the column. Then you can save the step of renaming the new column because you can use the correct name when you create the custom column.

More steps doesn't necessarily mean slower refresh, depends what you're doing in each step.

If you have lots of steps where you change the data type for example, and change from number to currency then back to number, that should be cleaned up.

Hope that makes sense?

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

Good advice, thanks @AllisonKennedy !

Hi @Anonymous 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your data model and your problem or share me with your pbix file from your Onedrive for Business.

 

Best Regards,

Rico Zhou

Greg_Deckler
Super User
Super User

@Anonymous - Create the new column with the code. Delete the old column. Rename the column. Steps are your friend.



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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 FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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