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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.