cancel
Showing results for 
Search instead for 
Did you mean: 
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
Solution Sage
Solution Sage

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
Community Champion
Community Champion

Hi @Keithlaf34 

please try

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

Keithlaf34_0-1652107789750.png

 

tamerj1
Community Champion
Community Champion

 

 

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
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors
Top Kudoed Authors