Date autogrouping for pivot tables in Excel Scripts?

Anna Neibling 0 Reputation points
2024-02-28T18:53:54.62+00:00

I'm recreating a few VBA scripts in Automate, since they broke with recent Office updates anyway.

Is there a way to mimic the way that either .AutoGroup from VBA (previously), or just manually adding a pivot table field based on a date automatically creates nested columns for Years (column name), Quarters (column Name), etc?


e.g. If I modify the example Farm script to have dates instead of the Farm column as so, and add "Date" as a column in a pivot table... User's image ... Excel automatically creates the following columns. User's image

If I record that process as a script and try to run it, it errors out at the first reference to

getHierarchy("Years (Date)")

If I only run the part where it creates the table, it turns out it only added the actual dates. Any ideas, short of creating new columns in the source table?User's image

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
870 questions
0 comments No comments
{count} votes