Home > Enterprise >  Extract Decimal Numbers From A List In Power Query
Extract Decimal Numbers From A List In Power Query

Time:11-24

I am trying to extract the decimal numbers from a string. I have a working solution, but i think it can be done in a better way,

enter image description here


The following M-Code does the work,

let
    Source = Excel.CurrentWorkbook(){[Name="Table21"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.FindText(Text.Split([Column1]," "),".")),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Custom", type number}}),
    #"Removed Errors" = Table.RemoveRowsWithErrors(#"Changed Type1", {"Custom"})
in
    #"Removed Errors"

But I want to extract the decimal numbers from the list

enter image description here


What should I add before

List.FindText(Text.Split([Column1]," "),".")

To extract only the decimal numbers.


Column1 Expected Output
100298 - 6000.2581 NG Migration & Dismantling Add 6000.2581
101536 - 6000.2578 NG Migration & Dismantling CS 6 6000.2578
101944 - 6000.2578 NG Migration & Dismantling CS 6 6000.2578
102209 - 6000.2578 NG Migration & Dismantling CS 6 6000.2578
102856 - 6000.2581 NG Migration & Dismantling Add 6000.2581
8000.8500 - car bus bicztytr 8000.8500
8000.7072 ertefg gfhfjfgj fghfgh 8000.7072
8000.7075 fghgfhg gfhhgjjses 8000.7075
8000.7076 rtretretre ter gdb v dffbdtbt 8000.7076
8000.7077 wqe ret gfn vbogf 8000.7077
8000.8181 gfhg(per lic. for UL900) 8000.8181
8000.8254 Mgfhghhode Licenses 8000.8254
8000.8254 Multi-mgfhghgode Licenses 8000.8254
gfhg(per lic. for UL900) 8000.8181 8000.8181
gfhg(per lic. for UL900) 8000.8181 8000.8181

CodePudding user response:

enter image description here

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nc9PS8MwGMfxt/JjJwU30tik6VEUvGxexNPcYWn NKVrNU0n upNN3QrIkohp/D5Js zXs8SQmguMAcnhCwoEwke7rFy1m Daxs89xFw3Llut21C7RqLG6Vmm6shTdg1P6WZ DO9fQT/avM0ndpSSvLJrWB80rpiKAQjJNbF1kP2HaQrPsJ78CeQkYxC 6CNhTWlqYytYGwZzwix4TKCgyptVXW6GwEOH7w HgTtYZXEHsoYqYIMI5vh7VUj0vhYg71srTkbOYlLDj9dvMRXalcsYFqPp2VOyOUZoyzFanBl2SqNpSt0MxrqKPo6uPnu4OwP99s3 J7k32zzCQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),

    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each   List.RemoveItems ( List.Transform( List.FindText(Text.Split([Column1]," "),"."), each Text.Select(_, {"0".."9", "."})) , {"."}){0}, type number )
in
    #"Added Custom"
  • Related