0845 643 64 63

Deploying MDX calculation scripts with xmla

If you’re a Business Intelligence developer I assume you have BIDS Helper installed. If not then stop reading this post and go and install it. Now. It adds a number of very useful features to the Business Intelligence Development Studio which provide help with many aspects of SSIS, SSRS and SSAS development.

One of my favourite utilities is the Deploy MDX Script function. This takes the calculation script for an SSAS cube (named sets, calculated measures, scope logic, etc.) and deploys it in isolation without having to redeploy and rebuild the entire cube. This is a life saver when trying to write and test complex MDX calculations, and has saved me days if not weeks of waiting around.

The Deploy MDX Script button works perfectly when deploying updated script to the development environment, but what if you want to deploy the same script changes to a testing or live environment? Is there a way of scripting the change without redeploying the entire cube?

Yes there is, by using the following xmla script. Just change the DatabaseID and CubeID elements of the Object element to point to your Analysis Services database and cube, and paste your MDX calculation script in between the <Text> and </Text> tags. Run the script in SQL Server Management Studio and it should update the cube with the new script.

This script works for SQL Server 2008 and SQL Server 2008 R2.

The CALCULATE command controls the aggregation of leaf cells in the cube.
If the CALCULATE command is deleted or modified, the data within the cube is affected.
You should edit this command only if you manually specify how the cube is aggregated.

--Paste your MDX Calculations here


And there you have it, you can update your MDX calculated members outside of BIDS without doing a full deploy.

Frog-Blog Out

6 comments on “Deploying MDX calculation scripts with xmla

  1. Stefan Wilms on said:

    A very nice trick. I have a problem with translations. When I script a cube in SSMS I get the MdxScript without CalculationProperty-Elements. Running that script results in desired changes in Members and Sets but loosing all Translations. I found the CalculationProperty-Elements in the deployment-Files for the Wizard, only. Adding those to the script is a solution.

  2. asmita bote on said:

    Hi while using above script I am getting below error :

    Executing the query …
    Errors in the metadata manager. Either the cube with the ID of ‘CEE POS BI’ does not exist in the database with the ID of ‘CEE POS UA’, or the user does not have permissions to access the object.
    Execution complete

    Can you please help me to resolve this?

    • I’m assuming that you’ve already checked the permissions? In which case the next most common cause for this is a difference between the IDs and names of the cube and databasae. Usually the ID and name are the same, but if you rename a cube or database then the name changes but the ID doesn’t.
      The script needs the ID, so double check the IDs are correct and try again.

  3. Henrique Lima on said:

    Thats a great script! Thanks. Do deployments like that could cause any impact performance wise? Would you recommend planning for a cube full rebuild after?

  4. SSAS dev on said:

    Thanks for the post. I tried to use it to deploy my MDX. The script showed error.
    XML parsing failed at line 103, column 138: Illegal name character.
    The script is the slicing of one dimension: xxx.&[0]
    It doesn’t like “&[”
    But the same script worked fine in SSAS MDX.
    How can I solve this problem?

    • Alex Whittles on said:

      You may have to escape special characters when running them in script mode from SSMS; i.e. try replacing & with “& amp;” (but with no space!)

Leave a Reply

Your email address will not be published. Required fields are marked *


371,433 Spambots Blocked by Simple Comments

HTML tags are not allowed.

Power BI Sentinel
The Frog Blog

Team Purple Frog specialise in designing and implementing Microsoft Data Analytics solutions, including Data Warehouses, Cubes, SQL Server, SSIS, ADF, SSAS, Power BI, MDX, DAX, Machine Learning and more.

This is a collection of thoughts, ramblings and ideas that we think would be useful to share.


Alex Whittles
Jeet Kainth
Jon Fletcher
Nick Edwards
Joe Billingham
Lewis Prince
Reiss McSporran
Microsoft Gold Partner

Data Platform MVP

Power BI Sentinel
Frog Blog Out