Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Trim a string before a character

Hi Experts,

 

I have a column which have a string as the below. I want to have a DAX formula to truncate the text on the first Semi-Colon ":"

Rohde & Schwarz GmbH & Co. KG: Q42 FY22 MaintRenew: SO#: 9990

Result would be: 

Rohde & Schwarz GmbH & Co. KG

  • Hi Anonymous 

     

    Try this code to add a new column:

    Column = 
    Var _SR = SEARCH(":",'Table'[Data])
    
    return
    left('Table'[Data],len('Table'[Data])-_SR-2)

     

    or this code to add a new measure:

    measure= 
    Var _SR = SEARCH(":",max('Table'[Data]))
    
    return
    left(max('Table'[Data]),len(max('Table'[Data]))-_SR-2)

     

    If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
    Appreciate your Kudos!!
    LinkedIn: 
    www.linkedin.com/in/vahid-dm/

     

     

1 Reply

  • Hi Anonymous 

     

    Try this code to add a new column:

    Column = 
    Var _SR = SEARCH(":",'Table'[Data])
    
    return
    left('Table'[Data],len('Table'[Data])-_SR-2)

     

    or this code to add a new measure:

    measure= 
    Var _SR = SEARCH(":",max('Table'[Data]))
    
    return
    left(max('Table'[Data]),len(max('Table'[Data]))-_SR-2)

     

    If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
    Appreciate your Kudos!!
    LinkedIn: 
    www.linkedin.com/in/vahid-dm/