Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Column with text and numbers

I have a column formated as text with 2 types of data. 1) 12345 and 2) AB123. Now I am looking for a way to have in another column the Values of 1 as values and the first 2 letters of 2 as text. It is needed to make a connection to another table in which the values and the letters are connected to cities.

 

An idea is welcome.

  • Anonymous's avatar
    Anonymous
    7 years ago

    My solution was:  

    to get the value in a new Column:

    ProductValue = VALUE(database[column])
    and for the first 2 letters
    ProductID = LEFT(database[column];2)
     
    Very simple but it it does what is needed.
     

2 Replies

  • v-juanli-msft's avatar
    v-juanli-msft
    Community Support

    Hi Anonymous 

    If i understand you correct, you want

    column         ->   column1   column2

    12345                  12345        AB

    AB123

     

    If so, in Edit queries,

    1. add two column

    2.Replace errors with null

    3.add conditional column

    4.Fill down for "Custom" column

    5.Filter Rows which is null for 'Custom.1"

    6. remove columns

     

    Then Whole code in Advanced editor

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNjFVitWJVnJ0ArLBLEMjE1MzMMvZBchWio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [column = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"column", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Number.FromText([column])),
        #"Inserted First Characters" = Table.AddColumn(#"Added Custom", "First Characters", each Text.Start([column], 2), type text),
        #"Replaced Errors" = Table.ReplaceErrorValues(#"Inserted First Characters", {{"Custom", null}}),
        #"Added Conditional Column" = Table.AddColumn(#"Replaced Errors", "Custom.1", each if [Custom] = null then 1 else null),
        #"Filled Down" = Table.FillDown(#"Added Conditional Column",{"Custom"}),
        #"Filtered Rows" = Table.SelectRows(#"Filled Down", each [Custom.1] <> null and [Custom.1] <> ""),
        #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"column", "Custom.1"})
    in
        #"Removed Columns"

    Best Regards
    Maggie

     

    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Anonymous's avatar
      Anonymous
      Not applicable

      My solution was:  

      to get the value in a new Column:

      ProductValue = VALUE(database[column])
      and for the first 2 letters
      ProductID = LEFT(database[column];2)
       
      Very simple but it it does what is needed.