PowerPivot Football Project: The first DAX formulas, and Relationships

November 2, 2009

Continuing the series on The Great Football Project…

When we last left off, recall that I had used Excel-linked tables to clean all of the “no name” players out of the DimPlayers table, creating a CleanPlayers table to take its place.

Clean Players Table

I pretty quickly realize that I still have two problems:

  1. Hey, not all of my remaining players have BirthName’s! (First Names)
  2. I don’t have a FullName column, which is gonna be awkward when I build reports

Turns out that I can solve both problems with a single calculated column.  Time for some…

DAX Formula Language

DAX is the formula language of PowerPivot.  DAX really could have been named “Excel Formulas++” but we went with the catchier name.  Because really, DAX is just Excel’s formula language with a number of nifty improvements.

I use Ctrl-RightArrow to jump over to the rightmost edge of the table, since PowerPivot supports commonly-used Excel keyboard shortcuts, to the Add Column:

Adding a Column

And then I start to type the following formula:

     =IF([

and see:

PowerPivot Formula Bar

Let’s stop there briefly, because there are a few things worth noting already:

  1. I’m starting my formula with the typical “=” Excel syntax
  2. It uses the IF function, and you can see from the function signature under the formula bar that it’s the same IF function from Excel
  3. All column names in PowerPivot are wrapped in square brackets
  4. Once I enter the open square bracket, I get AutoComplete against all columns in the current table! 

    OK, let’s just finish the formula.  I notice from the dropdown that there is a [NickName] column, and I remember that in this db, most of the time you want to use [NickName] over [BirthName].  So I’ll fall back to using [BirthName] only when there is no [NickName]:

         =IF([NickName]="",[BirthName]&" "&[LastName],[NickName]&" "&[LastName])

    (I used the & operator instead of =CONCATENATE for readability reasons.)

    I rename the resulting column to be FullName and I’m done.  I’ve added an expression-based column to a state of the art, in-memory, column-oriented store (the PowerPivot db), but I don’t really think about it because there was no SQL syntax, no MDX, no VB expressions.  I just added a calc column using Excel syntax.

    FullName Column 

    Relating this to the FactEvent table

    The FactEvent table, that contains the plays themselves, does not contain player names – it contains player ID’s.  This is good db design, but it’s typically a pain for Excel users, since Excel’s features pretty much only work on single tables.

    Excel users denormalize multiple tables into one by using functions like =VLOOKUP() that get the job done, but are tedious to write, are often slow to execute on large datasets, and result in large spreadsheets.  Plus they have to write one such formula for every column they want to grab from another table.

    PowerPivot really shines here, and I suspect Excel pros will adopt it for some of their work based simply on this one capability:  PowerPivot is a version of Excel that supports relationships between tables.

    Conceptually Similar to VLOOKUP

    If I want to think about relationships in a similar way as VLOOKUP’s, I can.  I go to the “big” table – the one with the most rows, the one I want to augment with data from other tables.  In this case, FactEvent.  On the Table ribbon tab there’s a Create Relationship button:

    PowerPivot Add Relationship

    This brings up the following dialog:

    PowerPivot Relationship Dialog

    I’ve filled in the right values in each dropdown, and done so thinking as if I was writing a VLOOKUP (well, ok, a VLOOKUP where I can match on any column, not just the first column of the lookup table!)

    …and if I happened to get the two tables reversed in my head, no worries, PowerPivot figures that out for me.
        And for my next trick…
        Pretty cool and all, but the real fun starts after I have the relationship is in place.  Fireworks in tomorrow’s post.
        Next Football Post

      SharePoint Samurai’s Surrational SharePoint Fairy

      November 2, 2009

      Truth is indeed stranger than fiction.  I am not making this up – 1) There IS a SharePoint Samurai, and he is quite famous in the SharePoint community.  and 2) He DID do some artistic SharePoint Fairy interpretations in PhotoShop:

      SharePoint Fairy by Samurai v1   SharePoint Fairy by Samurai v2

      (CORRECTION:  These imges were taken/rendered by Marcy Kellar, not the Samurai.  Apologies to Marcy.  See more of her work from the SharePoint conference here:  http://marcykellarstudio.com/events/spc09 )

      The SharePoint Samurai’s name is Michael Gannotti, and he does actually wear his Samurai outfit to conventions.  I had not heard of him until recently, but he is quite the presence in the SharePoint scene:

      The SharePoint Samurai, Michael Gannotti

      (Click image to visit his impressive site, complete with SharePoint Fairy interview!)

      BI and Excel Pros – do we have anything like the Samurai and the Fairy?  I think not.  The gauntlet has been thrown down by the SharePoint community. 

      Who among us will take up this challenge?


      Haunted by myself, circa 1996

      November 2, 2009

      In order to more efficiently work on the Great Football Project, I installed Office 2010 Beta 2 at home and am now running the new Outlook.

      …and the new Outlook constantly bombards with my original cardkey picture from when I joined MS in 1996.

      I was a baby.  And boy, did I have a lot to learn…  I had no idea at all, how much I was going to be changed by the coming years.  I can see all of that in the picture.  It’s disconcerting :)

      Updated the Who is PowerPivotPro page with “then and now” pics if you want to see what I mean.


      Thank you Mariano!

      November 2, 2009

      PowerPivot CTP3 and Office Beta 2 have been troublesome beasts to download remotely off the corpnet.  Mariano to the rescue!  I got these on Saturday:

      PowerPivot DVDs

      Thanks man.  I really appreciate it :)