Forum Discussion

ryan_b_123's avatar
ryan_b_123
Frequent Visitor
4 years ago
Solved

Power M - Find Numbers Before Specific Text

Hello, I am looking to extract numbers before specific text ("BUP").  I think it is possible we may need to address " BUP" specifically, as users would likely put a space between number and "BUP".  E...
  • Vijay_A_Verma's avatar
    Vijay_A_Verma
    4 years ago

    Use this in a custom column

    = if Text.End([Data],3)="BUP" then Text.Replace(List.Last(Text.Split(Text.Select(Text.Replace([Data]," BUP","BUP"),{"0".."9"," ","B","U","P"})," ")),"BUP","") else 0

    Full test code

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjFQcAoNUIrViVZy8PF3dgzx9PdTMDKFC2ak5uTkx5fnF+WkoCoyMoUpMTGNKTUwMDKDkHDNsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
        #"Added Custom" = Table.AddColumn(Source, "Custom", each if Text.End([Data],3)="BUP" then Text.Replace(List.Last(Text.Split(Text.Select(Text.Replace([Data]," BUP","BUP"),{"0".."9"," ","B","U","P"})," ")),"BUP","") else 0, type number)
    in
        #"Added Custom"