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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
dhruvgulati
Helper I
Helper I

how to replace all special character with space

replace all the special character in a column containing sentences with white space

 

input 

hi.you/love

 

output

hi you love

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

You need to have an approach where you need to replace all other characters other than allowed. In below approach, a to z and 0 to 9 are allowed. Hence, it will replace any other character encountered

{"A".."Z","a".."z","0".."9"} - If you feel 0 to 9 not allowed, make it {"A".."Z","a".."z"}

So basically you are taking Whitelist approach rather than Blacklist approach as creating Blacklist is a big task and also prone to error.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8sjU89TPyS9Lja/ML1WK1YlW8q10yEvMTVXNLAZzwzNSi1JjSg0MjMwSi1K1gaoU0/Mz89LBko4pKUWpxcUKmcUKxiY6Cs75OTmZeUB9sQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    BuffListAllowedChars = List.Buffer({"A".."Z","a".."z","0".."9"}),
    SourceList = List.Buffer(Source[Column1]),
    ListCount = List.Count(SourceList),
    GenList = List.Generate(()=>[x=Text.Combine(List.Transform(Text.ToList(SourceList{0}),(a)=>if List.Contains(BuffListAllowedChars,a) then a else " ")),i=0], each [i]<ListCount, each [i=[i]+1, x=Text.Combine(List.Transform(Text.ToList(SourceList{i}),(a)=>if List.Contains(BuffListAllowedChars,a) then a else " "))], each [x]),
    Result = Table.FromColumns({GenList},{"Result"}) 
in
    Result

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Super User
Super User

You need to have an approach where you need to replace all other characters other than allowed. In below approach, a to z and 0 to 9 are allowed. Hence, it will replace any other character encountered

{"A".."Z","a".."z","0".."9"} - If you feel 0 to 9 not allowed, make it {"A".."Z","a".."z"}

So basically you are taking Whitelist approach rather than Blacklist approach as creating Blacklist is a big task and also prone to error.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8sjU89TPyS9Lja/ML1WK1YlW8q10yEvMTVXNLAZzwzNSi1JjSg0MjMwSi1K1gaoU0/Mz89LBko4pKUWpxcUKmcUKxiY6Cs75OTmZeUB9sQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    BuffListAllowedChars = List.Buffer({"A".."Z","a".."z","0".."9"}),
    SourceList = List.Buffer(Source[Column1]),
    ListCount = List.Count(SourceList),
    GenList = List.Generate(()=>[x=Text.Combine(List.Transform(Text.ToList(SourceList{0}),(a)=>if List.Contains(BuffListAllowedChars,a) then a else " ")),i=0], each [i]<ListCount, each [i=[i]+1, x=Text.Combine(List.Transform(Text.ToList(SourceList{i}),(a)=>if List.Contains(BuffListAllowedChars,a) then a else " "))], each [x]),
    Result = Table.FromColumns({GenList},{"Result"}) 
in
    Result
mahoneypat
Microsoft Employee
Microsoft Employee

Here is one way to do it. Just create a blank query, open the Advanced Editor, and replace the code there with the below, to see how it works. This approach updates the values in an existing column. You could also take the code from the Custom1 step and create a new column with it, then delete the original.

 

let
    Source =
        Table.FromRows(
            Json.Document(
                Binary.Decompress(
                    Binary.FromText(
                        "i45WysjUq8wv1c/JL0tVio0FAA==",
                        BinaryEncoding.Base64
                    ),
                    Compression.Deflate
                )
            ),
            let
                _t = ((type nullable text)
                meta
                [
                    Serialized.Text = true
                ])
            in
                type table [TextColumn = _t]
        ),
    #"Changed Type" =
        Table.TransformColumnTypes(
            Source,
            {
                {
                    "TextColumn",
                    type text
                }
            }
        ),
    Custom1 =
        Table.TransformColumns(
            #"Changed Type",
            {
                "TextColumn",
                each
                    Text.Combine(
                        List.ReplaceMatchingItems(
                            Text.ToList(_),
                            List.Transform(
                                {
                                    ".",
                                    "/"
                                },
                                each
                                    {
                                        _,
                                        " "
                                    }
                            )
                        ),
                        ""
                    )
            }
        )
in
    Custom1

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors