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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

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
October Power BI Update Carousel

Power BI Monthly Update - October 2025

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