Search code examples
powerbipowerquerym

Power BI Encoding UTF8 for a column


I am trying to force an encoding for a column in Power BI to UTF 8, however it is failing with an error.

= Table.SelectRows(
  #"Changed Type", 
  each 
    if ([number] is null or [number] = "") then
      null
    else
      Text.FromBinary(Text.ToBinary([number], 1251), TextEncoding.Utf8)
)

The [number] field is TEXT and contains values like TEST_DAVE, PROD10, test10 .

The error is

Expression.Error: We cannot convert the value "TEST_DAVE" to type Logical. Details: Value=TEST_DAVE Type=[Type]

Tried lots of combinations of this statement but its not working yet ... Any ideas please ?


Solution

  • The Table.SelectRows function expects a logical true/false result but you're returning nulls and/or text.

    Try using Table.TransformColumns instead.

    = Table.TransformColumns(
        #"Changed Type",
        {
         "number",
         each if (_ = null or _ = "") then null
              else Text.FromBinary(Text.ToBinary(_, 1251), TextEncoding.Utf8)
        }
      )