Forum Discussion
Simple m query code question: custom column showing that outputs Wk - 01 (Week 1)
I already have the Week Number column. And it currently just shows a numeric value which is fine.
I want to add a custom column that ouputs: Wk - 01 (etc)
My attempt below did not work. Essentially, the new column should just concatenate the string "Wk" + the week number from the week number column.
= Table.AddColumn(#"Renamed Columns1", "Custom", each text.combine({"Wk" & " " &,)[Week Number])
Text.Format doesn't seem to support leading zeros.
= Table.AddColumn(#"Renamed Columns1", "Custom", each Text.Format("Wk - #{0}",{[Week Number]}))So this won't work. The standard brute force method would be:
= Table.AddColumn(#"Renamed Columns1", "Custom", each "Wk - " & Text.End("0" & Text.From([Week Number]),2))
5 Replies
- lbendlinSuper User
Text.Format doesn't seem to support leading zeros.
= Table.AddColumn(#"Renamed Columns1", "Custom", each Text.Format("Wk - #{0}",{[Week Number]}))So this won't work. The standard brute force method would be:
= Table.AddColumn(#"Renamed Columns1", "Custom", each "Wk - " & Text.End("0" & Text.From([Week Number]),2))- AnonymousNot applicable
lbendlin Thanks...worked perfectly!
- AnonymousNot applicable
lbendlin I think I spoke to soon. It did give me the correct column format, but it creates a column with the "table" in the column that you then have to expand. Upon doing so it increases the amount of rows exponentially (with duplicates). Any suggestions on how to fix?
- lbendlinSuper User
You may be adding other transforms that result in a table rather than a single value. Can you show the full sample code?