+ Reply to Thread
Results 1 to 37 of 37

Filter pivot by date

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Filter pivot by date

    I need to figure out how to filter the pivot table in the attachment by the Posted date. I only want to look at the data for dates within 30 days of today, and can't figure out how to do that manually, much less programatically. The attachement is a small sample of a huge report I receive; all I get is the pivot, which contains tons of information. I filter it down by my various criteria, but that's still hundreds of thousands of lines. Limiting to the last 30 days can make a huge difference, but I can't find the trick to it. Any help is greatly appreciated.

    Thanks,
    John
    Attached Files Attached Files

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Filter pivot by date

    this seems to do what you want....I think...you can change the -90 to whatever time frame you want....

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Filter pivot by date

    Ernest,
    Apparently, YOU ROCK!. I'm testing it, and so far it hasn't failed. I'll update again once I'm thoroughly convinced. Thanks for teachming me the CDATE function; I wasn't aware of that one.

  4. #4
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Filter pivot by date

    I had just worked on this last week and was trying to do the same and it wasn't quite working and then I determined the dates weren't really matching so I tried cdate()....so it helped both of us....glad I help....have a great day

    thanks for the "*"

  5. #5
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Filter pivot by date

    I hate it when a good solution doesn't want to work for me. Below is how I tried to use the code. I'm getting an error 13 when I run it now. Any ideas?
    Please Login or Register  to view this content.

  6. #6
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Filter pivot by date

    well a few things....the data set is different because I don't have the BUDGET_REF and I don't know what .Position = 7 becuase in the original data set there weren't 7 columns.....I stepped through this and bypassed the errors (none were 13) and the For loop worked fine.....can you upload a small version of the data you are applying this macro....

  7. #7
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Filter pivot by date

    That's what I had in the original attachment, and for that data set the macro worked fine. Now when I try it on the actual workbook I get the error 13. I thought I might have plumbed it into my existing code wrong, so tried the code as shown below. I got the same error. The error is occuring on the CDate line:
    Please Login or Register  to view this content.
    Here's the code as implemented this last time:
    Please Login or Register  to view this content.

  8. #8
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Filter pivot by date

    which error 13 is it?.....Stack overflow or Type mismatch?

  9. #9
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Filter pivot by date

    Type mismatch

  10. #10
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Filter pivot by date

    that's what I thought....the example file the dates on the 2nd worksheet are not real excel dates. they are text versions of dates. XL dates are really numbers "Formatted" to look like dates. If you try to compare one to the other it gets stupid....let me try a few things....

  11. #11
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Filter pivot by date

    I though it might be the date issue but I can run it either way....can you upload a new macro enabled file?....

  12. #12
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Filter pivot by date

    Done. Original file in xlsm format.
    Attached Files Attached Files

  13. #13
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Filter pivot by date

    right, there is no macro....can I get the file with the FilterData() macro?

    I'm trying to see everything you see, without the company confidential stuff....because I can't duplicate the error....

  14. #14
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Filter pivot by date

    Sure, attached, but in the attachment the macro works. I can't upload my full pivot, as the file is huge. So I have to select some data, doubleclick, delete about 40 columns of data and about 300K rows to create something small enough to attach, and build a pivot from that that vaguely resembles my original data set.
    Attached Files Attached Files

  15. #15
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Filter pivot by date

    very weird....so here is a couple of things to try on the "real" data set....take out the Cdate on the Now() - 90 side of the equation....then run the macro....if the error goes away verify that the right dates were hidden. If that doesn't fix the error then remove the Cdate on the PTItem.value side and run the macro...verify the data....if neither fix the error try this....

    Please Login or Register  to view this content.

  16. #16
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Filter pivot by date

    Trifecta. I got the Error 13 on all three tries. Here's how I did each one:
    Please Login or Register  to view this content.
    So then I thought, why not take out the CDate altogether? So I did this:
    Please Login or Register  to view this content.
    No error! But.... the result isn't what I expect. Looking at 2012, 2013, and 2014, January and October are turned off, some of November is turned off, but I have 12 and 13 on for all other results (in other words, Feb 2012 is on, when I want it off).

  17. #17
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Filter pivot by date

    convert your dates to real XL dates in the raw data section....refresh the PT and run the macro....to convert to REal date check out the DATEVALUE() function....

    ACTUALLY: check to see if your dates are real XL dates....in an open cells type this

    Please Login or Register  to view this content.
    TRUE = real XL date
    FALSE = TEXT Date

  18. #18
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Filter pivot by date

    That's part of the problem; I have access to the pivot, not to the raw data. The dataset is too large to pull in all the detail, so I'm stuck with trying to work with the pivot table, not the raw data.

  19. #19
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Filter pivot by date

    or try this....sorry for all the confusion....

    Please Login or Register  to view this content.

  20. #20
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Filter pivot by date

    understood...try the solution in post #19

  21. #21
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Filter pivot by date

    Still getting a type mismatch. Also, doing your date check, the results are FALSE, so it's text dates.

  22. #22
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Filter pivot by date

    so in the example file you sent there is a "Sheet2" which I assume is a pared down version of the file you get. In the Posted_Date column can you convert this to real XL dates? If you can't I'm out of ideas except to link this post to the "I'm totally lost" forum....

  23. #23
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Filter pivot by date

    Actually, the Pivot is the pared down version of the file I get. Sheet2 is a pared down version of the data I can pull from my original pivot table, which I then used to build the pivot in the workbook.

    It seems that the subject dates are text dates, but so are the dates in my example file. So why does the code work on one and not the other? I'm about to leave for the day, so probably won't be able to respond until tomorrow. I appreciate all the help you've given so far.

  24. #24
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Filter pivot by date

    No problem...I'm glad to help...I might send this link to the Water Cooler forum....in there is a Call in the Calvery area....have a great night...

  25. #25
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Filter pivot by date

    May you try this code:
    Please Login or Register  to view this content.
    This will create a log file in the same folder as the workbook for any items that may not be converted to dates - if you may post this file it could assist to debug the issues.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  26. #26
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Filter pivot by date

    Sorry I didn't get back to you yesterday. I understand the concept, but we have an issue with saving the log file; the folder is protected, so I can't save a document in it. Can we save the log file to my desktop instead?

  27. #27
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Filter pivot by date

    Yes - you must only change this line to the path you wish:
    Please Login or Register  to view this content.

  28. #28
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Filter pivot by date

    Okay, changed by adding the below section:
    Please Login or Register  to view this content.
    Result was a valid file, containing only these two lines:
    Please Login or Register  to view this content.

  29. #29
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Filter pivot by date

    OK - was pivot table filtered correctly by the code? If not, may you give example where it did not work?

  30. #30
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Filter pivot by date

    Yes, except that it left blanks in. I revamped your code slightly to turn off whatever isn't a date, and that appears to be working. Please let me know if you see any problems with the way I've changed it.
    Please Login or Register  to view this content.

  31. #31
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Filter pivot by date

    You may shorten a little bit:
    Please Login or Register  to view this content.

  32. #32
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Filter pivot by date

    Since I really don't need to log my errors, because the blanks are going to show up every time, I think we can make it even shorter:
    Please Login or Register  to view this content.
    That should work, shouldn't it?

  33. #33
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Filter pivot by date

    Yes - you may prefer only to comment out the error logging in case of future issues.

  34. #34
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Filter pivot by date

    That's a good thought. No sense in reinventing the wheel, is there?

    Thanks for all your help on this.

  35. #35
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Filter pivot by date

    You are welcome.

  36. #36
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Filter pivot by date

    @ Izandol - Thanks for helping out on this....it was bizarre for me because my code worked perfectly on my system....thanks for helping out and I'm glad it got resolved - Great Job - have a star from me....

  37. #37
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Filter pivot by date

    Thanks to you too.

+ 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. Pivot Table: OR condition filter on Multi Date/Sum Filter
    By ddalt10 in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 11-09-2013, 12:49 PM
  2. [SOLVED] How to set a 'Date Filter' on a field in the 'Report Filter' section of a Pivot Table?
    By Rhino_dance in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 03-28-2013, 11:01 AM
  3. Date filter on Pivot Table?
    By umss in forum Excel General
    Replies: 1
    Last Post: 03-27-2012, 03:33 AM
  4. Filter several pivot tables by one programmed date range filter in Excel 2003
    By olewka in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-08-2011, 11:49 AM
  5. Pivot Table Date Filter
    By coolzero in forum Excel General
    Replies: 1
    Last Post: 07-09-2010, 04:11 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