Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
nellyvk
New Member

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 

nellyvk_0-1715184322065.png

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

nellyvk_1-1715184439723.png

 

Any suggestions?

1 ACCEPTED SOLUTION
v-zhengdxu-msft
Community Support
Community Support

Hi @nellyvk 

 

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

I create a set of sample:

vzhengdxumsft_0-1715221685717.png

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:

vzhengdxumsft_1-1715221715077.png

 

 

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.

View solution in original post

2 REPLIES 2
v-zhengdxu-msft
Community Support
Community Support

Hi @nellyvk 

 

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

I create a set of sample:

vzhengdxumsft_0-1715221685717.png

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:

vzhengdxumsft_1-1715221715077.png

 

 

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.

amitchandak
Super User
Super User

@nellyvk , 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])

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.