+ Reply to Thread
Results 1 to 31 of 31

Pivot table Help

  1. #1
    Forum Contributor
    Join Date
    11-01-2006
    Posts
    113

    Pivot table Help

    Hi All,

    Attached Report Showing Revenue,Cost and profit.This report is used to prepare on Monthly basis.Based on Workings i work out pivot Table where i show the report.

    Now i need to show Cummulative profit in a separate column every month i.e When i work out Nov Statement ,it should include october & November profit,when i prepare Dec Statement it should include October+november+December Profit.

    Anybody help me out

    Thanks in Advance

    MNK
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    11-01-2006
    Posts
    113
    Can anybody help me out

    Thanks

  3. #3
    Forum Contributor
    Join Date
    11-01-2006
    Posts
    113
    Is this Possibe !!!!!!!!!!!!!!!!!!

  4. #4
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    I worked on this on and off today for a couple of hours. It seems difficult.

    If the data table had profit in it, that would make life easier. But, since Profit is already a calculated field .... Let's just say, I would know how to do it in Access, but it would take a subquery ... which is not something pivot tables support (as far as I know).

    On the other hand, I am NOT a great authority on Pivot Tables.

    So, basically, what I am thinking is that you need a formula next to the table that does a SUMIF for revenue and subtracts a SUMIF for each of the costs.

  5. #5
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Strike that ... can't use SUMIF because you need BOTH customer and department to match. So, you need several SUMPRODUCTS. Ugh, this is really getting difficult.

  6. #6
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Here, for example, is the formula required for cell F9:

    Please Login or Register  to view this content.
    and even that is too simple, because it is using a 'fixed' reference for the Department, and we would have to complicate the formula to adjust for the fact that the department info is intermittent.

    I think the only satisfactory answer is to find a way to do it in the pivot table. And I have not been able to find a way to do that in a single pivot table.

    Wait ... I just had another idea to try. I haven't given up yet.

  7. #7
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    I tried using MS Query. Basically, what you would have to do is to replace the pivot table with custom controls (which would allow users to select what they now can select with the Pivot Table page and Field selections), then build the SQL for the query they want to run.

    It would work, but would be an enormous VBA effort.

    Now I give up.
    Last edited by MSP77079; 01-20-2007 at 10:33 PM.

  8. #8
    Forum Contributor
    Join Date
    11-01-2006
    Posts
    113
    It is an great effort by you.Thanks

    is there any simple way to solve this ?

    Appreciate your suggestions

    Thanks

  9. #9
    Forum Contributor
    Join Date
    11-01-2006
    Posts
    113

    Help

    Can anyone suggest best way

    Thanks

  10. #10
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    Not a answer your going to like

    You could add a second table with same criteria. See attached


    VBA Noob
    Attached Files Attached Files
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  11. #11
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Hi Noob, Good suggestion. Hiding the extra columns, as you have done, makes it appear as if it is a single table.

    Depending on how users are going to interact with the Pivot Table ... putting the tables right next to each other might be an issue if users want to be able to move fields from Page to Field level (requiring more columns for the first Pivot Table).

    To facilitate this, one could:
    1. leave additional, blank, columns between the two tables
    2. use Data >> Group to make hiding and showing those extra columns easier

    The final problem is keeping the two tables in sync as the user makes various selections for page and field filters. This requires VBA, which I have done before (so, I should have thought to mention this!). There is a Worksheet_PivotTableUpdate event which could be used to trigger the VBA that keeps the two tables in sync.

  12. #12
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi ...

    If I may jump in ...
    Do you mean your pivot table should retain the possibility of selecting Oct-Nov-Dec independently and, at the same time, have another column which groups all three months ...( i.e "All" in the month selection...) ...?
    HTH
    Carim


    Top Excel Links

  13. #13
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi again,

    Can you change your format and have Month field appearing as a column ...?

  14. #14
    Forum Contributor
    Join Date
    11-01-2006
    Posts
    113
    Thanks both VBA Noob & MSP77079

    What MSP77079 saying is absolutely right.If iam going to select for Nov data or sub-select onsite/offshore problem persists.is it possible with VBA ?

    Thanks

  15. #15
    Forum Contributor
    Join Date
    11-01-2006
    Posts
    113
    Hi carim,

    It doesn't allow me to change Month in Column in Pivot1

  16. #16
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi,

    Attached is what I meant ...
    User can pick a given month in cell C8 ...
    Attached Files Attached Files

  17. #17
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Hi all,

    I was working on the VBA to align the two tables. I have not yet looked at Carim's suggestion, will do that now.

    If the solution ends up with 2 pivot tables, here is the first part of the code that will be required (aligns the page fields and the current page selections):

    Please Login or Register  to view this content.
    I will post the workbook when I have it completely working. But, first ... to look at Carim's suggestions.

  18. #18
    Forum Contributor
    Join Date
    11-01-2006
    Posts
    113

    Thanks

    Hi Carim,

    It's Simple and rocks.The only way is to brought down the month column in data feild.I kept away the month from data column for specific reason.Is it anyway possible to keep away month from data feild.
    Awaiting your reply

    Thanks

  19. #19
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi,

    In this layout, the field Month is a Column ... (it is not in the Data area...)

    What is your "specific reason" for not having Month as a column ...?

  20. #20
    Forum Contributor
    Join Date
    11-01-2006
    Posts
    113
    Hi MSP77079,

    What Carim suggesting it helps,but somer reason i kept Month in outer column.If your VBA helps to keep Month in outer column as my first post,it solves my problem like anything

    Thanks for all of your efforts

  21. #21
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    I like Carim's solution as well, and am very happy to stop working on the VBA for the 2-table solution.

    Just to be sure I am not missing anything ... it appears to me that if one wants to see the "YTD" numbers in the single table, they MUST display all months. So ... the single table allows the user to see the YTD total or any single month; but, not both unless they display all months. Correct?

    ----------------- ADDED LATER -------------
    Looks like nandhamnk and I were writing at the same time. And, just for the challenge of it, I will go ahead and keep working on the 2-table solution to see if I can make a go of it.

    There is one complication hidden in the Noob's work. He had to manually select which departments to show in order to get the customers to align. I fear (cannot prove) that this will be more problematic as the test data is replaced with real data. But, perhaps not. We shall see.
    Last edited by MSP77079; 01-21-2007 at 01:16 PM.

  22. #22
    Forum Contributor
    Join Date
    11-01-2006
    Posts
    113
    Thanks for your support MSP77079

  23. #23
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203

    Stuck ...

    What I have so far is code to align the two pivot tables so that they have exactly the same page and field selections. The problem I have (as i expected might happen) is this ... suppose you select November ... the number of rows in the second pivot table will exceed the number of rows in the first pivot table, even if the all customers who do not show up in the first table are hidden in the second.

    Why? Because for Department 3 (for example) only 2 customers had sales in November, but 19 customers have data for Department 3 for the 3 month period.

    So, I am stuck at trying to figure a way around that problem.

    meanwhile ... here is the code I have for keeping the two tables aligned.

    Please Login or Register  to view this content.

  24. #24
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Thinking about this some more ... if the rows are not going to line up, in general, then there is no need to have the 2 pivot tables on the same worksheet.

    So, the easiest thing to do to create the all-months pivot table is to copy the table from Sheet1 to a hidden sheet. Then simply change the month page setting to "All". This greatly simplifies the code.

    If you have a GETPIVOTDATA formula pointing to each of the Profit cells in Pivot Table 1 and replace the pivot table cell reference with the pivot table on the hidden sheet, you will get the Profit for all months.

    The trick (which I have not yet figured out) is to set up the GETPIVOTDATA formula pointing to each of the Profit cells in Pivot Table 1. Excel does this so automatically when you simply type in "=" and click on the cell reference. But, I can't seem to figure out how to duplicate that in VBA.

  25. #25
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Well, I was unable to find an elegant way to create the GETPIVOTDATA formulas. So, I resorted to brute force (or was it brutal force?).

    The attached is written as 1 Event routine and 2 subroutines:
    + the Worksheet_PivotTableUpdate Event calls
    + copyPivotTable, which copies the pivot table to a hidden sheet and changes the month page selection to "All", then calls
    + WriteGETPIVOTDATA, which ... well ... writes the GETPIVOTDATA formulas

    If anyone comes up with a less brutal way to do the latter, it should be easy to drop in the improvement.
    Attached Files Attached Files
    Last edited by MSP77079; 01-21-2007 at 07:29 PM. Reason: Fix some formatting in attachment

  26. #26
    Forum Contributor
    Join Date
    11-01-2006
    Posts
    113

    Thanks for your Effort

    Thanks MSP77079.

    You Made an enormorous try.

  27. #27
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Is this NOT what you wanted? I thought it was more than a try, I thought it was a success? No?

  28. #28
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203

    If anyone is still following this thread ...

    I have found the "key" to creating the GETPIVOTDATA formula without resorting to brute force.

    The example below is not based on the workbook attached above, but it illustrates the principle. When I have time, I will incorporate this into the WriteGETPIVOTDATA routine in the workbook attached above.

    Please Login or Register  to view this content.
    Last edited by MSP77079; 01-22-2007 at 12:22 PM.

  29. #29
    Forum Contributor
    Join Date
    11-01-2006
    Posts
    113

    Smile Thanks

    Thank you very much

  30. #30
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203

    Final version, I think ...

    I like this one SOOoooo much more than the earlier version. For one thing, it allows the correct totals by Department and overall, not just by customer. And, because it is using built-in features of pivot tables (vs. brute force of VBA logic), I feel more confident that it will survive what users might throw at it.

    I learned a lot doing this project!
    Attached Files Attached Files

  31. #31
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    One thing I did not address in the earlier version is ... what if the Profit column is moved, so that it is not the last column in the data fields?

    This version solves that issue.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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