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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
GiveMeArrays
Frequent Visitor

Correct Syntax for Table.TransformColumns + Text.Length + Text.Combine

Please help with syntax guidance for the following M code:

 

= Table.TransformColumns( #"table" , { "column", each if Text.Length(_) = 4 then _ else Text.Combine( {"0",_} ) } )

 

Result: Expression.Error: A cyclic reference was encountered during evaluation.

 

In short, the "column" within "table" stores four digit numbers as text for IDs. However, some three digit IDs need a zero appended to the front of the string (e.g., 0123). The formula above is attempting to fix that.

 

Dozens of edits have brought me this far, so maybe it's conceptual at this point, rather than syntax?

 

Thank You!

1 ACCEPTED SOLUTION
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @GiveMeArrays - You could consider using Text.PadStart like this:

DarylLynchBzy_0-1661541440441.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI3VorViVYyNjExBTNMjYxNYSJg2sRIKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}}),
    #"Added to Column" = Table.TransformColumns(#"Changed Type", {{"Column1", each Text.PadStart( Text.From(_) ,4 , "0" ) , type text }})
in
    #"Added to Column"

 

View solution in original post

1 REPLY 1
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @GiveMeArrays - You could consider using Text.PadStart like this:

DarylLynchBzy_0-1661541440441.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI3VorViVYyNjExBTNMjYxNYSJg2sRIKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}}),
    #"Added to Column" = Table.TransformColumns(#"Changed Type", {{"Column1", each Text.PadStart( Text.From(_) ,4 , "0" ) , type text }})
in
    #"Added to Column"

 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors