cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
hanzlova Frequent Visitor
Frequent Visitor

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

Accepted Solutions
Community Support Team
Community Support Team

Re: How to choose the record with the highest value by group

Hi @hanzlova ,

 

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
Community Support Team
Community Support Team

Re: How to choose the record with the highest value by group

Hi @hanzlova ,

 

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

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors
Top Kudoed Authors