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
Pandadev
Post Prodigy
Post Prodigy

¿Hay una opción bin to Hex en PowerBI

Hola estoy tratando de convertir código binario de 24 bits a hexadecimal

Una fórmula como esta funcionó en Excel usando el Bin2Hex

"RIGHT("0"&BIN2HEX(LEFT(A1,LEN(A1)/3)),2)&RIGHT("0"&BIN2HEX(MID(A1,LEN(A1)/3+1,1,3 LEN(A1)/3)),2)&RIGHT("0"&BIN2HEX(MID(A1,2*LEN(A1)/3+1,LEN(A1)/3)),2)

Un ejemplo 1100000001110011111110 debe ser C059DE

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

Hola, @Pandadev

Tengo un método complicado, si no crees que estorpe, puedes probarlo:

Necesita usar la columna condicional para convertir "4 bit binario" a "1bit hex", luego combinarlos.

97.png Consulta M:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0NIAAQwMQ09AQRAMJpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Index = _t, #"24bit binary" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"24bit binary", type text}, {"Index", type text}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "24bit binary", "24bit binary - Copy"),
    #"Split Column by Position" = Table.SplitColumn(#"Duplicated Column", "24bit binary - Copy", Splitter.SplitTextByRepeatedLengths(4), {"4bit binary - 1", "4bit binary - 2", "4bit binary - 3", "4bit binary - 4", "4bit binary - 5", "4bit binary - 6"}),
    #"Unpivoted Columns2" = Table.UnpivotOtherColumns(#"Split Column by Position", {"Index", "24bit binary"}, "Attribute", "Value"),
    #"Added Conditional Column" = Table.AddColumn(#"Unpivoted Columns2", "1 bit HEX ", each if [Value] = "0000" then 0 else if [Value] = "0001" then 1 else if [Value] = "0010" then 2 else if [Value] = "0011" then 3 else if [Value] = "0100" then 4 else if [Value] = "0101" then 5 else if [Value] = "0110" then 6 else if [Value] = "0111" then 7 else if [Value] = "1000" then 8 else if [Value] = "1001" then 9 else if [Value] = "1010" then "A" else if [Value] = "1011" then "B" else if [Value] = "1100" then "C" else if [Value] = "1101" then "D" else if [Value] = "1110" then "E" else if [Value] = "1111" then "F" else null),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Conditional Column",{{"1 bit HEX ", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Value"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Attribute]), "Attribute", "1 bit HEX "),
    #"Merged Columns" = Table.CombineColumns(#"Pivoted Column",{"4bit binary - 1", "4bit binary - 2", "4bit binary - 3", "4bit binary - 4", "4bit binary - 5", "4bit binary - 6"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged")
in
    #"Merged Columns"

Para obtener más detalles, por favor chech el archivo de ejemplo.

Saludos
Equipo de soporte de la comunidad _ Eason

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

He probado esta solución dax , pero viene con un error . He convertido el número largo binario de texto a decimal , trató de convertirlo a binario, donde sólo va a binario naranja, pero seguir recibiendo un MOD tiene un tipo de datos incorrecto o el resultado es demasiado grande

DEC2HEX ?
VAR ConvertMe á 'Reg'[Modo S binario]
Base var 24
BitTable de VAR (VAR BitTable)
GENERATESERIES ( 1, 6 )
VAR DEC2HEX ?
CONCATENAR(
BitTable,
VAR c - MOD ( TRUNC ( ConvertMe / POWER ( base, [value] - 1 ) ), base )
RETURN SWITCH(c,10,"A",11,"B",12,"C",13,"D",14,"E",15,"F",c),
,
[Valor],Desc)
devolución
• DEC2HEX - // Devuelve 'FF'

@Pandadev ,

GENERATESERIES ( 1, 6 ) debe ser hasta 8 o 16

Mi consejo sería usar la forma de consulta de energía. Todas las formas DAx son un poco complejas.

He probado el código M para MODE S , que es el texto binario convertido a bin

• Table.AddColumn(-"Changed Type2", "Mode S Bin", each Binary.ToText([Mode S Binary])) convierte de nuevo al texto correctamente

• Table.AddColumn(-"Changed Type2", "Mode S Hex", each BinaryEncoding.Hex([Mode S Binary])) cuando probé esto sólo trae de vuelta el error

Hola, @Pandadev

Tengo un método complicado, si no crees que estorpe, puedes probarlo:

Necesita usar la columna condicional para convertir "4 bit binario" a "1bit hex", luego combinarlos.

97.png Consulta M:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0NIAAQwMQ09AQRAMJpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Index = _t, #"24bit binary" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"24bit binary", type text}, {"Index", type text}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "24bit binary", "24bit binary - Copy"),
    #"Split Column by Position" = Table.SplitColumn(#"Duplicated Column", "24bit binary - Copy", Splitter.SplitTextByRepeatedLengths(4), {"4bit binary - 1", "4bit binary - 2", "4bit binary - 3", "4bit binary - 4", "4bit binary - 5", "4bit binary - 6"}),
    #"Unpivoted Columns2" = Table.UnpivotOtherColumns(#"Split Column by Position", {"Index", "24bit binary"}, "Attribute", "Value"),
    #"Added Conditional Column" = Table.AddColumn(#"Unpivoted Columns2", "1 bit HEX ", each if [Value] = "0000" then 0 else if [Value] = "0001" then 1 else if [Value] = "0010" then 2 else if [Value] = "0011" then 3 else if [Value] = "0100" then 4 else if [Value] = "0101" then 5 else if [Value] = "0110" then 6 else if [Value] = "0111" then 7 else if [Value] = "1000" then 8 else if [Value] = "1001" then 9 else if [Value] = "1010" then "A" else if [Value] = "1011" then "B" else if [Value] = "1100" then "C" else if [Value] = "1101" then "D" else if [Value] = "1110" then "E" else if [Value] = "1111" then "F" else null),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Conditional Column",{{"1 bit HEX ", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Value"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Attribute]), "Attribute", "1 bit HEX "),
    #"Merged Columns" = Table.CombineColumns(#"Pivoted Column",{"4bit binary - 1", "4bit binary - 2", "4bit binary - 3", "4bit binary - 4", "4bit binary - 5", "4bit binary - 6"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged")
in
    #"Merged Columns"

Para obtener más detalles, por favor chech el archivo de ejemplo.

Saludos
Equipo de soporte de la comunidad _ Eason

Gracias , esa solución funcionó muy bien

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.