Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Comparison operator saved in Cell - How to use?

Hi all,

 

I have two columns that I need to compare and the comparison operator is saved in a third column. I am not sure how to write the query to use the operator that is saved in the cells 

I tried using COMBINEVALUES but it return the whole thing as a string, rather than doing the operation

 

Any suggestions?

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous 

     

    Thanks for the reply from amitchandak , please allow me to provide another insight:

    I create a set of sample:

    Then add a calculate column:

    Column =
    SWITCH (
        TRUE (),
        'Table'[Value1] > 'Table'[Value2]
            && FIND ( ">", 'Table'[Operator],, BLANK () ) <> BLANK (), "True",
        'Table'[Value1] = 'Table'[Value2]
            && FIND ( "=", 'Table'[Operator],, BLANK () ) <> BLANK (), "True",
        'Table'[Value1] < 'Table'[Value2]
            && FIND ( "<", 'Table'[Operator],, BLANK () ) <> BLANK (), "True",
        "False"
    )
    

     The result is as follow:

     

     

    Best Regards

    Zhengdong Xu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • Anonymous , Try Expression.Evaluate in power query

    New column in power query, assuming you have three columns with col2 as CheckParameter

    Expression.Evaluate([Col1] & " " & [CheckParameter] & " " & [Col3])

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous 

     

    Thanks for the reply from amitchandak , please allow me to provide another insight:

    I create a set of sample:

    Then add a calculate column:

    Column =
    SWITCH (
        TRUE (),
        'Table'[Value1] > 'Table'[Value2]
            && FIND ( ">", 'Table'[Operator],, BLANK () ) <> BLANK (), "True",
        'Table'[Value1] = 'Table'[Value2]
            && FIND ( "=", 'Table'[Operator],, BLANK () ) <> BLANK (), "True",
        'Table'[Value1] < 'Table'[Value2]
            && FIND ( "<", 'Table'[Operator],, BLANK () ) <> BLANK (), "True",
        "False"
    )
    

     The result is as follow:

     

     

    Best Regards

    Zhengdong Xu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.