+ Reply to Thread
Results 1 to 6 of 6

VBA code to filter pivot table by 2 separate lists

  1. #1
    Registered User
    Join Date
    10-26-2018
    Location
    Toronto, Canada
    MS-Off Ver
    MS 365 Apps for Enterprise (Windows 10)
    Posts
    14

    VBA code to filter pivot table by 2 separate lists

    Hi,

    I have a pivot table connected live to a Power BI dataset, which shows a list of product sales by store location by day.

    Our company ran a promotion on a few products at certain store locations for a particular period of time.

    I need a code that would let me filter this pivot table on only the stores and products where this promotion was happening, by using the values in column A for both "Store List" and "Product List" sheets.

    I've seen solutions that let me do this filtering by list but not when connected to a pivot table.

    Attaching an example for reference

    Thank you!
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: VBA code to filter pivot table by 2 separate lists

    Hi,

    I used the power pivot data model to do this

    first add the sales list to the data model
    add the filter tables to the data model
    make relationships
    add a true or false column in de sales table with a formula

    make a pivot table based on the data model table

    check the file so might make more sense
    Attached Files Attached Files
    Please be as complete as possible in your asking so it may save use all the time to rework the solution because you didn't give all the requirements. If you have a layout in mind please work it out first so we can adapt our solution to it. Thanks.
    If you have been helped, maybe you could click the *

  3. #3
    Registered User
    Join Date
    10-26-2018
    Location
    Toronto, Canada
    MS-Off Ver
    MS 365 Apps for Enterprise (Windows 10)
    Posts
    14

    Re: VBA code to filter pivot table by 2 separate lists

    Quote Originally Posted by Joske920 View Post
    Hi,

    I used the power pivot data model to do this

    first add the sales list to the data model
    add the filter tables to the data model
    make relationships
    add a true or false column in de sales table with a formula

    make a pivot table based on the data model table

    check the file so might make more sense
    Hi, thanks for the reply. It doesn't seem to work in my case. When I try to add the pivot table to the data model I get an error message saying:

    "The selected range is invalid. Select a valid range. A table cannot overlap a range that contains a PivotTable report, query results, protected cells or another table."

  4. #4
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: VBA code to filter pivot table by 2 separate lists

    did you look at the attached file?

    go to the data model and look at the tables

    you cant add a pivot to the data model
    a pivot is based on a table, not the other way around

  5. #5
    Registered User
    Join Date
    10-26-2018
    Location
    Toronto, Canada
    MS-Off Ver
    MS 365 Apps for Enterprise (Windows 10)
    Posts
    14

    Re: VBA code to filter pivot table by 2 separate lists

    Quote Originally Posted by Joske920 View Post
    did you look at the attached file?

    go to the data model and look at the tables

    you cant add a pivot to the data model
    a pivot is based on a table, not the other way around
    Yes i saw your file.
    What I am saying is my actual data (not the mockup data) is in a pivot table, connected live to a Power BI dataset.
    So I can't convert it to a table in this instance

  6. #6
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: VBA code to filter pivot table by 2 separate lists

    Hi,

    I can find any way to connect to the pivot data myself

    a solution could be to copy the pivot and past to a table as values and then get the data as I have given in the answer.

    sorry to disappoint.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 04-24-2020, 04:56 AM
  2. Help: Print Pivot Table Report TO pdf. BY Filter AS Separate Page
    By happydays886 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-25-2017, 10:21 AM
  3. Need a VBA Code to filter Pivot Table
    By itsanand in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-16-2017, 08:10 AM
  4. [SOLVED] how to filter a pivot table using a separate filter
    By FrancisM2411 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 11-29-2016, 04:10 AM
  5. Replies: 0
    Last Post: 07-14-2016, 03:51 PM
  6. Filter Pivot Table based on Combo Box on separate tab
    By ctpoodle in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 12-03-2013, 10:00 AM
  7. Separate Pivot Table Filter
    By laguna92651 in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 11-02-2013, 02:01 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1