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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors