How to add a calculated measure to SSAS cube using XMLA
May 20, 2010 Leave a comment
Needed a way of programatically adding a calculated measure to a cube after the cube had been built and processed, the xmla below will do this – Run in SQL management studio as xmla query.
<Alter AllowCreate="true" ObjectExpansion="ExpandFull" xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<Object>
<DatabaseID>CVCC</DatabaseID>
<CubeID>CVCC</CubeID>
<MdxScriptID>MDXScript</MdxScriptID>
</Object>
<ObjectDefinition>
<MdxScript>
<ID>MDXScript</ID>
<Name>MDXScript</Name>
<Commands>
<Command>
<Text> <!–if you want to figure out what to paste below build the calculation in visual studio then look at the ‘script view’–>
CALCULATE;
CREATE MEMBER CURRENTCUBE.[MEASURES].PcntEscalations
AS [Measures].[NumEscalations]/[Measures].[NumCalls],
FORMAT_STRING = "Percent",
NON_EMPTY_BEHAVIOR = { [NumCalls], [NumEscalations] },
VISIBLE = 1 ;
</Text>
</Command>
</Commands>
</MdxScript>
</ObjectDefinition>
</Alter>
<Object>
<DatabaseID>CVCC</DatabaseID>
<CubeID>CVCC</CubeID>
<MdxScriptID>MDXScript</MdxScriptID>
</Object>
<ObjectDefinition>
<MdxScript>
<ID>MDXScript</ID>
<Name>MDXScript</Name>
<Commands>
<Command>
<Text> <!–if you want to figure out what to paste below build the calculation in visual studio then look at the ‘script view’–>
CALCULATE;
CREATE MEMBER CURRENTCUBE.[MEASURES].PcntEscalations
AS [Measures].[NumEscalations]/[Measures].[NumCalls],
FORMAT_STRING = "Percent",
NON_EMPTY_BEHAVIOR = { [NumCalls], [NumEscalations] },
VISIBLE = 1 ;
</Text>
</Command>
</Commands>
</MdxScript>
</ObjectDefinition>
</Alter>