Generating large numbers of partitions using Excel
Quite often when I’m doing proof-of-concept type work I find myself in the situation where I need to build a cube with near-production data volumes, and in order to make sure that performance is good I have to partition that cube. However setting up tens or even possibly hundreds of partitions in BIDS manually is no-one’s idea of fun, so how can you automate this process easily? If you’re using a SQL Server datasource then you should try using the functionality built into the Analysis Services Stored Procedure Project:
But what if you’re using an Oracle datasource or hit a bug with the ASSP code? Most consultants have a preferred method (such as their own custom code, or SSIS packages) but I thought I’d blog about the most commonly used approach which is to use Excel. Here are the steps:
- Your starting point should be a cube with just one partition in each measure group.I would recommend not putting all your data in this partition, but create it as a slice of the data, the first of the partitions you want to create. So you’ll probably want to make it query-bound rather than table bound, and set the Slice property appropriately (see here for why this is important).
- Open up SQL Management Studio and expand the tree in the Object Explorer so you can see the partition for your first measure group then right click and Script Partition As -> CREATE To. This will open a new XMLA window and give you your template XMLA command to create a partition.
- Let’s say we are going to partition by month, we have three months and they have surrogate keys 1 to 3. Our template partition is correctly configured for Month 1 and we want to be able to alter this template for months 2 and 3, so we’re going to ‘parameterise’ the following properties:
- ID – so, if your existing ID property is set to "Month_1", we need to replace the 1 with a string we can easily find with a search and replace like "@@@", making the new ID "Month_@@@"
- Name – which is usually the same as the ID
- Query Definition – you will have a Where clause in the SQL query behind the partition which is something like "Where Month_ID=1" and this should be changed to "Where Month_ID=@@@"
- Slice – the tuple will be something like "[Period].[Month].&" which again should be changed to "[Period].[Month].&[@@@]"
- Copy this XMLA command text into a cell in a new Excel workbook, say cell A1. Make sure you paste the text into the formula bar and not directly onto the worksheet – you want it all in one cell.
- Underneath this cell we’re going to use Excel formulas to take this template and generate the XMLA needed for all the partitions we want. In cell A2 enter the value 1, in A3 enter 2 and so on for as many months as you need. Remember in Excel if you enter values like this that increment by 1, if you select that area then drag it downwards Excel will automatically fill the new cells with incrementing values
- In cell B2 we’re going to use an Excel formula to replace the string @@@ with the value in A2. So something like the following will work:
- You can then copy and drag this formula downwards, and you’ll see all your new XMLA commands to create partitions appear in B3 and the cells underneath
- Copy and paste the new XMLA into a new XMLA query window in SQL Management Studio
- You may find that some unwanted double-quotes have appeared now. You need to replace the double sets of double quotes ("") with (") and the delete the single sets of double quotes. So first do a find and replace on "" and change it to something like @@@, then do a find and replace to delete all instances of ", then do another find and replace to change @@@ to ".
- You now need to wrap these XMLA commands in a batch statement so they can be run together. So paste the following text before the first Create:
and this at the very end:
- Now delete your original partition and execute the new XMLA batch command you’ve just created and hopefully you’ll have your new partitions created. You can then process them.