+ Reply to Thread
Results 1 to 3 of 3

Pivot tables based on certain conditions

  1. #1
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Pivot tables based on certain conditions

    Hi experts, gurus, MVPs and guests,

    I am trying to write a code that compares the surplus/deficit of two pivot tables in my "Compare" worksheet. I tried with some codes but could only create a single pivot table but not all the table that is supposed to be. When I used For Loop, the code did not create Pivot Table at all. Also I would want to create all the tables with name - ID & "_Table".

    I have attached the workbook with desired output in the "Compare" worksheet.

    I haven't added code here. My understanding level on this matter is not that great so even if I present code here it wouldn't be that worthy. I appreciate your time and suggestions / help.

    Thank you
    Roshan Shakya
    Attached Files Attached Files

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Pivot tables based on certain conditions

    The quickest way, if your requirement and data are this simple, is to blend your data using Power Query (Get & Transform Data).

    Format your source data as tables - I named them tblPurchase and tblIncome, respectively. Then you can use a query like this to blend the data:
    Please Login or Register  to view this content.
    Close and load to Data Model, then you can create pivot table(s) as required.

    You can then add a Measure to your Data Model, to calculate the variance dynamically:

    Please Login or Register  to view this content.
    See sample workbook: xlf_1297276_simple.xlsx

    If you needed to handle more complex calculations / filtering, then I'd recommend loading Income and Purchase data to separate tables in your data model, and creating a "People" dimension table, with relationships to both those fact tables....

    See worked example: xlf_1297276_powerpivot.xlsx
    Attached Files Attached Files
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Re: Pivot tables based on certain conditions

    Thank you Olly. I am not that accustomed to Power Query.

    The report I have is little complicated and has multiple phases of automation, which I have done with VBA. This is the output after automation and is a phase of interpretation. I have set "Check" comment when certain condition is passed by the data. Now the problem that I have is that the "Check" comment is dynamic and changes with modification of condition. I use 2010 Excel at work and not sure if Power Query works on this version.

    I would have liked to save the list of "Check" as an array and recall this when filtering in the Pivot Table. I admit that my knowledge to save in Array variable is still primitive. I would request for helping me to understand this process. However, the final users intend to have the individual Pivot Tables for each "Check" component from 2 Sources (of output).

    I appreciate Olly for sharing this valuable information.

    Kind regards
    Roshan Shakya

+ 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. [Solved] Merge tables based on mulitple conditions
    By stalen ros in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-23-2019, 08:21 AM
  2. Pivot based on three tables
    By franzony in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 03-23-2019, 06:03 AM
  3. Function - format tables based on conditions
    By passco in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-23-2014, 07:30 AM
  4. Replies: 1
    Last Post: 05-26-2014, 10:12 AM
  5. [SOLVED] sumifs based on conditions from 2 seperate tables
    By hcyeap in forum Excel General
    Replies: 3
    Last Post: 03-14-2014, 11:02 AM
  6. Filter multiple pivot tables based on same cell value (OLAP based)
    By natsuki-hime in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-15-2012, 05:21 AM
  7. Update all pivot tables based on 1st
    By spbready in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2009, 12:00 PM

Tags for this Thread

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