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
Anonymous
Not applicable

convertation from utf-8 to utf-16

Dear colleagues!

    I am getting string data from ODBC in UTF-8 encoding. Can anybody explain how to convert this data to UTF-16 using Power BI functions?

Something like it's possible in .NET:

 

Private Function Utf8ToUtf16(utf8String As String) As String

    ' Get UTF-8 bytes by reading each byte with ANSI encoding
    Dim utf8Bytes As Byte() = Encoding.Default.GetBytes(utf8String)

    ' Convert UTF-8 bytes to UTF-16 bytes
    Dim utf16Bytes As Byte() = Encoding.Convert(Encoding.UTF8, Encoding.Unicode, utf8Bytes)

    ' Return UTF-16 bytes as UTF-16 string
    Utf8ToUtf16 = Encoding.Unicode.GetString(utf16Bytes)
End Function

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Dear colleagues, thank you for help!

    It was my missunderstunding with encoding number. When I has changed query to this:

 #"Added Custom" = Table.AddColumn(Source, "CUSTCODEUTF16", each Text.FromBinary(Text.ToBinary([CUSTCODE], 1251), TextEncoding.Utf8)

everything start working correctly.

View solution in original post

5 REPLIES 5
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

You could use M function

TextEncoding.Utf8 or TextEncoding.Utf16

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi 

Hi @Anonymous 

As searched , the difference between utf-8 and utf-16 is how many bytes it require to represent a character in memory. UTF-8 uses minimum one byte, while UTF-16 uses minimum 2 bytes.

When you import data into Power BI, Power BI will cast the data to the corresponding data type.

Data type in Power Query are listed as below:

Capture11.JPG

For example, Text type - A Unicode character data string. Can be strings, numbers, or dates represented in a text format. Maximum string length is 268,435,456 Unicode characters (256 mega characters) or 536,870,912 bytes.

So you don't worry about the filed memory.

 

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Dear colleagues, thank you for help!

    It was my missunderstunding with encoding number. When I has changed query to this:

 #"Added Custom" = Table.AddColumn(Source, "CUSTCODEUTF16", each Text.FromBinary(Text.ToBinary([CUSTCODE], 1251), TextEncoding.Utf8)

everything start working correctly.

Hi @Anonymous ,

 

Hope you are well.

When I try to use below formula, then the result is "error"

 

soldier_rong_0-1669783589031.png

 

 

Table.AddColumn("Query1", "CUSTCODEUTF16", each Text.FromBinary(Text.ToBinary([Company Name], 1251), TextEncoding.Utf8)

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.

Top Solution Authors
Top Kudoed Authors