cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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

Accepted Solutions
Highlighted
Microsoft
Microsoft

Re: Dax Top 1- Top 2 with filter selection

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
Highlighted
Resolver II
Resolver II

Re: Dax Top 1- Top 2 with filter selection

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

Highlighted
Resolver I
Resolver I

Re: Dax Top 1- Top 2 with filter selection

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

 

 

 

Highlighted
Microsoft
Microsoft

Re: Dax Top 1- Top 2 with filter selection

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

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Upcoming Events

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors