Quantcast
Channel: SQL Server Analysis Services forum
Viewing all articles
Browse latest Browse all 14337

Trying to update my pivot table with powershell

$
0
0

 

 I'm trying to automate a Pivot Table update. I put outputs in the code so you can see what I'm trying to update and with
what values. I have a request to have them auto updated so users don't have to change shipdate and do a refresh. Can this be done with a Powershell script? I posted in PS forum and they suggested I try here..

To

 $date = 2015-09-07

From

 $dispshp = [DATE].[Ship Date].&[2015-09-01]

Update:

$workSheet.PivotTables(1).PivotFields("[DATE].[Ship Date]").CurrentPageName=$sdate

#Set the file path (can be a network location) $filePath ="C:\shipment.xls"#Create the Excel Object $excelObj =New-Object-ComObjectExcel.Application#Make Excel visible. Set to $false if you want this done in the background $excelObj.Visible= $true#Open the workbook $workBook = $excelObj.Workbooks.Open($filePath)#Focus on the top row of the "Data" worksheet#Note: This is only for visibility, it does not affect the data refresh $workSheet = $workBook.Sheets.Item("Customer") $sdate="{0:yyyy-MM-dd}"-f (Get-Date)# '2012-08-30 $sdate $workSheet.Select() $dispshp = $worksheet.PivotTables(1).PivotFields("[DATE].[Ship Date]").CurrentPageName#$workSheet.PivotTables(1).PivotFields("[DATE].[Ship Date]").CurrentPageName=$sdate $dispshp #Refresh all data in this workbook $workBook.RefreshALL()#Save any changes done by the refresh $workBook.Save()#Uncomment this line if you want Excel to close on its own $excelObj.Quit()

This is the error it throws...

Xcel pops up and display's message:

XML for Analysis Parser

   The restriction value provided by the consumer does not match other restrictions or refers to an unkown object.

 The PS error:
Exception setting "CurrentPageName": "Exception from HRESULT: 0x800A03EC"
At C:\powershell\pivot_table_refresh.ps1:25 char:3
+   $workSheet.PivotTables(1).PivotFields("[DATE].[Ship Date]").CurrentPageName =  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : CatchFromBaseAdapterSetValueTI


Viewing all articles
Browse latest Browse all 14337

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>