Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Trying to split text into two columns with an inconsistent delimeter

Hi All,

 

Here's a small mock data set for a data source I am trying to clean. I need to separate the text into two separate columns, but "traditional" methods like using some basic text funtions and splitting by delimeter do not work.

 

Power BI Question.png

 

I'm trying to split the column "Project Name" into two new columns:

  • One column will just have the Project Number (the 4-6 digit number at the beginning of the cell)
  • The other column will have the Project Name (the sting of text that comes after the number)

 

Here are my issues:

  • Due to human error when an employee enters a project name into our system, sometimes there is an extra space after the first dash (as seen in the second row) or sometimes the first dash is omitted (see the fifth row)
  • Ideally, the Project name should follow this taxonomy: "Project Name"space"-"space"Project Title" but this doesn't always happen for all instances

The Challenge:

  • I can't use a Left() funtion because the project numbers vary in number of digits
  • I cannot split the column by delimeter because there are a few instances that don't adhere to the "Project Name"space"-"space"Project Title" structure due to human error
  • For the extra space after the dash instances, I want to avoid the new Project Name column to return the extra space as well (conceptually thinking, I want all of the text to be left-most aligned so the first thing in the cell is a character, not a space)

The EXTRA Challenge:

  • This data is being pumped into Power BI directly from our CRM, and due to different permission levels, I cannot query edit. As such, I'm trying to figure out a fix by using DAX to create new columns. 

 

Thank you in advance for any or all insight you can offer to help me fix this very nitpicky issue!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Try using the below DAX to create columns:

Project Number = 
VAR v_hyphenPos = SEARCH( "-", Data[ProjectName], 1, 0)
RETURN
TRIM( LEFT( Data[ProjectName], v_hyphenPos-1 ) )
Project Name = 
VAR v_hyphenPos = SEARCH( "-", Data[ProjectName], 1, 0)
RETURN
TRIM( RIGHT( Data[ProjectName], (LEN(Data[ProjectName])-1) - (v_hyphenPos  - 1 ) ) )

Thanks.

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Try using the below DAX to create columns:

Project Number = 
VAR v_hyphenPos = SEARCH( "-", Data[ProjectName], 1, 0)
RETURN
TRIM( LEFT( Data[ProjectName], v_hyphenPos-1 ) )
Project Name = 
VAR v_hyphenPos = SEARCH( "-", Data[ProjectName], 1, 0)
RETURN
TRIM( RIGHT( Data[ProjectName], (LEN(Data[ProjectName])-1) - (v_hyphenPos  - 1 ) ) )

Thanks.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.