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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. 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.


Go to My LinkedIn Page


Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Power BI Header Change

Power BI Header Update

Read about the exciting updates for the Power BI forum.