March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello all,
This custom column is already working except i want to add another if statement.
#"Added Custom" = Table.AddColumn(#"Expanded Average weight", "Correct weight", each if( [Weight kg] = 0 and Text.Contains([Product], "something") )then [Average] else [Weight kg])
I want to add if([transactioncode] ="86") then [weight] ....i want the weight to be negative but i'm clueless on how to add this to the query. Can you please help me with this?
Thanks and regards
Solved! Go to Solution.
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
Proud to be a Datanaut!
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
Proud to be a Datanaut!
Hello Pete,
thanks for the info, worked like a charm and I learned something new today.
regards
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
21 | |
16 | |
13 | |
13 | |
9 |
User | Count |
---|---|
36 | |
31 | |
20 | |
19 | |
17 |