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
Choko_1
Regular Visitor

Rank by group and order it by another related column table

Hey Community!

I have those two tables: 

  1. Movie_Details - contain: "Major Genre", "Director"
  2. Revenue - contain: "ROI"

    I want to get the movie with the highest ROI for each Major Genre and show the Director's name of the film.

    The tables are related by column name "Title".

     

    I tried to rank by group (Genre) that will be ordered descending by ROI to get all the 1's, but it didn't work.

    Where did I go wrong?

     

    Here's the DAX code:

 

Rank Genre = 
RANKX(ALLEXCEPT(Movie_Details, Movie_Details[Major Genre]),MAXX(RELATEDTABLE(Revenue),Revenue[ROI]),,DESC)

 

 

 

And here's an example of the ranking for the genre "Action" with descending ROI:

 

Choko_1_0-1660140544901.png

 

1 ACCEPTED SOLUTION
daXtreme
Solution Sage
Solution Sage

daXtreme_0-1660213963877.pngdaXtreme_2-1660214045796.png

 

DEFINE 

MEASURE ROIs[Total ROI] = sum(ROIs[ROI] )

MEASURE Films[Rank by ROI] = 
if ( ISINSCOPE(Films[Title] ),
    var CurrentGenre = SELECTEDVALUE( Films[Genre] )
    var RankWithinGenre =
        RANKX(
            FILTER(
                ALLSELECTED( Films ),
                Films[Genre] = CurrentGenre
            ),
            [Total ROI]
        )
    return
        RankWithinGenre
)

View solution in original post

2 REPLIES 2
daXtreme
Solution Sage
Solution Sage

daXtreme_0-1660213963877.pngdaXtreme_2-1660214045796.png

 

DEFINE 

MEASURE ROIs[Total ROI] = sum(ROIs[ROI] )

MEASURE Films[Rank by ROI] = 
if ( ISINSCOPE(Films[Title] ),
    var CurrentGenre = SELECTEDVALUE( Films[Genre] )
    var RankWithinGenre =
        RANKX(
            FILTER(
                ALLSELECTED( Films ),
                Films[Genre] = CurrentGenre
            ),
            [Total ROI]
        )
    return
        RankWithinGenre
)

Thanks! it works great!

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