I have a column with quantity and UOM attach and are irregular size based on quantity and UOM. what would be the best way to split them
example if one row has 1.055gt and another row has 71.641gal
Hi Bill,
If you always have numbers first, you can try this method:
Add a new column with this formula:
=List.Max(Text.PositionOfAny([Text],{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}, Occurrence.All))+1
This will return the position of the last number from Text column.
Step 2: go to Add Column tab, Extract-Range, type 0 and 2 for those required parameters, the step will look like:
each Text.Middle([Text], 0, 2), where the last parameter is the number of chars we need, this should be dynamic, we will change this to:
each try Number.FromText(Text.Middle(Text.From([Text]), 0, [Custom])) otherwise null
As you can see, we passed the [Custom] column to indicate the dynamic number of chars we need to extract. I also wrapped this formula into Number.FromText formula, to try converting the result to a number, if this fails, we need to return null, to have only numbers in that column.
I there is no number in that column, and you want to return the original text, use:
each Text.Middle(Text.From([Text]), 0, [Custom])
In this case, you will have a mixed type column, with both text and numbers, which is not recommended.
The query should look like this:
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Custom", each List.Max(Text.PositionOfAny([Text],{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}, Occurrence.All))+1),
#"Inserted Text Range" = Table.AddColumn(#"Added Custom", "Text Range", each try Number.FromText(Text.Middle(Text.From([Text], "en-AU"), 0, [Custom])) otherwise null, type text),
#"Changed Type" = Table.TransformColumnTypes(#"Inserted Text Range",{{"Text Range", type number}})
in
#"Changed Type"