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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Bala16
Frequent Visitor

How to calculate Min or Max based on another table column value

I have a scenario like this. There are two tables TableA and TableB and linked with M:M relationships.

TableA has columns ID and Value

ID Value
a 10
a 20
a 5
b 10
b 20
b 3

TableB has many columns, but only two columns are used in the matrix chart

ID product
a X1
a X2
b X1
b X2

The requirement for the matrix chart is to show MIN(TableA[Value]) if TableB[Product] = X1, if its value = X2, then show Max(TableA[Value]).

The Matrix chart should look like this

ID Product calculated value
a X1 Min value
X2 Max value
b X1 Min value
X2 Max value

I could create measures to calculate Min and Max. But, I couldn't find the way to check X1 or X2 to show corresponding calculated value.

Please anyone can help me

3 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Bala16 , new column in Table B

 

= If ([Product] = "X1", minx(filter(TableA, TableA[ID] = TableB[ID]), TableA[Value]) ,  maxx(filter(TableA, TableA[ID] = TableB[ID]), TableA[Value]) )

 

or

 

= If ([Product] = "X1", min( TableA[Value]) ,  max( TableA[Value]) )

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

MasonMA
Community Champion
Community Champion

Hi, 

 

I'd suggest reshaping your TableA a bit in Power Query to make the relationship between TableA and TableB one to many. With your sample data: 

MasonMA_0-1763734631562.png

MasonMA_1-1763734666976.png

MasonMA_2-1763734705562.png

 

View solution in original post

dinesh_7780
Resolver V
Resolver V

Hi @Bala16 ,

Try below measure.

 

Calculated Value =

VAR CurrentProduct =

    SELECTEDVALUE ( TableB[Product] )

RETURN

SWITCH (

    TRUE(),

    CurrentProduct = "X1",

        CALCULATE ( MIN ( TableA[Value] ), TREATAS ( VALUES ( TableB[ID] ), TableA[ID] ) ),

    CurrentProduct = "X2",

        CALCULATE ( MAX ( TableA[Value] ), TREATAS ( VALUES ( TableB[ID] ), TableA[

ID] ) )

)

 

If my response as resolved your issue please mark it as solution and give kudos.

View solution in original post

3 REPLIES 3
dinesh_7780
Resolver V
Resolver V

Hi @Bala16 ,

Try below measure.

 

Calculated Value =

VAR CurrentProduct =

    SELECTEDVALUE ( TableB[Product] )

RETURN

SWITCH (

    TRUE(),

    CurrentProduct = "X1",

        CALCULATE ( MIN ( TableA[Value] ), TREATAS ( VALUES ( TableB[ID] ), TableA[ID] ) ),

    CurrentProduct = "X2",

        CALCULATE ( MAX ( TableA[Value] ), TREATAS ( VALUES ( TableB[ID] ), TableA[

ID] ) )

)

 

If my response as resolved your issue please mark it as solution and give kudos.

MasonMA
Community Champion
Community Champion

Hi, 

 

I'd suggest reshaping your TableA a bit in Power Query to make the relationship between TableA and TableB one to many. With your sample data: 

MasonMA_0-1763734631562.png

MasonMA_1-1763734666976.png

MasonMA_2-1763734705562.png

 

amitchandak
Super User
Super User

@Bala16 , new column in Table B

 

= If ([Product] = "X1", minx(filter(TableA, TableA[ID] = TableB[ID]), TableA[Value]) ,  maxx(filter(TableA, TableA[ID] = TableB[ID]), TableA[Value]) )

 

or

 

= If ([Product] = "X1", min( TableA[Value]) ,  max( TableA[Value]) )

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.