0

I am in need of my pivot table to preserve the date filed as mm/dd/yyyy. I have selected the field and attempted to set the custom value, I have unchecked the Autofit Column and made sure the Preserve Cell Formatting was checked. In experimenting I discovered that if I chose an individual cell (vs. Range of cells) that I could preserve the single cell by choosing the "Format" from the "Cells" task on the menu bar. With a Pivot Table that will have hundreds of potential cells this is not a practical approach to go cell by cell to make the change. Additionally, I found that I could select upwards of 10 cells and follow the above steps with success but strangely a single cell within the range would not format and would revert back to m/dd/yyyy. I need the mm/dd/yyyy in the Pivot Table for an import of records into another system that is not forgiving of the date format. Since the field is displayed as an element of a row the format cannot be set using the field settings option.

Pivot Table Fields

Results after refresh of Pivot Table

Field Settings when entered under "Rows"

5
  • Are you formatting the cells on the sheet, or the PivotTable field itself? Right click > Field settings > Number format, or in the field list pane, use drop-down arrow > Field settings. Change it in there and it should "stick".
    – AdamV
    Commented May 11, 2021 at 12:09
  • The number format is not available when using the field in a Row setting.
    – Gerry P.
    Commented May 11, 2021 at 23:34
  • It is for me (I checked before commenting, using an example which actually had dates). When the field is used as a value, you see "Value field settings". For a row or column you get "Field settings". BUT if the PivotTable is using the data model, you don't get this option. When you created the PT, did you tick the box to "Add this data to the data model"? or are you using PowerQuery as a starting point perhaps?
    – AdamV
    Commented May 12, 2021 at 10:49
  • I did not tick the Add this data to the data model as I am only sourcing one table of data. My date field is not under the "Values" section but rather is under the "Rows" section. i.sstatic.net/VKOnG.png
    – Gerry P.
    Commented May 13, 2021 at 13:00
  • Here's mine, in Excel 2016: !Screenshot of Number format button for PivotTable date field
    – AdamV
    Commented May 14, 2021 at 11:41

2 Answers 2

1

That's ugly. I see the same behaviour in that latest version of Excel 365, so it's not limited to Excel 2010. I'm not sure there is a solution to be achieved with Excel's settings.

The only thing I can advise is to automate a manual format after each refresh. In the sheet with the pivot table, right click the sheet tab, then click "View Code". Paste the following code into your code window and adjust the column letter to suit your data layout.

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
    Columns("L:L").NumberFormat = "mm/dd/yy;@"
    Debug.Print "ran macro to set date format in pivot table"
End Sub

Remember to save the file as a macro-enabled workbook with the .xlsm extension.

1
  • The Macro works great!!! Thanks I must say it is frustrating when features of Excel 365 fail to work.
    – Gerry P.
    Commented May 11, 2021 at 23:51
0

convert the 'date' column into 'text' using TEXT function [TEXT(value,"mm ddd yyyy")]. Use the latter (text) column in pivot instead of the first. Pivot will give you the date in the required format. The format can be changed as required.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .