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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
umaluagr
New Member

Replace letters with null

Hi community

 

Is there a possibility to replace letters in a column with "null"?

 

I have a column that contains rows with letters and rows with numbers. I want to replace only rows with letters with a null value.

e.g.

ABC

123

DEF

234

 

should result in

null

123

null

234

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @umaluagr, add this as a new step.

 

Replace

  • Source with your previous step reference
  • [Column1] with your [ColumnName]
  • "Column1" with your "ColumnName"

dufoq3_0-1714378508112.png

 

= Table.ReplaceValue(Source,
        each try Number.From([Column1]) otherwise false is number,
        each null,
        (x,y,z)=> if y then x else z,
        {"Column1"} )

 

Whole code with sample data:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKVorViVYyNDIG045OzmDaxNRMKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source,
        each try Number.From([Column1]) otherwise false is number,
        each null,
        (x,y,z)=> if y then x else z,
        {"Column1"} )
in
    #"Replaced Value"

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

1 REPLY 1
dufoq3
Super User
Super User

Hi @umaluagr, add this as a new step.

 

Replace

  • Source with your previous step reference
  • [Column1] with your [ColumnName]
  • "Column1" with your "ColumnName"

dufoq3_0-1714378508112.png

 

= Table.ReplaceValue(Source,
        each try Number.From([Column1]) otherwise false is number,
        each null,
        (x,y,z)=> if y then x else z,
        {"Column1"} )

 

Whole code with sample data:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKVorViVYyNDIG045OzmDaxNRMKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source,
        each try Number.From([Column1]) otherwise false is number,
        each null,
        (x,y,z)=> if y then x else z,
        {"Column1"} )
in
    #"Replaced Value"

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors
Top Kudoed Authors