Forum Discussion
Tony2021
Oct 25, 2021Iron Contributor
Power Query If Statement
Hello, I am having difficulty updating the field [Amt_New] in the Append Query based on some conditions. If [Amt1] is 0 and [Amt2] is 0 then leave [Amt_New] as is (no change). basically leave t...
- Oct 25, 2021
If I understood the logic of source correctly only one of AMT1, AMT2, AMT_New is not zero, thus you may simply sum them and replace with result AMT_New. Plus I'd clean the query, too many unnecessary steps
let Source = Table.Combine({Stampli_PQ, SAP_PQ_Drill_mod, SAP_PQ_Not_DD, BOA_PQ_mod}), #"Removed Other Columns" = Table.SelectColumns(Source,{"Vendor", "Amount Currency", "Payment Date", "Co Name", "Amount", "Amt", "Amt_NEW"}), #"Replaced Value" = Table.ReplaceValue(#"Removed Other Columns",null,0,Replacer.ReplaceValue,{"Amt", "Amt_NEW", "Amount"}), #"Changed Type" = Table.TransformColumnTypes(#"Replaced Value",{{"Amount", Currency.Type},{"Amt_NEW", Currency.Type}, {"Amt", Currency.Type}}), #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Amount", "Amt1"}, {"Amt", "Amt2"}}), #"Replaced Value1" = Table.ReplaceValue(#"Renamed Columns",each [Amt_NEW],each List.Sum({ [Amt1], [Amt2], [Amt_NEW] }) ,Replacer.ReplaceValue,{"Amt_NEW"}), #"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value1",{{"Amt_NEW", Currency.Type}}) in #"Changed Type1"
Tony2021
Oct 25, 2021Iron Contributor
Very nice. I didnt think of that strategy. Crafty. thanks guys. I really appreciate the insight.
SergeiBaklan
Oct 25, 2021Diamond Contributor
Tony2021 , glad to help