Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Split text and stick together using DAX

I have a column which contains last name, fist name, and email. I want to get first name and last name from that usnig DAX.

I have tried using FIND with LEFT, but wasn't successful.

Looking forward to your help.

 

Example data

NoPerson
1Smith, John, [email protected]
2Morris, Elena, [email protected]
3Anderson, Jack, [email protected]
4Harris, Mari, [email protected]

 

Output

NoPersonName
1Smith, John, [email protected]John Smith
2Morris, Elena, [email protected]Elena Morris
3Anderson, Jack, [email protected]Jack Anderson
4Harris, Mari, [email protected]Mari Harris

 

Thanks

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous 

     

    M is more intuitive...

    Column = 
    VAR firstP = SEARCH(",",[Person],1)
    VAR secondP = FIND(",",[Person],firstP+1)
    RETURN
    MID([Person],firstP+1,secondP-firstP-1)&" "&LEFT([Person],firstP-1)

     

2 Replies

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    This would be much easier in the query editor.  Why not do it there?

    Pat

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous 

     

    M is more intuitive...

    Column = 
    VAR firstP = SEARCH(",",[Person],1)
    VAR secondP = FIND(",",[Person],firstP+1)
    RETURN
    MID([Person],firstP+1,secondP-firstP-1)&" "&LEFT([Person],firstP-1)