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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Mardob
Frequent Visitor

Lookup MAX value(s) with a measure / calculated column

Hi all,

 

I got stucked with a following issue. I'm having a table with products, costs, prices and margins. I would like to vlookup product code with the highest margin value.

 

When there is just one highest margin value in a table, there is no issue. The problem appears when there are a few products with the same highest margin value.

 

The sample table looks as below:

CODECOSTPRICEMARGIN
12345     2     4    0.5
12346     7    14    0.5
12347     6    12    0.5
12348    12    19    0.37
12349    10     7    -0.43

 

The formula:

CODE_HIGHEST_VALUE = 

LOOKUPVALUE(SampleTable[CODE],SampleTable[MARGIN],MAX(SampleTable[MARGIN]))
 
And it doesn't work, as we have a few products with highest, 50% margin.
 
How can I calculate it (preferably with a measure but I believe it can be not possible) to show all affected product codes?
 
Thanks!
1 ACCEPTED SOLUTION
Mardob
Frequent Visitor

Thanks, guys, but your formulas are not working as I wished. But I have found the solution:

 

MaxCodes =

VAR MaxMargin =

    MAXX(SampleTable,SampleTable[MARGIN]

    )

RETURN

CONCATENATEX(

    FILTER(

        ALLSELECTED(SampleTable),

        SampleTable[MARGIN] = MaxMargin

    ),

    SampleTable[CODE],

    ","

)

View solution in original post

3 REPLIES 3
Mardob
Frequent Visitor

Thanks, guys, but your formulas are not working as I wished. But I have found the solution:

 

MaxCodes =

VAR MaxMargin =

    MAXX(SampleTable,SampleTable[MARGIN]

    )

RETURN

CONCATENATEX(

    FILTER(

        ALLSELECTED(SampleTable),

        SampleTable[MARGIN] = MaxMargin

    ),

    SampleTable[CODE],

    ","

)

ThxAlot
Super User
Super User

(Almost) Nothing can't be achieved by a proper DAX measure,

ThxAlot_1-1720517921310.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



amitchandak
Super User
Super User

@Mardob , You can have measures

 

MARGIN p = Sum(Table[MARGIN])

TOP 1= calculate(Max(Table[CODE]), keepfilters( index(1, allselected(Table[CODE]), orderBy([MARGIN p], desc))) )

 

Plot this with Table code in visual

 

Or a measure like

CONCATANATEX(index(1, allselected(Table[CODE]), orderBy([MARGIN p], desc)), Table[CODE], ", ")

 

Power BI Index function: Top/Bottom Performer by name and value- https://youtu.be/HPhzzCwe10U

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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
Top Kudoed Authors