PDA

View Full Version : PQ - Extract numbers from column with condition



sandy666
02-14-2021, 01:53 AM
(question from the web (https://www.mrexcel.com/board/threads/neer-help-on-power-query-nested-if-statement.1161540/))

If cell contains "Cr" then remove "Cr" and multiply by -1


SourceResult

rawNumber


100
100


200
200


300
300

400 Cr
-400


500
500


600
600

200 Cr
-200


let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
Text = Table.TransformColumnTypes(Source,{{"raw", type text}}),
Number = Table.AddColumn(Text, "Number", each try Number.From([raw]) otherwise Number.From(Text.Select([raw],{"0".."9"})) * -1),
RC = Table.RemoveColumns(Number,{"raw"})
in
RC