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
Anonymous
Not applicable

How to choose the record with the highest value by group

Hi everybody,

 

I would like to ask, how to choose the last record in table. I have table with many rows. I would like to recognize and choose only rows, where the value is the highest.

 

Example:

ID | Group name | Value

0 | All | 0

1 | Woman | 1

2 | Man | 1

3 | Woman's T-shirt | 2

4 | Woman's shoes | 2

5 | Woman's socks | 2

 

The result is:

3 | Woman's T-shirt | 2

4 | Woman's shoes | 2

5 | Woman's socks | 2

AND

2 | Man | 1

 

because group Man doesn' t have higher value in column Value.

 

Do you know, how to do it? In real life it looks like tree, where you have groups and sub-groups. And you know ID employee (column ID) and you know his manager (because you have other columns as Manager, where is ID employee). So there is know superior and subordinate relationship.

 

I tried filter values by highest value, but I lost group Man with value 1. I tried change table from star to snowflake.

 

Do you have any ideas, how to solve it?

 

Thank you very much for help.

Mary

1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please check the following step as below.

 

1. Create two calcualted columns in the fact table.

new group = 
IF (
    'Table'[Value] = 0,
    BLANK (),
    IF ( SEARCH ( "Woman", [Group name],, BLANK () ) = BLANK (), "man", "woman" )
)
max value = 
CALCULATE (
    MAX ( 'Table'[Value] ),
    FILTER ( 'Table', 'Table'[new group] = EARLIER ( 'Table'[new group] ) )
)

2. Create a calculated table to get the excepted result.

Table 2 = 
SUMMARIZE (
    FILTER (
        'Table',
        'Table'[new group] <> BLANK ()
            && 'Table'[Value] = 'Table'[max value]
    ),
    'Table'[ID],
    'Table'[new group],
    "value", MAX ( 'Table'[Value] )
)

Capture.PNG

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

1 REPLY 1
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please check the following step as below.

 

1. Create two calcualted columns in the fact table.

new group = 
IF (
    'Table'[Value] = 0,
    BLANK (),
    IF ( SEARCH ( "Woman", [Group name],, BLANK () ) = BLANK (), "man", "woman" )
)
max value = 
CALCULATE (
    MAX ( 'Table'[Value] ),
    FILTER ( 'Table', 'Table'[new group] = EARLIER ( 'Table'[new group] ) )
)

2. Create a calculated table to get the excepted result.

Table 2 = 
SUMMARIZE (
    FILTER (
        'Table',
        'Table'[new group] <> BLANK ()
            && 'Table'[Value] = 'Table'[max value]
    ),
    'Table'[ID],
    'Table'[new group],
    "value", MAX ( 'Table'[Value] )
)

Capture.PNG

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

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.

Top Solution Authors
Top Kudoed Authors