Any Pivot Table experts? Filter by Date Range

elayem

Board Regular
Joined
Sep 11, 2009
Messages
51
Hi All,

None of the search results have come up for me on this. Is there any way to automate filtering a Pivot Table by a date range?

For example, I have data in Column A w/ Dates, e.g. November 12, 2012 and Values in Column B. 1, 2, 3, etc. There may be multiple data on a particular date (i.e. 5 more rows with November 12, 2012 and corresponding data).

I wanted to set up 2 cells where users can input the Start Date and End Date and have the Pivot Table automatically reflect this date range. Is this possible? E.g. User will input November 30, 2012 in cell D1 and December 5, 2012 in cell E1.

Thanks in advanced,
Elayem
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
hi

Here is one way. For this set up of data. Cell A1 "Dates". Cell B1 "Values". Cell D1 "Start Date". Cell E1 "End Date". Data below headers in contiguous blocks - so no blank rows. Dates & values from row 2 to row xx. Start date in cell D2. End date in cell E2. Create normal defined name ranges for the tables. Range "A1:Bxx" name MainTable. Range "D1:D2" name Start. Range "E1:E2" name End. Save & close the file.

From a new file, ALT-D-P. Choose external data source. Get Data. Excel files, OK. Choose the file, OK. See Add Tables. Select one table to add, then close the dialog box. Now in MS Query hit the SQL button and change whatever is there to
Code:
SELECT M.Dates, M.Values
FROM End E, MainTable M, Start S
WHERE M.Dates >= S.[Start Date] AND M.Dates <= E.[End Date]
OK to enter that, now see the (date filtered) results set. Hit the 'open door' icon to exit MS Query. Then choose finish & set up the pivot table how you want it. If you want you can open the source data file & the worksheet containing the pivot table can be moved into that file.

Now change the start and end dates then refresh the pivot table. If you want you could add a little VBA so that the pivot table refreshes on change to either start or end date input cells.

HTH
 
Upvote 0
Hi. What file type am I saving the original data? When I am browsing for that file later on, it doesn't show up because it's only searching for data files.
 
Upvote 0
I don't know what file type you're saving the original data as. I saved it as an Excel file.

If it is not an Excel file, what file type do you want?
 
Upvote 0
I want excel, but during this step:

From a new file, ALT-D-P. Choose external data source. Get Data. Excel files, OK

It couldn't find the excel file... Let me go back to check.
 
Upvote 0

Forum statistics

Threads
1,216,922
Messages
6,133,512
Members
449,808
Latest member
BoredSean

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top