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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.