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
JimT99
Helper I
Helper I

Create Calculated Column using column value as variable in where clause

DAX_CALC.png


I want to create a calculated column in one table (call it TableA) that Calculates a value from another table (TableB) based on column value in TableA

ProdMax = CALCULATE(MAX(TABLEB[Value]) WHERE TABLEA[PRODUCT] = TABLEB[PRODUCT]

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

Try this:

ProdMax =
VAR _Prod = TABLEA[PRODUCT]
RETURN
    CALCULATE ( MAX ( TABLEB[Value] ), TABLEB[PRODUCT] = _Prod )

 

Other variations:

ProdMax =
CALCULATE (
    MAX ( TABLEB[Value] ),
    TABLEB[PRODUCT] = EARLIER ( TABLEA[PRODUCT] )
)
ProdMax =
MAXX (
    FILTER ( TABLEB, TABLEB[PRODUCT] = TABLEA[PRODUCT] ),
    TABLEB[Value]
)

 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

I replicated your data. Solution is as follows. Create a relationship between table A and B based on the product field. Then create a measure : 

MAX VALUE = CALCULATE(MAX('Table B'[Value])). After create a table with the MAX Value measure, and product field from TABLE A.
 
Power5_1-1700001140530.png

 

Power5_0-1700001055366.png

 

AlexisOlson
Super User
Super User

Try this:

ProdMax =
VAR _Prod = TABLEA[PRODUCT]
RETURN
    CALCULATE ( MAX ( TABLEB[Value] ), TABLEB[PRODUCT] = _Prod )

 

Other variations:

ProdMax =
CALCULATE (
    MAX ( TABLEB[Value] ),
    TABLEB[PRODUCT] = EARLIER ( TABLEA[PRODUCT] )
)
ProdMax =
MAXX (
    FILTER ( TABLEB, TABLEB[PRODUCT] = TABLEA[PRODUCT] ),
    TABLEB[Value]
)

 

Why does  STDEV.P not workin place of MAX

Prodstd =
CALCULATE (
    STDEV.P ( Query1_TSP[Value] ),
    Query1_TSP[Att_BatchDesc] = EARLIER ( SPECS_BATCHDESC_ATTRIBUTE[Att_BatchDesc] ))

I tried your 2nd suggestion and it worked.  Thank YOU!!

Anonymous
Not applicable

You need to create a relationship between the two tables. In my response you can see how it is achieved. @AlexisOlson  measures work great but you need to get the relationship down for it all to be tied in together.

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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