Forum Discussion
Using the "IF" function to create a new column
Ah, OK, sounds to me like you want more of a "lookup" function. See below code for creating one of these. Note that while I use a manually created list, you could use a list created from something like a database table, etc. To create this example, just create a blank query and paste in the code. Then you can test it with in the Query Editor interface. To use it, just create a new column that calls the function name with a parameter:
let
fnHex2Dec = (input) =>
let
values = {
{"0", 0},
{"1", 1},
{"2", 2},
{"3", 3},
{"4", 4},
{"5", 5},
{"6", 6},
{"7", 7},
{"8", 8},
{"9", 9},
{"A", 10},
{"B", 11},
{"C", 12},
{"D", 13},
{"E", 14},
{"F", 15}
},
Result = Value.ReplaceType({List.First(List.Select(values, each _{0}=input)){1}},type {number})
in
Result
in
fnHex2DecThis function takes a single input parameter, a single text character and translates it to a decimal equivalent. You can test this function by clicking the "Invoke" button in the Power Query Editor window. Be sure to enter a single value preceded by a single quote, such as 'A. The single quote forces the input to be recognized as text. This ensures that if you enter a 7, that it is recognized as text instead of a number.
This is "M" code by the way.
To use it, create a new column in the Query Editor like:
=fnHex2Dec("A")- Greg_Deckler10 years ago
Community Champion
I'm not sure what you mean by an "invoke" function?