Forum Discussion

Orstenpowers's avatar
Orstenpowers
Icon for Post Patron rankPost Patron
6 years ago

Trim, length and text to figure

Dear all,


While working on an exhaustive database, I had to recognize that the data I had been provided with, are of worse quality than expected.

Actually I do have a column “DN” (formatted as text) that contains data looking as follows:

 

DN 1200 / 48"DN 1200
DN 1200 / 48"       ETFEDN 1200
DN 125 / 5"DN 125
DN 1400 / 56"DN 1400
DN 150  /   6"DN 150
DN 150 / 6"DN 150
DN 1600 / 64"DN 1600
DN 1800 / 72"DN 1800
DN 2.5  /  1/10"DN 2,5
DN 2.5 / 1/10"DN 2,5

 

The complete list currently consists of 102 different wordings (left column) that could be reduced to 31 (right column). I just checked this with Excel.

 

As you can see, sometimes there are also double/ triple spaces. I learned that these could be removed with “Trim”!?

However, my request is more complicated.

What I can recognize is that following actions are required (exceeding my skills by far):

 

  1. Double/ triple spaces need to be removed
  2. Length required is “/” -1
  3. “2.5” needs to be recognized as “2,5”
  4. Figures to be recognized as such, allowing me to sort them.

 

Is there anybody out there to help with a custom column or something similar that I can implement? I am lost. 😥

 

20 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Maybe not the most sexy solution (or at all), but you could try the following:

     

    1) Split the column at each occurence of SPACE

    2) Replace .(dot) with ,(comma) in the column that end up containing for example 2.5

    3) Create a Custom Column with the following M expression --> [DN]&" "&[2,5] --> DN and 2,5 must be replaced with the name of the column containing these values

     

    This is based on the assumption that your uotput should be like the column to the right, and the format before / is the same for all rows.

     

  • Stachu's avatar
    Stachu
    Icon for Community Champion rankCommunity Champion

    Try the following:

    1) Select column DN

    2) In 'Add Column' tab, press 'Column From Examples'

    3) Start typing DN 1200 in the first row, it should suggest Text Before Delimiter transformation, if not move to second row and type it again

    4) Press OK, it should generate following formula (#"Changed Type" is previous step name, most likely will be different in your case):

    = Table.AddColumn(#"Changed Type", "Text Before Delimiter", each Text.BeforeDelimiter([DN], " ", 1), type text)

     5) Select the new column, go to Transform tab and use Replace Values to convert '.' to ','

    • Orstenpowers's avatar
      Orstenpowers
      Icon for Post Patron rankPost Patron

      Dear Stachu,

       

      Thanks for your reply!

      It looks quite good, but does your proposal consider the double/ triple spaces that the original column could consist of?

      Looking forward to hearing from you I remain

      • Stachu's avatar
        Stachu
        Icon for Community Champion rankCommunity Champion

        In the Transform tab, under Format there is Trim you can apply to columns - does it work for you as expected?

  • ahmedoye's avatar
    ahmedoye
    Icon for Responsive Resident rankResponsive Resident

    Orstenpowers  here's what i would do:

    1. Right click on the column, replace values to replace "." with ","
    2. Right click on the column, replace " /" (space and /) with "*/" (asterisk)
    3. Right click on the column>>Split column by delimiter>>at the first occurrence using */ as the delimiter.
    4. Right click on the column, replace "*" with nothing.

    If this answers your question, kindly mark as solution.

  • ziying35's avatar
    ziying35
    Icon for Impactful Individual rankImpactful Individual
    = Table.AddColumn(Source,"extract", each Text.Combine(List.FirstN(Splitter.SplitTextByWhitespace()([txt]),2)," "))

    See if my code works