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
BalaVenuGopal
Resolver I
Resolver I

Dax Top 1- Top 2 with filter selection

Hi team ,

 

I have category and month and sales count data .

 

1)  i want to show Category and Month and Sales Count in tabular or matrix report

2) Along with this i want to show (Top 1 month - Sales ) -  (Top 2 month - Sales ) as  another column.

 

Filter :

 

I will use MOnth as filter so what ever the months i have choosen from filter from them measure need to dynamically pick up top 1 sales - top 2 sales .

 

Can any one help here through dax measure .

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @BalaVenuGopal,

 

Based on below sample table, please create measures:

2.PNG

S Sales = SUM('Monthly Sales'[Sales Count])

Rank Cat Month =
RANKX (
    ALLEXCEPT ( 'Monthly Sales', 'Monthly Sales'[Category] ),
    [S Sales],
    ,
    DESC,
    DENSE
)

Top1 =
CALCULATE (
    [S Sales],
    FILTER (
        ALLEXCEPT ( 'Monthly Sales', 'Monthly Sales'[Category] ),
        [Rank Cat Month] = 1
    )
)
Top2 =
CALCULATE (
    [S Sales],
    FILTER (
        ALLEXCEPT ( 'Monthly Sales', 'Monthly Sales'[Category] ),
        [Rank Cat Month] = 2
    )
)

Top1-Top2 = [Top1]-[Top2] 

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yulgu-msft
Employee
Employee

Hi @BalaVenuGopal,

 

Based on below sample table, please create measures:

2.PNG

S Sales = SUM('Monthly Sales'[Sales Count])

Rank Cat Month =
RANKX (
    ALLEXCEPT ( 'Monthly Sales', 'Monthly Sales'[Category] ),
    [S Sales],
    ,
    DESC,
    DENSE
)

Top1 =
CALCULATE (
    [S Sales],
    FILTER (
        ALLEXCEPT ( 'Monthly Sales', 'Monthly Sales'[Category] ),
        [Rank Cat Month] = 1
    )
)
Top2 =
CALCULATE (
    [S Sales],
    FILTER (
        ALLEXCEPT ( 'Monthly Sales', 'Monthly Sales'[Category] ),
        [Rank Cat Month] = 2
    )
)

Top1-Top2 = [Top1]-[Top2] 

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Salonic
Resolver I
Resolver I

Hello,

 

I created this little table in a pbi file :

 

006.png

 

Then created 2 measures :

 

S Sales = SUM(Data[Sales]) 
Rank Cat Month = RANKX(ALL(Data[Category]);[S Sales])

You may then create a table with "Rank Cat Month" is less than 3

 

 

 

RahulYadav
Resolver II
Resolver II

Hi @BalaVenuGopal,

Could you please provide more information about the request? Also, if you can provide sample data in excel along with sample output you are looking for. You can scramble data if it is confidential.

 

Thanks,

Rahul

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