Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

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

  • 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))
    • Anonymous's avatar
      Anonymous
      Not applicable

      lbendlin   Thanks...worked perfectly!

    • Anonymous's avatar
      Anonymous
      Not 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?

      • lbendlin's avatar
        lbendlin
        Super User

        You may be adding other transforms that result in a table rather than a single value. Can you show the full sample code?