Forum Discussion

juuju's avatar
juuju
New Member
8 years ago
Solved

DAX: extracting string using delimiter

Hi guys, newbie to the forum! I've recently discovered PowerPivot and it's fantastic - but do occassionaly encounter issues when converting Excel formulas to DAX-friendly formulas.   I have a colum...
  • TomMartens's avatar
    8 years ago

    Hey,

     

    besides the fact that I would try to create the columns using the Query Editor here are two DAX Statements to create Calculated Columns

    First Derived Column = 
    var FirstColon = FIND(":",'Table1'[Origin Column],1)
    var SecondColon = FIND(":",'Table1'[Origin Column],FirstColon + 1)
    var ThirdColon = FIND(":",'Table1'[Origin Column],SecondColon + 1)
    return
    MID('Table1'[Origin Column], SecondColon + 1, ThirdColon - SecondColon - 1)

    and

    Second Derived Column = 
    var FirstColon = FIND(":",'Table1'[Origin Column],1)
    var SecondColon = FIND(":",'Table1'[Origin Column],FirstColon + 1)
    var ThirdColon = FIND(":",'Table1'[Origin Column],SecondColon + 1)
    var LengthOfString = LEN('Table1'[Origin Column])
    return
    MID('Table1'[Origin Column],ThirdColon + 1, LengthOfString -  ThirdColon + 1)

    this would create the following

  • ImkeF's avatar
    ImkeF
    8 years ago

    As TomMartens mentioned already, this task can easier be done in Power Query /the query editor in PBI.

     

    If you want to extract the values between the 2nd and 3rd colon delimiter, you add a column with this formula:

     Text.Split([Value], ":"){2}

    It splits the text on each colon and returns a list of the separated values. To fetch the 3rd value from the list you use {2} because the count starts at zero here.

     

    To extract the values after the last colon, there is a nice user interface for it:

     

    It results in this formula:

    Text.AfterDelimiter([Value], ":", {0, RelativePosition.FromEnd})