Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

extracting text from column using DAX

Hi All, I have this column: Property 102(1 Mar Street - Sold) 102 (1 Mar Street - Sold) 103 (12 Waler Street - North Sydney - Sold) 103 (12 Waler Street - North Sydney - Sold) ...
  • danextian's avatar
    1 year ago

    Hi Anonymous 

    This is better off done with M than in DAX. This will be a very long and possibly nasty code with DAX. Below is a sample M based on your data.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pY/LCsIwEEV/5dJVBIX0aV0ruvCxaAUXtYtABhVCAmkq9O8NaqEUEcTtnMOcmaoKQh6xEHthUTpL5DBDaZScBPX0CfGNxp5GOAlFA+FgrLui7KSm7k8/BEtwbjmPMqRYm1ZLFBI7cSfrjO61BCzOsfKzrkFhhPRrxk7KMhxvSopeeAV7PPcljo2xFxq8+umm3Mc4tqTdW/zx2AVYiqVRzbjjhfoB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Property = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Property", type text}}),
        #"Inserted Text Before Delimiter" = Table.AddColumn(#"Changed Type", "ID", each Text.BeforeDelimiter([Property], "("), type text),
        #"Inserted Text Between Delimiters" = Table.AddColumn(#"Inserted Text Before Delimiter", "Address", each Text.BeforeDelimiter(Text.BetweenDelimiters([Property], "(", "-"), ")"), type text),
        #"Inserted Text Between Delimiters1" = Table.AddColumn(#"Inserted Text Between Delimiters", "State", each Text.Trim(Text.BeforeDelimiter(Text.BetweenDelimiters([Property], "-", "-"), ")")), type text),
        #"Inserted Text Between Delimiters2" = Table.AddColumn(#"Inserted Text Between Delimiters1", "Status", each 
    if Text.Contains([Property], "-") then
    Text.BetweenDelimiters([Property], "-", ")", {0, RelativePosition.FromEnd}, 0) else null, type text)
    in
        #"Inserted Text Between Delimiters2"

    The applied transformations are not entirely accurate due to inconsistencies in the address data.