Column Expressions - IF inside the true values? It's possible?

Hi friends

I’m always use column expressions for my IF statements.

It’s possible to use another IF inside de True value brackets?

For example:

if (column("@CalculosPorFora") == "SIM" && column("CFOP_Ficha3") == "5405" && column("BC") == 1)
 column("vProd")+column("vFrete")+column("vSeg")-column("vDesc")+column("vOutro") * if (column("ICMS") > 0 {column("ICMS")} else {column("ICMS_ST")})

It’s possible to see that I’m trying to use another IF inside the true value.
I’m trying to reduce the IFs inside the rule, and trying the approach like Excel IF formulas.

In JavaScript, which the Column Expression essentially is, you cannot use the if inline like you do here (and which works in Python). Instead, you can use the ternary operator:

column("vProd")+column("vFrete")+column("vSeg")-column("vDesc")+column("vOutro") * 
(column("ICMS") > 0 ? column("ICMS") : column("ICMS_ST"))

Alternatively, you could first assign either column(“ICMS”) or column(“ICMS_ST”) to a separate variable based on a normal if, then use that variable inside your expression:

if (column("@CalculosPorFora") == "SIM" && column("CFOP_Ficha3") == "5405" && column("BC") == 1)
    var icms = column("ICMS");
    if (column("ICMS") <= 0) {
        icms = column("ICMS_ST")
    column("vProd")+column("vFrete")+column("vSeg")-column("vDesc")+column("vOutro") * icms

Kind regards,


Hi Alexander,
Sorry for the late answer.

I tried the code.
The column expression node doesn’t give error, but return missing values.

I did correct?

I see the link ternary operator but, I seams that columns expressions doesn’t accept similar terms, like “const” instead of “var”

It looks correct, but if your ifs do not match, then a missing value is returned. Can you make sure that your conditions are correct? You can also try removing conditions step-by-step and see when you get an output.
Kind regards,

It Worked

The column test result exactly the column on the left.

I always wanted to know if column expressions could do calculations with VAR statements, but I had never found anything on the forum. I use VAR in DAX PBI.

You solved my problem and taught me something new.
Very cool.
Thank you very much. :fist_right: :sparkles: :fist_left:

1 Like

A post was split to a new topic: IN operator in Column Expression node

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.