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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
patrick3
Helper II
Helper II

Table with duplicate keys - want to return 1 value in 1 column based on another colum

Hi community, 

 

Not quite sure how best to describe it, but a table should help:

 

UserKeyValueCategoryReturn of Formula
120Blue WidgetsRed Widgets
230Red WidgetsRed Widgets
340Green WidgetsGreen Widgets
450Blue WidgetsBlue Widgets
130Green WidgetsRed Widgets
540Green WidgetsGreen Widgets
650Blue WidgetsBlue Widgets
140Red WidgetsRed Widgets

 

As you can see, the UserKey "1" appears 3 times, with 3 different values and 3 different categories.

I'm looking for a way to write a dax formula that checks all occurences of the UserKey, then returns the category with the highest value in the new column.

 

In the example, I want the new column to have "Red Widgets" because it has a value of 40 in the last row.

 

Hope that makes sense and someone can help me out.

 

Thanks,

Patrick

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

Hello @patrick3 

Give this a try.

Return of Formula =
VAR _UserKey = 'Table'[UserKey]
VAR _MaxValue =
    CALCULATE (
        MAX ( 'Table'[Value] ),
        ALL ( 'Table' ),
        'Table'[UserKey] = _UserKey
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[Category] ),
        ALL ( 'Table' ),
        'Table'[Value] = _MaxValue,
        'Table'[UserKey] = _UserKey
    )

View solution in original post

2 REPLIES 2
jdbuchanan71
Super User
Super User

Hello @patrick3 

Give this a try.

Return of Formula =
VAR _UserKey = 'Table'[UserKey]
VAR _MaxValue =
    CALCULATE (
        MAX ( 'Table'[Value] ),
        ALL ( 'Table' ),
        'Table'[UserKey] = _UserKey
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[Category] ),
        ALL ( 'Table' ),
        'Table'[Value] = _MaxValue,
        'Table'[UserKey] = _UserKey
    )

@jdbuchanan71  that's perfect, thanks a lot!

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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