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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Keithlaf34
Frequent Visitor

Pulling a column based on the max value of a different column

Hello all,

 

I am trying to pull the Item code based on max quantity. For example, if i filtered on customer ID AA, it should return the item code A3A. Is there a measure i can use to solve this?

Keithlaf34_0-1652105124819.png

 

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @Keithlaf34 

Try this, create the measure below

Measure = 
var _selectedCustomre= SELECTEDVALUE(CustomerSlicer[Customer ID])
var _maxqty= MAXX(filter(ALL('Table'),'Table'[Customer ID]=_selectedCustomre),'Table'[Quantity])
var _maxItem=MAXX(FILTER(ALL('Table'),'Table'[Customer ID]=_selectedCustomre && 'Table'[Quantity]= _maxqty),'Table'[Item Code])
return IF(ISFILTERED(CustomerSlicer[Customer ID]),_maxItem,"select customer")

vxiaotang_0-1652337169439.png

vxiaotang_1-1652337181524.png

 

Best Regards,

Community Support Team _Tang

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

View solution in original post

6 REPLIES 6
v-xiaotang
Community Support
Community Support

Hi @Keithlaf34 

Try this, create the measure below

Measure = 
var _selectedCustomre= SELECTEDVALUE(CustomerSlicer[Customer ID])
var _maxqty= MAXX(filter(ALL('Table'),'Table'[Customer ID]=_selectedCustomre),'Table'[Quantity])
var _maxItem=MAXX(FILTER(ALL('Table'),'Table'[Customer ID]=_selectedCustomre && 'Table'[Quantity]= _maxqty),'Table'[Item Code])
return IF(ISFILTERED(CustomerSlicer[Customer ID]),_maxItem,"select customer")

vxiaotang_0-1652337169439.png

vxiaotang_1-1652337181524.png

 

Best Regards,

Community Support Team _Tang

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

johnt75
Super User
Super User

You could use TOPN, e.g.

Top Product =
var currentCustomer = SELECTEDVALUE( 'Table'[Customer ID])
var summaryTable = TOPN( 1, 'Table', 'Table'[Quantity])
return IF( COUNTROWS(summaryTable) = 1, SELECTCOLUMNS( summaryTable, "@val", [Item Code]))

This would return blank if there are 2 top products, but if you wanted to be able to display all tied products then you could run CONCATENATEX over the summary table

tamerj1
Super User
Super User

Hi @Keithlaf34 

please try

Code =
CALCULATE (
    MAX ( Customers[Item Code] ),
    Customers[Quantity] = MAX ( Customers[Quantity] )
)

Keithlaf34_0-1652107789750.png

 

 

 

Code =
VAR MaxQty = MAX ( Customers[Quantity] )
RETURN 
CALCULATE (
    MAXA ( Customers[Item Code] ),
    Customers[Quantity] = MaxQty
)

 

 

Keithlaf34_0-1652130465125.png

getting a different error unfortunately. appreciate the help.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.