Forum Discussion
smpa01
4 years agoCommunity Champion
Integer/Decimal to Binary in PQ
Does PQ currently have any syntax that converts an integer /decimal value to Binary. I looked into the documentation and could not find anything e.g. 52 = 110100, 137.5879541 = 100010...
- 4 years ago
mahoneypat this is mine and only for integer but I even have a better solution than this, getting blogged out.
let Source = (p1 as number) => let Loop = List.Generate( () => [i = p1, j = Number.IntegerDivide(i, 2), k = Number.Mod(i, 2), l = Text.From(k)], each [i] > 0, each [i = [j], j = Number.IntegerDivide(i, 2), k = Number.Mod(i, 2), l = Text.From(k) & [l]], each [l] ) in Loop{List.Count(Loop) - 1}, Source1 = {1..100}, #"Converted to Table" = Table.FromList(Source1, Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Added Custom" = Table.AddColumn(#"Converted to Table", "Custom", each fx([Column1])) in #"Added Custom"
mahoneypat
4 years agoMicrosoft Employee
I am not aware of a native function to do that. However, you could do it with a custom function, R or Python, or with a REST API call (slower).
Pat