Share via

Using Power Query to split a column at a variable position

Anonymous
2024-11-15T18:01:53+00:00

My data looks like this...

Column A
Dr. Sam Karta Jr., CEO, Tallis Partners
Fred Sampson, III, Director, Aspen Institute
Ruth Kaufmann, PhD, Executive Director
Marci Cheng, CHRO

I need Power Query to split this column so that job titles — but not the suffixes (e.g., PhD, Jr., III, etc.) — transfer to a new column. Not everyone has a suffix, and each row entry has a different number of commas, so I cannot reliably split using a delimiter.

Instead, I want PQ to look for the existence of a suffix (e.g., PhD, Jr., III, etc.) then split any remaining text (i.e., text after the suffix) into a new column. If a suffix does not exist (see Marci Cheng), PQ splits at the first comma.

So, the data would look like this...

Column A Column B
Dr. Sam Karta Jr. CEO, Tallis Partners
Fred Sampson, III Director, Aspen Institute
Ruth Kaufmann, PhD Executive Director
Marci Cheng CHRO

Can you help? Thank you so much!

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Ashish Mathur 102K Reputation points Volunteer Moderator
2024-11-16T03:44:04+00:00

Hi,

You may download my solution workbook from here.

Hope this helps.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Anonymous
    2024-11-27T17:30:02+00:00

    Great solution. Thanks, Ashish! What courses or online resources do you recommend to learn these advanced features?

    Was this answer helpful?

    0 comments No comments
  2. Ashish Mathur 102K Reputation points Volunteer Moderator
    2024-11-16T03:54:02+00:00

    Hi,

    If you want a formula-based solution, then enter this formula in cell B2

    =IFERROR(TRIM(CHOOSECOLS(TEXTSPLIT(A2:A5,$D$2:$D$4),2)),TEXTAFTER(A2:A5,", "))

    Hope this helps.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2024-11-15T19:14:16+00:00

    I'm hoping to keep this transformation in PQ, but I appreciate you demonstrating this in formula notation as well.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2024-11-15T18:25:20+00:00

    Are you accept formula?

    =TEXTSPLIT(IF(LEN(A2)-LEN(SUBSTITUTE(A2,",",""))=1,SUBSTITUTE(A2,", ","|"),SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,"Jr., ","Jr.|"),"III, ","III|"),"PhD, ","PHD|")),"|")

    Was this answer helpful?

    0 comments No comments