Straight to the "issue".
I got one "simple" task to try to solve in Power BI > Power Query, where I got one mixed column supposed to be an Amount column, with lot of different number/text/special chars combinations, which have to be firstly converted into number format and then conditionally calculated if there is "brutto (no case sensitive) in general", then divide that value with 1.5 and if there is CHF value divide that value with 1.9. The rest of data, like errors, #values or even nulls can be removed. Expected column is shown as OnlyAmountNr and in my Query steps.
This is short example of my data:
| Amount | OnlyAmountNr |
|-----------------|--------------|
| Brutto ? 468384 | 468384 |
| 965- | 965 |
| 703623 brutto | 703623 |
| 654-? Netto | 654 |
| ?1738 | 1738 |
| CHF 12800.0 | 12800 |
| #VALUE! | - |
| 89989 | 89989 |
| 0 | 0 |
What I used, at least to my knowledge are these steps,which might be too long for this kind of task:
let
Quelle = Sql.Databases("ukTest123.database.windows.net"),
CSD_DE_RawData = Quelle{[Name="CSD_DE_RawData"]}[Data],
money_ASD_Applications =
CSD_DE_RawData{[Schema="money",Item="ASD_Applications"]}[Data],
EXTRACT_SPECIAL_CHARS = Table.AddColumn(money_ASD_Applications, "Custom1", each Text.Select([Amount],{"A".."z","0".."9"})),
EXTRACT_NUMBERS = Table.AddColumn(EXTRACT_SPECIAL_CHARS, "Custom2", each Text.Select([Custom1],{"a".."z","A".."Z"})),
EXTRACT_T_F = Table.AddColumn(EXTRACT_NUMBERS, "Boolean", each if Text.Contains([Custom1], "brutto") then true else if Text.Contains([Custom1], "Brutto") then true else false),
EXTRACT_TEXT = Table.AddColumn(EXTRACT_T_F, "OnlyAmountNr", each Text.Remove([Custom1],Text.ToList(Text.Remove([Custom1],{"0".."9"})))),
#"Changed Type" = Table.TransformColumnTypes(EXTRACT_TEXT,{{"OnlyAmountNr", type number}}),
#"CALCULATION_MwSt." = Table.AddColumn(#"Changed Type", "MwSt._CH_DE", each if [OnlyAmountNr]> 1 and [Boolean]= true then ([OnlyAmountNr]/1.199) else if [OnlyAmountNr]>1 and [Custom2]="CHF" then ([OnlyAmountNr]/1.077) else null)
in
#"CALCULATION_MwSt."