Categories
Business Intelligence Geeky/Programming SQLServerPedia Syndication

Excel 2007, OLAP Cubes: Customizable, User Defined Named Sets in Excel 2007 using VBA

In a perfect world, your master data and master data management (MDM) is set up so everyone can see things how they want. Categories of Items, Regions, etc, etc are all defined in your dimension data, and you can create hierarchies, etc that make sense and everyone is happy. But, this is not a perfect world 🙂

Some users want to see “their” items, “their” regions, etc. And they ask and ask for you to add it to the cube, but you have to deny them. Why? Because if you add their named set, you have to add all of them that are requested, that don’t make sense to 99% of the other people using the cube.

You probably could even go about doing some crazy MDX or something in your cube to create the named sets per user, but then you still have to manage it all in your MDX script in your SSAS project.

I blogged a while ago about the OLAP Pivot Table Extensions on CodePlex , which, is an awesome toolkit, but it is geared around Calculated Measures. I downloaded the code and took a gander here and there and it would be pretty easily modified to work with Named Sets (change xlCalculatedMember to xlCalculatedSet , add a radio button on adding a new calc, etc) – but, its in VS2005, and I have VS2008 (2005 BIDS, not C#), and right now I don’t feel like mucking around with that, maybe someone with more time, and more ambition can do it 🙂 – Or maybe when I get some free time I will take a look, but for now here is a solution.

I took the idea outlined at the bottom half of this blog http://blogs.msdn.com/excel/archive/2008/02/05/common-questions-around-excel-2007-OLAP-PivotTables.aspx  about named sets and creating them in macros..

Sub AddNamedSet()

Dim pvt As PivotTable
Dim strName As String
Dim strFormula As String
Dim cbf As CubeField

Set pvt = Sheet1.PivotTables("PivotTable1")
strName = "[My Mountain Bikes]"
strFormula = "[Product].[Product Categories].[Bikes].[Mountain Bikes].children"
pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, Type:=xlCalculatedSet
Set cbf = pvt.CubeFields.AddSet(Name:="[My Mountain Bikes]", Caption:="Mountain Bikes")

End Sub

That macro is pretty sweet, you can add a named set to your workbook. But, its pretty static. You have to edit the macro every time you want to add more items, it doesn’t update or remove the sets you might have, etc.

What I whipped up quick was an updated macro that lets you build customizable named sets based on data in another worksheet in your Excel file (you can imaging it coming from other sources – another Excel file, a SQL table, etc, etc). I did this with a cube we use at work, but for this example, I changed it to pull off the AdventureWorks DW SSAS DB, AdventureWorks Cube, (SQL 2005 edition)

First off, here is the macro: 

Text File of Macro: Custom_NamedSets_Macro.txt</a

Excel 2007 Workbook with Macro: Custom_NamedSets.xlsm

Sub AddNamedSet()

    ' data sheet top row must be set name [Set Name] and then item numbers after
    Dim sourceData As Worksheet
    Set sourceData = Worksheets("Data")

    Dim strName As String
    ' get the name of the set, including brackets []
    strName = sourceData.Range("A1").Value

    ' used range is the whole column, rangeVals is the item numbers
    Dim usedRange As Range
    Dim rangeVals As Range
    Dim maxRow As Integer

    Set usedRange = sourceData.usedRange

    maxRow = usedRange.Rows.Count

    ' get the item numbers
    Set rangeVals = sourceData.Range("A2:A" & maxRow)

    Dim strFormula As String
    Dim i As Integer

    ' loop through and build forumla
    strFormula = "'{"

    For i = 1 To rangeVals.Count
       strFormula = strFormula & rangeVals(i, 1) & ","
    Next i

    ' remove last comma and add last curly and tick
    strFormula = Left(strFormula, Len(strFormula) - 1) & "}'"

    ' get pivot table object
    Dim pvt As PivotTable
    Set pvt = Sheet1.PivotTables(1)

    ' Add a calculated member titled "[MySet]"
    pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, Type:=xlCalculatedSet

    ' Add a set to the CubeField object.
    Dim cbf As CubeField
    Set cbf = pvt.CubeFields.AddSet(Name:=strName, Caption:=Replace(Replace(strName, "[", ""), "]", ""))


End Sub

Sub DeleteNamedSets()

    Dim pvt As PivotTable
    Set pvt = Sheet1.PivotTables(1)

    Dim i As Integer

    For i = 1 To pvt.CalculatedMembers.Count
        pvt.CalculatedMembers.Item(i).Delete
    Next i
    pvt.RefreshTable

End Sub

Now, this was a 15-20 minute VBA hack. It could really use some cleanup, but works. What I did to make it work with Advendture Works was just put the whole “member” string in the data tab of the spreadsheet. In my case at work, I just was using item number and had some of the member string in the macro. But really you can see you could add a named set on each column, or something, you really could make this powerful. And since I added the delete, if they re-run the add, it will recreate the set, so they can modify the data and re-add. It should be expanded on and made a little more robust, but you get the idea. Now, think of how you could use this with your cubes, and how you could get your user’s thinking about ways to use custom named sets!

Categories
Business Intelligence Geeky/Programming

ADOMD.NET: Could not load file or assembly Microsoft.AnalysisServices.AdomdClient

If you are developing a .NET/ASP.net solution using ADOMD.NET locally, and everything works great, and you go to release to a production server and end up with this error:

Could not load file or assembly ‘Microsoft.AnalysisServices.AdomdClient, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91’ or one of its dependencies. The system cannot find the file specified.

You need to install the “Feature Pack for Microsoft SQL Server 2005” which you can find here: http://www.microsoft.com/downloads/details.aspx?FamilyID=50b97994-8453-4998-8226-fa42ec403d17&DisplayLang=en

Categories
Business Intelligence Geeky/Programming SQLServerPedia Syndication

Microsoft BI: Creating Local OLAP Cubes using XMLA and ascmd.exe

Most people, when using OLAP cubes, are hitting the live version that is located on SQL Server Analysis Services (SSAS). They hit it with Excel, or some other reporting tool, etc. I have blogged previously about offline cubes and how you could possibly use them.

Now, the blog I did before, I talked about creating them with Excel, and that works great for end users. But what about automating the process? What about filtering dimension members, or measure groups, etc?  Now that you can use the Panorama Gadget for Google Apps/iGoogle (http://google-pivot-tables.blogspot.com/2008/04/panorama-analytics-gadget-for-google.html) you can upload .cub files and do BI in the cloud, how cool is that!

506479481_683e31e6db

Well, one option is purchase CubeSlice – http://www.localcubetask.com/  and use that to create your .cub files. CubeSlice works great, and is a good option if you want something with a ton of options and ease of use.

You can also create .cub’s using CREATE GLOBAL CUBE syntax in MDX, and you can also use XMLA to create a .cub. Options galore! Chris Webb blogged a few years about about using XMLA to create .cub’s here – http://cwebbbi.spaces.live.com/blog/cns!7B84B0F2C239489A!877.entry  He was using the MDX Sample App (I believe that comes with SQL 2000?)

What I was looking for was an easy way to us GLOBAL CUBE or XMLA and automate it, CubeSlice is nice, but there has to be a way to replicate (at least in a basic way) what they are doing. Thinking about XMLA – as to me it seems more powerful, that was the route I chose. I didn’t want to install the MX Sample App from SQL2K, and what Chris Webb says in his blog, and other things I read, basically the problem with using XMLA to create you .cub in SQL Server Management Studio is that you can’t specify a connection string, you have to connect to an SSAS instance. Using the MDX Sample App, you can specify a local file, and then run the XMLA and it will create the .cub file. So I just need to replicate that. 

I have also blogged about using ascmd.exe here . ascmd comes with the SSAS Samples with SQL 2005 (usually located here: C:Program FilesMicrosoft SQL Server90SamplesAnalysis ServicesAdministratorascmd) . You just need to compile it and you can use it to execute XMLA. So I decided to try that. I created an XMLA file to create my cube, and then executed it with ascmd.exe

ascmd -S c:MyOfflineCube.cub -i c:MyOfflineCube.xmla

In seconds, you have an offline cube. Now, in your XMLA you can have filters, etc. You could create an XMLA file that has some kind of variable, and you could create a replace task to replace that with what you wanted filtered, think maybe based on location, or employee, etc, and then kick out personal cubes for users, etc.

One thing I didn’t really get into is how to get your XMLA script. You could figure it out for yourself, but I actually just used CubeSlice for this example. You can create an offline cube with CubeSlice and actually see the XMLA code and use that. Maybe creating the XMLA script manually/yourself would be good info for another blog post 🙂

Categories
Blogging

5 Years Ago Today…

Wow, two “X years Ago Today” this week..

5 Years ago today, I started this blog. June 19th 2004. I wish I would have started earlier. I was addicted to reading them (like crack) from like 2001-2003, and finally bit the bullet and started one in 2004. First on Blogger, then moved to WordPress (wow I jacked my SEO on that one), but then a few hosting providers later, even my own server, and here I am. Media Temple is my current hosting and I have never been happier with a hosting provider.

I do need a new theme, I wish someone would help me out! I would even pay – 50 bucks? Who wants to? I did add the “ads” about a year or so ago, and surprisingly it brings in decent money, not huge $$ but enough to pay for hosting for the year for sure.

I love blogging, I love my blog too. Why? Because it’s mine. I can blog about whatever, and it’s mine. It has been with me through 7 apartments, 3 girlfriends, 5 cities, 5 computers, 4 OS’s, 1 baby, 5 jobs, and much more. It’s always there.

People say “blogging is dead” and I don’t agree. Blogging may be dead, for the lazy. I can “tweet all day” but if I have something to really say, or put out there and think through and share, the blog is the place. I see so many A-list bloggers just let their blogs die because of Twitter/FriendFeed. For Shame. Don’t you have anything share that is longer than 140 characters? Come on.

Anyways, this blog will be around for a while, looking back I just wish I would have blogged more. Make it a ritual. Share knowledge. Share with the community (does that make me a communist? oh noes!) Have fun!

Thinking back 5 years ago, I can’t even remember much of what I was doing. in St. Cloud, MN. Working for St. Cloud Wireless Holdings. Doing ASP Classic/SQL 2000. Reading blogs with RSS Bandit and other tools. Using a PPC 6601 as a phone. Driving a Chevy Silverado 1500. Had a 1 bedroom apt, bachelor pad. Was starting to play guitar again. Never thought I would be where I am right now, never. And 5 years from now, I bet I will say the same thing 🙂

Happy Blogging! 🙂


Categories
Geeky/Programming

iTunes DJ – iPhone, Remote App – Party!

Not sure when this came about, but I just realized that there is an “iTunes DJ” in iTunes now. It obviously lets you just play a random selection it picks. But what I didn’t know, is allowing anyone on your wifi network to connect with their iPhone and the Remote App. Once you connect with the Remote app, you can browse the library, and request a song. Multiple people can request a song, and vote it up. Totally awesome!!



I also pump out the output from my MacBook to the MacBook and AppleTV through iTunes so I get total surround sound.

So the Apple Remote app, iPhone, iTunes DJ = ultimate geek iPhone party! Who’s game?


Categories
Geeky/Programming

Bookmark Bar – Uber Micro Sharing

I use pretty much every browser. I switch between them depending on mood, system I am on, phase of the moon, etc. But there are some essential “bookmarklets” that I always want to use/set up.


There are a few things I wish I could tweak though. Like with Yammer, the ability to choose a group before it hits the page. Also with the Yammer bookmarklet there is about a 50/50 chance the URL/title wont come through so you have to do it manually.

With the Gmail This one, on Safari, it opens in a tab instead of a popup, and loading Gmail is kind of slow (IMHO) when you want to just write a mail from out of no where.

What bookmarklets do you use? Are you a share-a-holic?


Categories
Geeky/Programming

One Year Ago Today…

One Year Ago Today, I bought my MacBook Pro. And guess what? It is still running, on the original config, original boot, no reformatting, no repaving, no major surgery, nothing. And it still runs great. I have a ton of apps installed, but just enough, just what I need.

What is funny though, is that using VMWare Fusion, I have reformatted or redone my Windows VM’s multiple times because of issues. Is that just how things are? I think so.

This is probably the longest time EVER that I have had a machine without reformatting it. I think back when I was eleven years old, like 1991, reformatting our 386 25Mhz Packard Bell every 6 or so months with Windows 3.11

I have to say, the MacBook Pro is an awesome machine. Every time I use it, I wish I could just run a Windows VM for work on it, off a USB drive, just take it back and forth, and that is one less physical machine I would have to worry about.. someday..

What is the longest you have went without reformatting, voluntary or involuntary?


Photo Courtesy of Alistair Israel


Categories
Business Intelligence SQLServerPedia Syndication

SQL Job – Check Cube Valid Data as Last Step

Running a SQL Agent job to do an ETL/Cube Processing, you might also want to check the status of the cube after you process it, just to make sure.

Create a job step that is a T-SQL type, and

image

DECLARE @forecast VARCHAR(10)

    SELECT  @forecast = CAST("[Measures].[Forecast-Part]" AS VARCHAR(10))
        FROM
    OPENROWSET(‘MSOLAP’, ‘Data Source=localhost;Initial Catalog=ComponentForecast;’,
        ‘SELECT { [Measures].[Forecast-Part] }  ON COLUMNS FROM [ComponentForecast]’)

IF @forecast = ‘0’ OR @forecast IS NULL
RAISERROR (‘Cube Data Not Loaded Correctly’, 17, 1)

 

Of course your MDX query in the OPENROWSET will need to be different depending on your cube. If you get more complicated, you can also just call a stored procedure and let your imagination run wild with what you can do.

* update – fixed sql code – changed from BIGINT to VARCHAR(10)

Categories
Geeky/Programming Life

New Bike, iPhone, RunKeeper

Since working at Trek, I have been hounded to get a new bike, even more so than by my friends in Portland when I lived there, and EVERYONE has like 5 bikes there.

So, I finally decided to pick up a new bike, a Trek 7.2 FX, Newport Blue, 22.5 inch. It’s a Hybrid – not a road bike, not a MTB, but somewhere in between.

Some pictures are here, of the bike building process, because when you work at a bike company, you take 25 minutes of out of the day to build a bike.



http://www.flickr.com/photos/scaleovenstove/sets/72157619164047726/

So after getting my bike, I had to get some more gear. The usual, helmet, lights, pump, bag, tools, all that stuff. Most other people will get a “computer” for their bike, a little electronic device to track speed, etc. Guess what? I already had one, it is called an iPhone (what doesn’t the iPhone do.. “there’s an app for that”.. is true.)

I jumped on Amazon and looked for a good armband for the iPhone 3G, with good reviews. This is the one I ended up with

So what other parts are there to this equation? The app of course. RunKeeper Pro. (http://www.runkeeper.com) It lets you set your activity type, you start the music before you start RunKeeper, lock the GPS on, and start your activity. You can “lock” the screen so you dont bump it, and then tap it to get pace/speed info. It will also tell you every 5 minutes and/or every mile what your speed/pace is. Once you are done with your activity, you upload it to their site. It maps it out, elevation, speed, nice google map interface. Aggregates miles over weeks/months, and lets you share with your friends.

Here was a ride I did the other day, http://www.runkeeper.com/ui/activities/1000402


RunKeeper really keeps you motivated. I haven’t used Nike+, but I am guessing it is pretty similar. But Nike+ doesn’t work on the iPhone, just iPod Touch.

I really like my bike, there was a Gary Fisher I had my eye on though, so maybe that will be my next bike. Using my iPhone and RunKeeper, I can keep track of my rides, miles, and share with my friends (which kind of helps you stay motivated too). Fun Stuff – Go By BIke!


Categories
Geeky/Programming Product Reviews

Pen Tablet Blog Post

Today, I picked up a Bamboo Fun Pen tablet by Wacom.

image

As you can see, I wrote this post using nothing but the tablet, pretty sweet!