Forum Discussion

Gauravshahin's avatar
Gauravshahin
Frequent Visitor
1 year ago
Solved

Text.AfterDelimiter in transformation step did not change column type

Hi Experts, I used = Table.TransformColumns(#"Unpivoted Columns", {{"FcstWK", each Text.AfterDelimiter(_, "k"), type number}}) to extract Week Numbers from below column. Durinng this step, I specif...
  • PhilipTreacy's avatar
    1 year ago

    Gauravshahin 

     

    What seems to be happening is that the data is transformed to a number, but the type of the column remains as text, so the numbers are treated as text.  I can't tell you why it's doing this as it seems wrong.

     

    Even if you do this

     

    each Number.From(Text.AfterDelimiter(_, "k"))

     

    the column is still an ANY type (ABC 123) rather than number.  Seems that PQ is treating the column type and the data in the column as different types.  A bug?  Or by design?  I don't know why you'd have a column of one type and the data within treated as a different type.

     

    Phil

  • Gauravshahin's avatar
    Gauravshahin
    1 year ago

    Thank you for your reply @PhilipTreacy.
    I have done the work around and it seems to be working for now.
    Since we now know that, output from Text.AfterDelimiter(_, "k") will always be ANY, I nested it with Number.FromText and specify column type as Number.


    = Table.TransformColumns(#"Unpivoted Columns", {{"FcstWK", each Number.FromText(Text.AfterDelimiter(_, "k")), type number}})

    However, I am still unsure why Table.TransformColumns is not converting it to number.

     

     

    Preview