Forum Discussion
Double if statement in custom column
- 2 years ago
Hi Janosa ,
The basic Power Query (M) structure for an IF statement is as follows:
if SomethingIsTrue then DoThisThing else if ThisOtherThingIsTrue then DoThisIntead else EscapeActionIfAllConditionsFalse // i.e. if..then..else if..then..else // No brackets, no capitalsThe conditions get evaluated in order, top to bottom, so you need to be clear about what you want to be checked and when.
Based on the above, your new query step might look something like this:
#"Added Custom" = Table.AddColumn( #"Expanded Average weight", "Correct weight", each if [transactioncode] = "86" then -[weight] else if [Weight kg] = 0 and Text.Contains([Product], "something") then [Average] else [Weight kg] )Also make sure that your [transactioncode] column is actually Text data type, otherwise you need to remove the quotes from "86".
Pete
Hi Janosa ,
The basic Power Query (M) structure for an IF statement is as follows:
if SomethingIsTrue then DoThisThing
else if ThisOtherThingIsTrue then DoThisIntead
else EscapeActionIfAllConditionsFalse
// i.e. if..then..else if..then..else
// No brackets, no capitals
The conditions get evaluated in order, top to bottom, so you need to be clear about what you want to be checked and when.
Based on the above, your new query step might look something like this:
#"Added Custom" =
Table.AddColumn(
#"Expanded Average weight",
"Correct weight",
each if [transactioncode] = "86" then -[weight]
else if [Weight kg] = 0 and Text.Contains([Product], "something") then [Average]
else [Weight kg]
)
Also make sure that your [transactioncode] column is actually Text data type, otherwise you need to remove the quotes from "86".
Pete