Reputation: 119
I'm trying to add leading zeros into a column in power query call JobCodes. I know I can do this by adding a new column using Text.Start([JobCodes],5,"0")
, but I don't want to add a new column and go back to remove the column I don't need. I want to be able to do this in one step using Table.TransformColumns
function. Is this possible?
Table.TransformColumns(#"Changed Type", each Text.PadStart([JobCodes],5,"0"))
Expression.Error: We cannot convert a value of type Function to type List. Details: Value=Function Type=Type
Upvotes: 3
Views: 11399
Reputation: 1
The correct expresion is:
= Table.TransformColumns(#"Changed Type",{{"JobCodes", each Text.PadStart(Text.From( _), 6, "0"), type text}})
Upvotes: 0
Reputation: 21298
Or
= Table.ReplaceValue( Source, each [JobCodes] ,each Text.PadStart(Number.ToText([JobCodes]),5,"0") ,Replacer.ReplaceValue,{"JobCodes"})
in Replace
Upvotes: 0
Reputation: 40204
Your syntax is just a bit off.
I think this is what you want:
= Table.TransformColumns(#"Changed Type",{{"JobCodes", each Text.PadStart(_, 5,"0")}})
The error is because it was expecting a list of columns that you want to transform (notice the {{...}}
above.
The easiest wat to get the syntax right is to use the GUI to do a transformation and then just edit the function a bit. For example, you could use Format > Add Prefix which would give you the following step (assuming you choose to prefix 000
).
= Table.TransformColumns(#"Changed Type", {{"JobCodes", each "000" & _, type text}})
Just take out the "000" & _
and put in the transformation you actually want.
Upvotes: 7