How to replace specific characters in data from SharePoint to Power Query?

rizzo93

Active Member
Joined
Jan 22, 2015
Messages
299
Office Version
  1. 365
My form on SharePoint has a multiple-choice field. When I bring that data into Excel (as a connection), it displays with extra characters like this:

Bruce Wayne;#5
Mickey Mouse;#20;#Clark Kent;#5
Daffy Duck;#17

When there's more than one name, I want "/" to replace those characters. When it's just one name, I want the characters removed like this:

Bruce Wayne
Mickey Mouse/Clark Kent
Daffy Duck

I'm using Power Query to process this and other columns of data but struggling to figure out how to make this particular change. All ideas are welcome, thanks!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
You'll want to use the Advanced option when replacing special characters:
1671548269501.png

The #() notation is known as Character Escape Sequences:
From the M Language manual:
#(000D) // short Unicode hexadecimal value
#(0000000D) // long Unicode hexadecimal value
#(cr) // compact escape shorthand for carriage return

Here's a way to determine what character is the problem:
Book1
CDEFGHI
7LFCRLFCR
8This has CRThis has LF84T84T
9104h104h
10105i105i
11115s115s
1232 32
13104h104h
1497a97a
15115s115s
1632 32
1710 13
1832 76L
1967C70F
2082R
Sheet1
Cell Formulas
RangeFormula
C8C8="This has "&CHAR(10)&" CR"
D8D8="This has "&CHAR(13)&"LF"
F8:F20F8=CODE(MID(Sheet1!$C8,SEQUENCE(LEN(Sheet1!$C8)),1))
G8:G20,I8:I19G8=CHAR(F8#)
H8:H19H8=CODE(MID(Sheet1!$D8,SEQUENCE(LEN(Sheet1!$D8)),1))
Dynamic array formulas.
 
Upvote 0
Thank you, @jdellasala.

I don't entirely understand your solution. Are you recommending a multi-step approach by replacing the unwanted characters one at a time in Power Query?

You mentioned "a way to determine what character is the problem." But it's multiple characters that are the problem. It's a combination of ";#" and the numbers that follow those characters (;#20;#) when more than one name appears in the field, and when they appear at the end of each value.

If you could show me an example using the sample data I provided above, perhaps that would help.
 
Upvote 0
Thank you, @jdellasala.

I don't entirely understand your solution. Are you recommending a multi-step approach by replacing the unwanted characters one at a time in Power Query?

You mentioned "a way to determine what character is the problem." But it's multiple characters that are the problem. It's a combination of ";#" and the numbers that follow those characters (;#20;#) when more than one name appears in the field, and when they appear at the end of each value.

If you could show me an example using the sample data I provided above, perhaps that would help.
Yes, you will have to filter each character or sequence of characters separately if you only use the UI. Search YouTube for Power Query filter using list for a solution where you can create a table of problem characters, bring that into PQ and use it to filter a column. That's more than I know off the top of my head, and I have to catch a plane!
 
Upvote 0
Yes, you will have to filter each character or sequence of characters separately if you only use the UI. Search YouTube for Power Query filter using list for a solution where you can create a table of problem characters, bring that into PQ and use it to filter a column. That's more than I know off the top of my head, and I have to catch a plane!
Much appreciated, @jdellasala!
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,956
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top