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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Irwin
Helper IV
Helper IV

Compare value from a columns to another column with conditions?

Hi all,

I am sorry if the title is confusing. I am not entirely sure how to correctly label my question.

I have two tables. I want to compare a value from the first table (ie. temperature) to the "max value" from the other table.

Here I need to also consider that there is different max values related to distributor/product code.

 

I would like the output to be.

"IF(Temperature from table one > max temperature from table two then 1 eller 0)"

However I need the measure to somehow check

table ones distributor and product code to match table two as there are different max values.

 

Table 1   
Distributor Product code Protein Temperature
114,312,2
125,511,4
135,311,7
213,912,1
22514,2
324,316,2
335,110,5
414,811,2
443,717,2

 

Table 2   
Distributor Product code Protein max Temperatur max
11513
12513
13613
21613
22513
32513
33612
41513
44414

 

Any help is appreciated 🙂

1 ACCEPTED SOLUTION

It shouldn't be using SELECTEDVALUE as it is a column not a measure, that's my mistake.

Temperature comparison = 
VAR ProductCode =
    'Table1'[ Product code]
VAR Distributor =
    'Table1'[Distributor]
VAR Temperature =
    'Table1'[ Temperature] 
VAR T2Temp =
    CALCULATE (
        MAX ( 'Table2'[ Temperatur max] ),
        TREATAS (
            { ( ProductCode, Distributor ) },
            'Table2'[ Product code],
            'Table2'[Distributor]
        )
    )
RETURN
    IF ( Temperature > T2Temp, 1, 0 )

View solution in original post

4 REPLIES 4
johnt75
Super User
Super User

Try

Temperature comparison =
VAR ProductCode =
    SELECTEDVALUE ( 'Table1'[Product code] )
VAR Distributor =
    SELECTEDVALUE ( 'Table1'[Distributor] )
VAR Temperature =
    SELECTEDVALUE ( 'Table1'[Temperature] )
VAR T2Temp =
    CALCULATE (
        MAX ( 'Table2'[Temperature] ),
        TREATAS (
            { ( ProductCode, Distributor ) },
            'Table2'[Product code],
            'Table2'[Distributor]
        )
    )
RETURN
    IF ( Temperature > T2Temp, 1, 0 )

Thank you so much for your reply! I think you might be on to something, but unfortunately this just gives "0" for all values.

 

Irwin_0-1674816549797.png

 

It shouldn't be using SELECTEDVALUE as it is a column not a measure, that's my mistake.

Temperature comparison = 
VAR ProductCode =
    'Table1'[ Product code]
VAR Distributor =
    'Table1'[Distributor]
VAR Temperature =
    'Table1'[ Temperature] 
VAR T2Temp =
    CALCULATE (
        MAX ( 'Table2'[ Temperatur max] ),
        TREATAS (
            { ( ProductCode, Distributor ) },
            'Table2'[ Product code],
            'Table2'[Distributor]
        )
    )
RETURN
    IF ( Temperature > T2Temp, 1, 0 )

That worked! Thank you so much! Appreciated 🙂

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors