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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
max_mustermann
Frequent Visitor

How to remove rows based on text length

I want to delete all rows of Column "test" which contain less than 4 characters.

 

E.g. "132" should be removed, "testtest" should not be removed.

 

I have tried the following in M but there is a syntax error:

 

= if Text.Length([test]) <4 then Table.RemoveRows(Table.FromRecords,1)

 

1 ACCEPTED SOLUTION
mahenkj2
Solution Sage
Solution Sage

Hi @max_mustermann ,

 

I can just tell you alternate way, since you are already checking Text.Length, just filtering records <4 or >3 will serve the purpose:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ2UorViVYqSS0uAWGl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [test = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"test", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Test-Length", each Text.Length([test])),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Test-Length", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type1", each [#"Test-Length"] > 3)
in
    #"Filtered Rows"

View solution in original post

1 REPLY 1
mahenkj2
Solution Sage
Solution Sage

Hi @max_mustermann ,

 

I can just tell you alternate way, since you are already checking Text.Length, just filtering records <4 or >3 will serve the purpose:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ2UorViVYqSS0uAWGl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [test = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"test", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Test-Length", each Text.Length([test])),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Test-Length", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type1", each [#"Test-Length"] > 3)
in
    #"Filtered Rows"

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.