Forum Discussion
TOP N Slicer for pivot table
Hi All,
I need to showcase the TOP 5, TOP 10, and TOP 20 products with sales in matrix visual,
Under product, I need to show the month
So, ie
I Want to display TOP Products sales under product I need to show each month how many sales happened
I want to show the top 5 product like this using top n slicer and while i drill down to month i need to show those top 5 products how they performed in each month
Current issue is while applying top 5 month at that time more poducts is coming , if we remove month from matrix visual it is showing correctly
Kindly help to achieve this dax
In matrix visual while expanding the procut the expected out put should be like this
Here i am attaching the dummy data in excel
| Product | Year Month | Sales |
| BD10M32 | January | 859 |
| BD10M32 | February | 607 |
| BD10M32 | March | 713 |
| BD10M32 | April | 231 |
| BD10M32 | May | 470 |
| BD10M32 | June | 607 |
| BD10M32 | July | 722 |
| BD10M32 | August | 255 |
| BD10M32 | September | 249 |
| BD10M32 | October | 427 |
| BD10M32 | November | 131 |
| BD10M32 | December | 142 |
| BD10M22 | January | 819 |
| BD10M22 | February | 709 |
| BD10M22 | March | 872 |
| BD10M22 | April | 660 |
| BD10M22 | May | 674 |
| BD10M22 | June | 950 |
| BD10M22 | July | 830 |
| BD10M22 | August | 855 |
| BD10M22 | September | 374 |
| BD10M22 | October | 465 |
| BD10M22 | November | 230 |
| BD10M22 | December | 468 |
| BD10M12 | January | 182 |
| BD10M12 | February | 114 |
| BD10M12 | March | 730 |
| BD10M12 | April | 764 |
| BD10M12 | May | 233 |
| BD10M12 | June | 942 |
| BD10M12 | July | 797 |
| BD10M12 | August | 185 |
| BD10M12 | September | 505 |
| BD10M12 | October | 737 |
| BD10M12 | November | 93 |
| BD10M12 | December | 459 |
| BD10M11 | January | 606 |
| BD10M11 | February | 123 |
| BD10M11 | March | 900 |
| BD10M11 | April | 52 |
| BD10M11 | May | 834 |
| BD10M11 | June | 946 |
| BD10M11 | July | 32 |
| BD10M11 | August | 642 |
| BD10M11 | September | 707 |
| BD10M11 | October | 418 |
| BD10M11 | November | 482 |
| BD10M11 | December | 444 |
| BD10M10 | January | 891 |
| BD10M10 | February | 989 |
| BD10M10 | March | 383 |
| BD10M10 | April | 470 |
| BD10M10 | May | 938 |
| BD10M10 | June | 759 |
| BD10M10 | July | 561 |
| BD10M10 | August | 457 |
| BD10M10 | September | 473 |
| BD10M10 | October | 411 |
| BD10M10 | November | 925 |
| BD10M10 | December | 327 |
| BD10M09 | January | 1000 |
| BD10M09 | February | 94 |
| BD10M09 | March | 294 |
| BD10M09 | April | 239 |
| BD10M09 | May | 529 |
| BD10M09 | June | 451 |
| BD10M09 | July | 70 |
| BD10M09 | August | 851 |
| BD10M09 | September | 235 |
| BD10M09 | October | 892 |
| BD10M09 | November | 105 |
| BD10M09 | December | 516 |
| BD10M08 | January | 533 |
| BD10M08 | February | 148 |
| BD10M08 | March | 684 |
| BD10M08 | April | 549 |
| BD10M08 | May | 905 |
| BD10M08 | June | 785 |
| BD10M08 | July | 860 |
| BD10M08 | August | 820 |
| BD10M08 | September | 977 |
| BD10M08 | October | 885 |
| BD10M08 | November | 51 |
| BD10M08 | December | 828 |
| BD10M07 | January | 845 |
| BD10M07 | February | 82 |
| BD10M07 | March | 353 |
| BD10M07 | April | 178 |
| BD10M07 | May | 505 |
| BD10M07 | June | 757 |
| BD10M07 | July | 795 |
| BD10M07 | August | 929 |
| BD10M07 | September | 224 |
| BD10M07 | October | 77 |
| BD10M07 | November | 245 |
| BD10M07 | December | 515 |
| BD10M06 | January | 824 |
| BD10M06 | February | 886 |
| BD10M06 | March | 885 |
| BD10M06 | April | 612 |
| BD10M06 | May | 893 |
| BD10M06 | June | 714 |
| BD10M06 | July | 574 |
| BD10M06 | August | 24 |
| BD10M06 | September | 673 |
| BD10M06 | October | 317 |
| BD10M06 | November | 48 |
| BD10M06 | December | 773 |
| BD10M08 | January | 833 |
| BD10M08 | February | 297 |
| BD10M08 | March | 891 |
| BD10M08 | April | 445 |
| BD10M08 | May | 546 |
| BD10M08 | June | 233 |
| BD10M08 | July | 418 |
| BD10M08 | August | 283 |
| BD10M08 | September | 381 |
| BD10M08 | October | 130 |
| BD10M08 | November | 618 |
| BD10M08 | December | 705 |
5 Replies
- Jihwan_Kim
Super User
Hi,
Please check the below and the attached pbix file.
Top 5 sales: = VAR _list = CALCULATETABLE ( TOPN ( 5, ALL ( 'Product'[Product ] ), [Sales:], DESC ), REMOVEFILTERS ( 'Month' ) ) RETURN CALCULATE ( [Sales:], KEEPFILTERS ( 'Product'[Product ] IN _list ) )- AnonymousNot applicable
Hi Jihwan_Kim ,
First of all, thank you for the solution, but I am facing a challenge
Here i have toip n slicer based on that only the pivot table should work,
Kindly Have a look- MarkLaf
Super User
You can create a measure to use as a filter on the matrix.
Create a table for your Top N options - here is DAX for 5, 10, 20:
N Options = { 5, 10, 20 }
Create the measure that you'll use as a filter:TopNProductSalesFilter = VAR _N = MAX( 'N Options'[Value] ) VAR _topN = CALCULATETABLE( TOPN( _N, ALL( 'Table'[Product] ), CALCULATE( SUM('Table'[Sales] ) ) ), REMOVEFILTERS( 'Table' ), VALUES( 'Table'[Product] ) ) RETURN IF( ISFILTERED( 'N Options'[Value] ), CALCULATE( INT( NOT ISEMPTY( 'Table' ) ), KEEPFILTERS( _topN ) ), 1 )Now put your matrix together and add [TopNProductSalesFilter] as a filter and set it equal to 1. Put 'N Options'[Value] in a slicer:
- Padycosmos
Solution Sage
Hope these 2 videos help:
- parry2k
Super User
Anonymous See attached with Top N selection. Jihwan_Kim has provided a great solution, and I tweaked DAX measure a bit.
Top 5 sales: = VAR _list = CALCULATETABLE ( TOPN ( [Top N Selected], ALL ( 'Product'[Product ] ), [Sales:], DESC ), REMOVEFILTERS ( 'Month' ) ) RETURN CALCULATE ( [Sales:], KEEPFILTERS ( _list ) ) )👉 Learn Power BI to our YT channel - @PowerBIHowTo