This is my code in PS:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices.Tabular")
$serverName = "panya\taylor";
$databaseName = "FreshDesk";
$tableName = "Metrics";
$measureName = "TestAuto";
$measureExpression = "SUMX ( FactTickets, FactTickets[PriorityID] * FactTickets[StatusID] )";
$svr = new-Object Microsoft.AnalysisServices.Tabular.Server
$svr.Connect($serverName)
$database = $svr.databases
$db = $database.GetByName($databaseName)
$table = $db.Model.Tables.Item($tableName)
$measure = new-Object Microsoft.AnalysisServices.Tabular.Measure
$measure.Name = $measureName
$measure.Expression = $measureExpression
$table.Measures.Add( $measure )
$db.Model.SaveChanges()
However it is giving me an error You cannot call a method on a null-valued expression.
Can't figure it out. The error is thrown at this line:
$table = $db.Model.Tables.Item($tableName)
but none of the variables used here is NULL
.