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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Martynas_BI
Frequent Visitor

DAX: show top N values by category

Hi,

 

I would like to show the top 3 company tickers based on 'Weight, %' column.

I would also like this calculation to be responsive to a 'report view' filter, when filtering by year (i.e. top 3 companies in year 2022 will be different than in 2021, etc.)

Martynas_BI_0-1683994864934.png

Here is the full data set if needed:

https://docs.google.com/spreadsheets/d/1Sa9xva8HVuW7178WPJPV-nv0ClrqMwDM19SokaIztMM/edit#gid=0

 

Many thanks in advance

 

 

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi,

I don't know how you want to model your data, but I assume your datamodel looks something like below.

I saw that there are two companies who has two Ticker categories. Please correct me if I misunderstood.

 

Jihwan_Kim_0-1684039271233.png

 

Jihwan_Kim_1-1684039597874.png

 

Top3 weight percent measure: =
CALCULATE (
    DIVIDE ( SUM ( Data[Shares] ), SUM ( Data[Value] ) ),
    KEEPFILTERS (
        WINDOW (
            1,
            ABS,
            3,
            ABS,
            ALLSELECTED ( Ticker[Ticker] ),
            ORDERBY (
                CALCULATE ( DIVIDE ( SUM ( Data[Shares] ), SUM ( Data[Value] ) ) ), DESC
            )
        )
    )
)

 

 

 

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.