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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
angsoka
Frequent Visitor

Measure to Show The Name of Top N Every Month

Dear All,

I have a database of monthly sales for every region. I want to have a table showing only the top 3 of it.

Database

CityJanFebMarch
Boston100300500
San Francisco300500100
New York200200400
Chicago400100200
Los Angeles500400300

 
What I want to have is a table showing list of monthly top 3 city 

 

Rank JanFebMarch
1Los AngelesSan FranciscoBoston
2ChicagoLos AngelesNew York
3San FranciscoBostonLos Angeles


Any assistance?  Appreciate the help!

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

It is for creating a measure.

 

Jihwan_Kim_0-1662567635761.png

 

 

Top 3 city name measure: =
VAR _rankingnumber =
    MAX ( 'Rank number table'[Rank] )
VAR _rankingtable =
    FILTER (
        ADDCOLUMNS (
            VALUES ( City[City] ),
            "@Ranking", RANKX ( ALL ( City[City] ), CALCULATE ( SUM ( Data[Value] ) ),, DESC )
        ),
        [@Ranking] = _rankingnumber
            && [@Ranking] <= 3
    )
RETURN
    IF ( HASONEVALUE ( 'Month'[Month] ), MAXX ( _rankingtable, City[City] ) )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

It is for creating a measure.

 

Jihwan_Kim_0-1662567635761.png

 

 

Top 3 city name measure: =
VAR _rankingnumber =
    MAX ( 'Rank number table'[Rank] )
VAR _rankingtable =
    FILTER (
        ADDCOLUMNS (
            VALUES ( City[City] ),
            "@Ranking", RANKX ( ALL ( City[City] ), CALCULATE ( SUM ( Data[Value] ) ),, DESC )
        ),
        [@Ranking] = _rankingnumber
            && [@Ranking] <= 3
    )
RETURN
    IF ( HASONEVALUE ( 'Month'[Month] ), MAXX ( _rankingtable, City[City] ) )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Dear Mr. Jihwan_Kim What a beautiful solution. Many thanks. May I ask how many years you've spent until you reached this level? Best regards, Angsoka

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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