• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Toggle Top N with Slicers

You are here: Home / Power Pivot / Toggle Top N with Slicers
November 25, 2021 by Mynda Treacy

Power Pivot course member, Peter, asked if it was possible to toggle the top n with a Slicer for a Pivot Chart and the answer is yes! With Power Pivot and disconnected tables, we can create interactive charts like this:

Toggle top n with slicers

Watch the Video

Subscribe YouTube

Download Workbook

Enter your email address below to download the sample workbook.

By submitting your email address you agree that we can email you our Excel newsletter.
Please enter a valid email address.

Download the Excel Workbook or download the Power BI Desktop file.

Setup Power Pivot Toggle Top N with Slicers

I’m using some sample data stored in an Excel Table called ‘Data’. You can see below it is grouped by category and sub-category and I want to filter the top n sub-categories:

Power Pivot toggle top n with slicers

We start by loading the data into Power Pivot, preferably via Power Query. Alternatively, if your data is in an Excel Table you can use the ‘Add to Data Model’ button on the Power Pivot tab:

Power Pivot ribbon tab

I also need to load a table that stores the top n values I want the user to be able to select in the Slicer into Power Pivot. You can see in the image below the table is called TopN:

top n table

IMPORTANT: These tables are not related in the Power Pivot data model.

Measures to Toggle Top N with Slicers

We need 4 measures:

Measure 1: detects the item selected in the top n slicer:

Selected TopN = MIN('TopN'[Display Top])

We use MIN here to handle the possibility the user selects more than one item in the Slicer. You could equally use MAX if you prefer.

Measure 2: We need to calculate the total amount, which is used in the next measure. It's easy with the SUM function:

Total Amount = SUM(Data[Amount])

Measure 3: Ranks the Sub-categories 1 to n based on the top N selected in the Slicer.

Rank Sub-category = RANKX(ALLSELECTED(Data[Sub-category]), [Total Amount], , 0)

RANKX returns the ranking of all selected sub-categories based on the Total Amount. The last argument, zero, specifies the sort order in descending order.

Measure 4: Filters out the sub-categories we don’t want included using an IF formula:

Include Sub-category = IF([Rank Sub-category] <= [Selected TopN],1,0)

It simply says, if the rank is less than or equal to the selected top n value, then return 1, otherwise return zero.

PivotTable to Toggle Top N with Slicers

Now we can build the PivotTable to support the Pivot Chart. The PivotTable end result is below (don't worry about the yellow warning in the Field List as this is expected).:

Power Pivot toggle top n pivottable

However, to apply the filter we temporarily add the ‘Include Sub-category’ measure to the PivotTable Values area:

Power Pivot filter pivottable

Once the filter is applied, the ‘Include Sub-category’ measure can be removed from the PivotTable.

And sort in ascending order based on the Rank Sub-category field.

Now you can insert the Slicer and the Pivot Chart:

insert Power Pivot pivot chart

Pivot Chart Formatting

The Pivot Chart starts off a bit ugly:

ugly Power Pivot pivot chart

Let’s apply some formatting to pretty it up (see video for further details).

  1. CTRL+1 the chart to open the format pane > Format Axis > Axis Options > Categories in reverse order
  2. Right-click the field buttons on the chart > Hide all field buttons on chart
  3. Select the ‘Rank Sub-category’ series in the chart > set fill colour to No Fill
  4. Set the series overlap to 100%
  5. Set the gap width to 50%
  6. Remove the legend
  7. Add custom dynamic chart label referencing another PivotTable that captures the Selected TopN.

Want More

Check out this tutorial that also uses disconnected tables to change the aggregation method using Slicers.

Want to learn more about Power Pivot? Please consider my comprehensive Power Pivot and DAX course.

More Power Pivot Posts

CUBE Functions

Excel CUBE Functions

Excel CUBE Functions are a great alternative to GETPIVOTDATA for Power Pivot PivotTables and still work with Slicers.
Introduction to DAX

Introduction to DAX Measures

Introduction to DAX in Power BI and Excel. Where and how to write DAX measures, understanding filter context and more.
power pivot running total

Power Pivot Running Total

The defaul Power Pivot Running Total setting doesn't handle aggregated periods. This measure solves this issue.
static data tables

Static Tables in Power Query, Power Pivot and Power BI

Use static tables to store data in Power Query, Power Pivot and Power BI without needing to load data from an external source
custom formatting strings in power bi

Custom Formatting Strings in Power BI

Control how data is displayed in Power BI using your own formats. Like hiding negative or zero values, using symbols or custom number formats
GETPIVOTDATA Function for Power Pivot

GETPIVOTDATA Function for Power Pivot

The GETPIVOTDATA Function for Power Pivot references measures and so it works a little different to GETPIVOTDATA for regular PivotTables.
values_as_%_of_another_column_thumb

Show Values as Percentage of Another PivotTable Column Total

Show Values as % of Another PivotTable Column Total can't be done with regular PivotTables, however with Power Pivot we can use a DAX measure.
Change PivotTable Aggregation Methods using Excel Slicers

Change PivotChart Aggregation Methods using Excel Slicers

Change Pivot Chart Aggregation Methods using Excel Slicers and Power Pivot. Disconnected tables and the SWITCH function are the secret sauce.
PivotTable Distinct Count

Excel PivotTable Distinct Count

Excel PivotTable Distinct Count, sometimes called ‘Unique Count’ will return a count of unique items in a field. It uses the Data Model (Power Pivot).
Power Pivot does VLOOKUP

Power Pivot does VLOOKUP

Creating PivotTables from multiple tables used to require consolidating the data into one table, but now Power Pivot does VLOOKUP, kind of. So you don't need to.


Category: Power Pivot
Previous Post:excel interactive personal finance dashboardInteractive Personal Finance Dashboard
Next Post:Power Query Keyboard Shortcuts to Save Timepower query keyboard shortcuts

Reader Interactions

Comments

  1. Lorean

    November 28, 2021 at 1:46 am

    I am very picky about details and it is like a balm for my soul to read such detailed instructions. Thanks!

    Regards, developer

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Current ye@r *

Leave this field empty

Sidebar

More results...

Featured Content

  • 10 Common Excel Mistakes to Avoid
  • Top Excel Functions for Data Analysts
  • Secrets to Building Excel Dashboards in Less Than 15 Minutes
  • Pro Excel Formula Writing Tips
  • Hidden Excel Double-Click Shortcuts
  • Top 10 Intermediate Excel Functions
  • 5 Pro Excel Dashboard Design Tips
  • 5 Excel SUM Function Tricks
  • 239 Excel Keyboard Shortcuts

100 Excel Tips and Tricks eBook

Download Free Tips & Tricks

Subscribe to Our Newsletter

Receive weekly tutorials on Excel, Power Query, Power Pivot, Power BI and More.

We respect your email privacy

Guides and Resources

  • Excel Keyboard Shortcuts
  • Excel Functions
  • Excel Formulas
  • Excel Custom Number Formatting
  • ALT Codes
  • Pivot Tables
  • VLOOKUP
  • VBA
  • Excel Userforms
  • Free Downloads

239 Excel Keyboard Shortcuts

Download Free PDF

Free Webinars

Excel Dashboards Webinar

Watch our free webinars and learn to create Interactive Dashboard Reports in Excel or Power BI

Click Here to Watch Now

mynda treacy microsoft mvpHi, I'm Mynda Treacy and I run MOTH with my husband, Phil. Through our blog, webinars, YouTube channel and courses we hope we can help you learn Excel, Power Pivot and DAX, Power Query, Power BI, and Excel Dashboards.

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk – For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.