machumpion
Registered User.
- Local time
- Today, 04:58
- Joined
- May 26, 2016
- Messages
- 93
I have a table featuring names, sales (called sumofrevenue2), and a date field (called expr1) formatted as Oct-2016, Nov-2016 etc.
I need to make a pivot table for each name, show their sales per quarter by year and then show the 2016 quarterly sales as a % of 2015 quarterly sales.
I am trying to use VBA to do this.
Here is the code I'm using to "Show value as" to calculate 2016 sales as % of 2015
With ActiveCell.PivotTable.PivotFields("sum of sumofrevenue2")
.Calculation = xlPercentOf
.BaseField = "years"
.BaseItem = "(previous)"
End With
The code is not working as intended. The basefield "years" is not an actual field in the source data. It appears when the date field Expr1 is added as a column pivot table label. I suspect that is why.
How can I use VBA to do a % of calculation for a date group that is not explicit in the source data? Thanks!
possible relevant information
When the base field is set to "years", the actual real years field gets changed to "years2"
When the base field is set to "years2", the actual real years field remains "years"
When the base field is set to "Expr1", no % of calculation occurs.
I need to make a pivot table for each name, show their sales per quarter by year and then show the 2016 quarterly sales as a % of 2015 quarterly sales.
I am trying to use VBA to do this.
Here is the code I'm using to "Show value as" to calculate 2016 sales as % of 2015
With ActiveCell.PivotTable.PivotFields("sum of sumofrevenue2")
.Calculation = xlPercentOf
.BaseField = "years"
.BaseItem = "(previous)"
End With
The code is not working as intended. The basefield "years" is not an actual field in the source data. It appears when the date field Expr1 is added as a column pivot table label. I suspect that is why.
How can I use VBA to do a % of calculation for a date group that is not explicit in the source data? Thanks!
possible relevant information
When the base field is set to "years", the actual real years field gets changed to "years2"
When the base field is set to "years2", the actual real years field remains "years"
When the base field is set to "Expr1", no % of calculation occurs.