Power BI: extract numbers and/or text

To extract numbers, text or any characters, the easy way to do it is from the Power Query Editor, from there, just click on “add column -> custom column”:

power bi

There are 2 functions that I can use:

  • Text.Select: select the specified characters
    Text.Select([argument],{"value1".."value2"})
  • Text.Remove: remove the specified characters
    Text.Remove([argument],{"value1".."value2"})

And to remove unuseful spaces:

  • Text.Combine(List.Select(Text.SplitAny([argument], " #(lf)#(cr)"), each _<>""), " ")
power bi power bi power bi

Both work the same way and based on what I want, they can give me the same results or not. They are case sensitives so if I said to remove small characters (for instance “a”), it will keep capital ones (for instance “A”):

power bi

I will use Text.Select for my examples from now on to not duplicate. For numbers, just replace the letters:

power bi

To get decimal numbers, I will need to add the separator:

Text.Select([argument],{"value1".."value2","."})

power bi

NOTE: if the separator is a coma for instance, just replace "." by ","

In case if it can’t find what I request or to ignore errors, I can tell it to put something else:

try ... otherwise value

power bi

NOTE: change “value” by yours or by “null” for an empty cell

To combine both or more options, just add it like that:

Text.Select([argument],{"value1".."value2","value3".."value4"})

power bi

With those 2 functions, I can select or remove what I want. The important rule to respect is that the decimal “value1” should be inferior to “value2”. For instance:

  • This formula will work:
    power bi
  • This formula will not work:
    power bi

In this wikipedia decimal unicode page, I can find the information and as you can see, ! has 33 and ) has 41:

power bi

Interesting Topics