Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

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

  • Anonymous's avatar
    Anonymous
    7 years ago

    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.

5 Replies

  • v-juanli-msft's avatar
    v-juanli-msft
    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's avatar
      Anonymous
      Not applicable

      Hi 

      • v-juanli-msft's avatar
        v-juanli-msft
        Community Support

        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:

        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.