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.
Hi I am trying to convert 24 bit binary code to hex
A formula like this worked in excel using the Bin2Hex
=RIGHT("0"&BIN2HEX(LEFT(A1,LEN(A1)/3)),2)&RIGHT("0"&BIN2HEX(MID(A1,LEN(A1)/3+1,LEN(A1)/3)),2)&RIGHT("0"&BIN2HEX(MID(A1,2*LEN(A1)/3+1,LEN(A1)/3)),2)
An example 110000000101100111011110 should be C059DE
Solved! Go to Solution.
@Pandadev , if it is binary not test you have code in Power Query/ M
refer
https://community.powerbi.com/t5/Desktop/Converting-Binary-to-hex-value-or-numeric-value/td-p/374779
For DAX, refer
https://dax.tips/2019/10/02/dax-base-conversions/
Hi, @Pandadev
I have a complicated method, if you don't think it’s clumsy , you can try it:
It needs to use conditional column to convert "4 bit binary " to "1bit hex",then merge them.
M query:
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"
For more details,please chech the sample file.
Best Regards,
Community Support Team _ Eason
@Pandadev , if it is binary not test you have code in Power Query/ M
refer
https://community.powerbi.com/t5/Desktop/Converting-Binary-to-hex-value-or-numeric-value/td-p/374779
For DAX, refer
https://dax.tips/2019/10/02/dax-base-conversions/
I tried this dax solution , but it comes up with an error . I converted the binary long number from text to decimal , tried converting it to binary , where it just goes to orange binary , but keep getting a MOD has wrong data type or result is too large
the GENERATESERIES ( 1, 6 ) should be till 8 or 16
My advice would be to use the power query way. All DAx ways are a bit complex.
I tried the M code for MODE S , which is the text binary converted to bin
= Table.AddColumn(#"Changed Type2", "Mode S Bin", each Binary.ToText([Mode S Binary])) converts back to text correctly
= Table.AddColumn(#"Changed Type2", "Mode S Hex", each BinaryEncoding.Hex([Mode S Binary])) when I tried this it just brings back error
Hi, @Pandadev
I have a complicated method, if you don't think it’s clumsy , you can try it:
It needs to use conditional column to convert "4 bit binary " to "1bit hex",then merge them.
M query:
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"
For more details,please chech the sample file.
Best Regards,
Community Support Team _ Eason
Thanks , that solution worked great
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
108 | |
100 | |
78 | |
64 | |
58 |
User | Count |
---|---|
148 | |
113 | |
97 | |
84 | |
67 |