Open an Excel PivotTable with the Latest Month-End Date Selected
Question details
The user needs an Excel PivotTable based on daily SQL Server data to open with the latest valid month-end date selected or filtered.

- Product
- Microsoft Excel PivotTable with SQL Server data
- Device & OS
- not provided
- Scenario
- A report uses daily source data and a PivotTable slicer for dates. The user wants to identify valid month-end dates and display the newest available month-end automatically when the workbook opens.
- Observed behavior
- A date slicer can retain a saved selection, but it does not natively detect and select a newly added latest month-end item on every workbook open.
Decide whether “month-end” means the calendar month-end date or the final available business or loaded date in each month. Ensure the PivotTable data source is refreshed before applying a latest-date filter or running any automation.
Create a reliable month-end field in the SQL Server source
Use this approach when the source data should consistently identify which daily records belong to a valid month-end before Excel receives the data.
Add a dedicated MonthEndDate or IsMonthEnd field to the SQL Server view or query used by the PivotTable. This avoids relying on manually selected slicer values and gives the report a dependable field for filtering.
For calendar month-end records, compare the date with SQL Server's EOMONTH result. For business month-end or the last loaded date, calculate the maximum available date within each year and month instead.
In the SQL Server query or view that feeds Excel, create an IsMonthEnd field using logic such as CASE WHEN CAST([Date] AS date) = EOMONTH(CAST([Date] AS date)) THEN 1 ELSE 0 END.
If weekends, holidays, or incomplete months are possible, use a window calculation that finds MAX([Date]) for each YEAR([Date]) and MONTH([Date]), then mark the row matching that maximum date as the valid month-end.
In Excel, select the PivotTable and choose PivotTable Analyze > Refresh, or use Data > Refresh All, so the new MonthEndDate or IsMonthEnd field is available.
Place IsMonthEnd in the PivotTable Filters area and select 1, or connect a slicer to MonthEndDate through PivotTable Analyze > Insert Slicer.

Return only the latest valid month-end date from the source query
Use this method when the workbook only needs to display the newest completed or valid month-end report when it opens.
Use a saved filter or VBA to update the date slicer after refresh
Use this approach when users must retain all historical month-end dates in the PivotTable but the slicer should move to the newest item automatically.
Create and review month-end PivotTable reports with WPS Office
If you need a free, lightweight spreadsheet application for reviewing and organizing month-end reports, WPS Office provides a familiar spreadsheet workspace with PivotTable tools and a smooth transition from Excel files. Open compatible workbooks, review filtered report data, and continue working in an Office-style interface.

Frequently Asked Questions
How do I identify the last available date in every month when the calendar month-end falls on a weekend?
Treat the business month-end as the maximum available date within each year and month. In SQL Server, calculate MAX([Date]) over the year-and-month group and mark the matching row as the valid month-end.
Can an Excel slicer automatically select the newest date after a data refresh?
Not by using a saved slicer selection alone. A saved filter retains its existing item; to select a newly added latest item automatically, filter the source query to that date or use a VBA macro after refresh.
Should I use an IsMonthEnd flag or a MonthEndDate column in my PivotTable?
Use IsMonthEnd when you only need to include or exclude month-end rows. Use MonthEndDate when users need a slicer or filter that displays the actual valid reporting dates.
Why does my PivotTable not show a new month-end date after the SQL data is updated?
Refresh the connection and PivotTable through Data > Refresh All. Also confirm that the source range, table, query, or Data Model includes the new rows and that the month-end calculation recognizes the new date.
Can I keep historical month-end reports while opening on the latest one?
Yes. Load all valid month-end rows, use MonthEndDate in a slicer, and use VBA to clear the slicer and select the maximum date after the workbook refreshes. Without VBA, the slicer will keep the last saved selection.




