Forum Discussion
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" ETFE | DN 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):
- Double/ triple spaces need to be removed
- Length required is “/” -1
- “2.5” needs to be recognized as “2,5”
- 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
- AnonymousNot 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
Community 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
Post 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
Community Champion
In the Transform tab, under Format there is Trim you can apply to columns - does it work for you as expected?
- ahmedoye
Responsive Resident
Orstenpowers here's what i would do:
- Right click on the column, replace values to replace "." with ","
- Right click on the column, replace " /" (space and /) with "*/" (asterisk)
- Right click on the column>>Split column by delimiter>>at the first occurrence using */ as the delimiter.
- Right click on the column, replace "*" with nothing.
If this answers your question, kindly mark as solution.
- ziying35
Impactful Individual
= Table.AddColumn(Source,"extract", each Text.Combine(List.FirstN(Splitter.SplitTextByWhitespace()([txt]),2)," "))See if my code works