Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

In this tutorial, we will show how to build advanced Excel dashboards using Power Query, Power Pivot, and VBA.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

Modern Excel dashboards have evolved far beyond simple charts and tables. By combining Power Query for data transformation, Power Pivot for advanced data modeling and analysis, and VBA for automation and enhanced interactivity, you can create professional dashboards.

In this tutorial, we will show how to build advanced Excel dashboards using Power Query, Power Pivot, and VBA.

Let’s create a sales dashboard for a fictional retail company that sells products across multiple regions. We’ll work with a dataset containing the following tables.

  • Sales – Contains transaction data.
  • Products – Product details and categories.
  • Customers – Customer information.
  • Regions – Geographic information.

Step 1: Use Power Query for Data Import

Import Data:

  • Go to the Data tab >> select Get Data >> select From File >> select From Text/CSV.
  • Navigate to your sales_data.txt file >> click Import.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • When the Power Query Editor opens, review the data and make these transformations:
  • Change data types.
  • Right-click any column >> select Change Data Type >> select Data Type.
    • OrderDate to Date.
    • Quantity to Whole Number.
    • UnitPrice and Discount to Decimal Number.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • Remove any duplicate rows using Remove Duplicates.
  • Repeat the import process for Products.csv, Customers.csv, and Dates.csv, applying appropriate data type transformations.

Transform Data with Power Query:

Let’s enhance our sales data by performing tasks using Power Query.

Add Calculated Columns:

  • In Power Query Editor, select Sales data.
  • Go to the Add Column tab >> select Custom Column.
  • Name it: Revenue.
  • Insert the following formula.
= [Quantity] * [UnitPrice] * (1-[DiscountRate])
  • Click OK.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • Add another custom column.
  • Name it: Profit.
  • Insert the following formula.
Profit = [Revenue] - ([Quantity] * [UnitCost])
  • Click OK.
  • We will need to merge with the Products table to get the Cost.

Merge Tables for Additional Insights:

  • In Power Query Editor with Sales data open.
  • Go to the Home tab >> click Merge Queries from the ribbon.
    • Select ProductID from the Sales table.
    • Select the Products table and join on ProductID.
    • Click OK.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • Click on the Expand Table option >> select only the UnitCost column to bring in.
  • Click OK.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • Now, drag the Profit column under the Expanded Products step.
  • You will get the profit amount.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • Once you are done with data transformation.
  • Click Close & Load To…

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • In the Import Data box;
    • Select Only Create Connection.
    • Select Add this data to Data Model for all four tables.
    • Click OK.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

Step 2: Build the Data Model with Power Pivot

Open Power Pivot:

If Power Pivot is not available in the ribbon, then enable it.

  • Go to the File tab >> select Options >> select Add-ins.
  • In Manage box >> select COM Add-ins >> select Go.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • Select Microsoft Power Pivot for Excel.
  • Click OK.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • Go to the Power Pivot tab >> select Manage.
  • It will open the imported data from Power Query.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

Create Relationships:

  • Go to the Home tab >> select Diagram View.
    • Drag Sales[ProductID] to Products[ProductID].
    • Drag Sales[CustomerID] to Customers[CustomerID].
    • Drag Customers[RegionID] to Regions[RegionID].

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • Or go to the Design tab >> select Create Relationship.
  • Then select matching columns.

Create Calculated Measures:

  • In Power Pivot, click on the Sales table.
  • Go to the Home tab >> select Measures >> click New Measure.
  • Or, go to the Home tab >> select Calculation Area.
  • Insert the calculated measures there:

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • Total Revenue:
Total Revenue := SUM(Sales[Revenue])
  • Total Profit:
Total Profit := SUM(Sales[Profit])
  • Profit Margin:
Profit Margin := DIVIDE([Total Profit], [Total Revenue], 0)
  • Total orders:
Total Orders:=COUNTA(Sales[OrderID])
  • Average Order Value:
Average Order Value:=DIVIDE([Total Revenue], DISTINCTCOUNT(Sales[OrderID]), 0)
  • YTD Revenue:
YTD Revenue:=CALCULATE([Total Revenue], DATESYTD(Sales[OrderDate]))
  • Previous Year Revenue:
Previous Year Revenue:=CALCULATE([Total Revenue], SAMEPERIODLASTYEAR(Sales[OrderDate]))
  • YOY Growth:
YOY Growth := DIVIDE([Total Revenue] - [Previous Year Revenue], [Previous Year Revenue], 0)

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

Step 3: Use Pivot Table to Create Dashboard Components

Create PivotTables

  • Go to the Insert tab >> select PivotTable >> select From Data Model.
  • In Power Pivot, go to the Home tab >> select Pivot Table.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • In the Create PivotTable box;
    • Select New Worksheet.
    • Click OK.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • Create separate PivotTables for Total Revenue, Total Profit, Profit Margin, and Growth.
  • Place these in cells that align with your dashboard structure.
  • Format as currency or percentage as appropriate.

Charts and Visualizations

Revenue Trend Chart:

  • Create a PivotTable from the Data Model.
    • Rows: Sales[OrderDate[Month]]
    • Values: Total Revenue
  • Go to the PivotTable Analyze tab >> select Clustered Column Chart.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

Top Products Chart:

  • Create a PivotTable from the Data Model.
    • Rows: Products[ProductName]
    • Values: Total Revenue
  • Sort by Total Revenue descending, filter to top 10.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • Go to the PivotTable Analyze tab >> select Clustered Bar Chart.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

Category Performance:

  • Create a PivotTable from the Data Model.
    • Rows: Products[Category]
    • Values: Total Revenue, Total Profit, Profit Margin.
  • Go to the PivotTable Analyze tab >> select Combo >> select Clustered Column – Line on Secondary Axis.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

Step 4: Insert Interactive Elements

Insert Slicers and Timeline:

Create Product and Region Slicers:

  • Go to the PivotAnalyze tab >> select Insert Slicer.
  • Select Products[Category] and Customers[Region].
  • Click OK.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • Format them to match your dashboard design.

Add a Timeline for Date Filtering:

  • Go to the PivotAnalyze tab >> select Insert Slicer.
  • Select Sales[OrderDate].
  • Click OK.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • Position above your charts.
  • Format to match your dashboard style.

Connect All Slicers to PivotTables:

  • Right-click each slicer >> select Report Connections.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • Check all PivotTables to ensure filters apply globally.
  • Click OK.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

Step 5: Automate and Enhance Interactivity with VBA

We’ll use VBA to make the dashboard dynamic and easier to navigate.

Example 1: Refresh Data Button

  • Go to the Developer tab >> select Insert >> select Button.
  • Rename the button to Refresh Data.
  • Right-click button >> select Assign Macro >> select New.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • Copy-paste the following code.

VBA Code:

Sub RefreshDashboard()
    ThisWorkbook.RefreshAll
    MsgBox "Dashboard data refreshed!", vbInformation
End Sub

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

Example 2: Dashboard Reset Button

  • Go to the Developer tab >> select Insert >> select Button.
  • Rename the button to Reset Dashboard.
  • Right-click button >> select Assign Macro >> select New.
  • Copy-paste the following code.

VBA Code:

Sub ResetDashboardFilter()
    Dim ws As Worksheet
    Dim slicer As slicerCache
    Dim pivotTable As pivotTable
    
    ' Clear all slicer caches
    For Each slicer In ActiveWorkbook.SlicerCaches
        slicer.ClearAllFilters
    Next slicer
    
    ' Reset any timelines (already using SlicerCaches)
    For Each slicer In ActiveWorkbook.SlicerCaches
        If slicer.SourceType = xlTimeline Then
            slicer.ClearAllFilters
        End If
    Next slicer
    
    ' Refresh pivot tables
    For Each ws In ActiveWorkbook.Worksheets
        For Each pivotTable In ws.PivotTables
            pivotTable.RefreshTable
        Next pivotTable
    Next ws
    
    MsgBox "Dashboard filters have been reset!", vbInformation, "Reset Filters"
End Sub

Step 6: Create the Dashboard Layout

Create a new worksheet named Dashboard.

  • Set Up the Dashboard Structure:
    • Dashboard title and date filter.
    • KPI section (Revenue, Profit, Margin, Growth).
    • Charts (Sales Trend, Top Products, Regional Performance).

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • You can create a summary table for the Data tables and a detailed analysis.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • Apply consistent formatting:
    • Use a consistent color scheme throughout.
    • Align all elements properly.
    • Add borders to separate dashboard sections.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

  • Add Conditional Formatting to Data Tables:
    • Use data bars and color scales to highlight important values.
    • Add KPI icons to show performance against targets.
  • Create an Instruction Sheet:
    • Create a new worksheet named Instructions.
    • Add text explaining how to use the dashboard.
    • Include information on data refresh, interactivity, and available features.

Step 7: Test and Troubleshoot

Test All Interactive Elements:

  • Ensure slicers filter all relevant visualizations.
  • Verify that buttons execute macros correctly.
  • Check the timeline controls to ensure data ranges are properly.
    • Select Beauty from the Category slicer.
    • Select Jan-April 2024 from Timeline.
  • This will update the entire dashboard based on the filter selection.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

Test Reset Data Filter:

  • Click on the Reset Dashboard.
  • A message will pop up, “Dashboard filters have been reset”.
  • Click OK.
  • All filters will be removed, and you will get a fresh dashboard.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

Test Data Refresh:

  • Modify the source data.
  • Click Refresh Data.
  • Ensure all calculations update correctly.
  • Check for any broken connections or formulas.

Building Advanced Excel Dashboards: Power Query, Power Pivot, and VBA

Download Practice Workbook

Conclusion

Following all the steps, you can build an advanced Excel dashboard that will work as a powerful business intelligence tool. This dashboard leverages the power of Power Query for data preparation, Power Pivot for modeling and analysis, and VBA for enhanced interactivity. This dashboard provides a user-friendly interface for analyzing sales performance across products, regions, and time periods. Experiment with the dashboard and add more advanced functionalities.

Get FREE Advanced Excel Exercises with Solutions!

Shamima Sultana
Shamima Sultana

Shamima Sultana, BSc, Computer Science and Engineering, East West University, Bangladesh, has been working with the ExcelDemy project for 3+ years. She has written and reviewed 1000+ articles for ExcelDemy. She has also led several teams with Excel VBA and Content Development works. Currently, she is working as the Project Manager and oversees the day-to-day work, leads the services team, allocates resources to the right area, etc. Her work and learning interests vary from Microsoft Office Suites, and... Read Full Bio

4 Comments
  1. Dear Shamima Sultana,

    I recently read your article on building advanced Excel dashboards using Power Query, Power Pivot, and VBA. I found it very insightful and would love to explore the concepts more deeply.

    Would it be possible for you to share the sample dataset used in the tutorial (Sales, Products, Customers, and Regions)? I would like to follow along and practice building a similar dashboard for learning purposes.

    Thank you in advance for your time and generosity.

    Best regards,

    Diva Aliyah
    [email protected]

    • Hello Diva,

      Thank you for your thoughtful comment and your interest in the advanced Excel dashboard tutorial. I’m glad you found it insightful!

      To make your learning experience easier, I’ve attached a downloadable file with the sample dataset (Sales, Products, Customers, and Regions) as well as the complete dashboard solution. You can use this file to follow along step by step and practice building your own dashboard.

      If you have any questions or need further assistance, please feel free to reach out. Happy learning!

      Regards
      ExcelDemy

  2. Good morning Shamima Sultana, I really appreciate your tutorials, unfortunately there is never a file with the solution available to download for practice. Many websites of your colleagues include the file for those like me who would like to try the features of the tutorials. Thank you and good work.

    • Hello Flavio,

      Good morning! Thank you so much for your kind words and for sharing your feedback!
      I understand how useful it is to have a practice file to follow along. I’m happy to let you know that I’ve now attached a downloadable file containing both the sample dataset and the dashboard solution. You can use this file to practice and explore all the features demonstrated in the tutorial.

      Thank you again for your support and encouragement. If you have any further questions or need more resources, feel free to let me know!

      Regards
      ExcelDemy

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo