Forum Discussion

Hamidrezaei's avatar
Hamidrezaei
Frequent Visitor
6 years ago
Solved

White spaces

Hi Guys,    Is there any way to change colums with space to null? some cells contains only one or multiple spaces inside.  The function Trim seems to remove only beggining and the end of a cell wi...
  • v-alq-msft's avatar
    6 years ago

    Hi, Hamidrezaei 

     

    Based on your descirption, I created data to reproduce your scenario. The pbix file is attached in the end.

    Test(row 4 and row 6 both have spaces):

     

    You may add steps in Power Query as below.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlRwVHBWitWJVjJScFFwA7OMFVwV3MEsBTBpquCh4AnhAwViAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
        Custom1 = Table.ReplaceValue(#"Changed Type"," ","",Replacer.ReplaceText,{"Column1"}),
        Custom2 = Table.AddColumn(Custom1,"Custom2",each if Text.Length([Column1])=0 then null else [Column1]),
        #"Removed Columns" = Table.RemoveColumns(Custom2,{"Column1"})
    in
        #"Removed Columns"

     

    Result:

     

    Best Regards

    Allan

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.