As a general rule, whenever several different people ask me about the same problem I begin to think that it’s time to blog about it. In this particular case the problem is how to display data by different time zones; I’ve been asked about this a few times recently, possibly because AS2005’s ability to handle multiple languages and currency conversion means that people now feel like they can build ‘international’ cubes and this requirement arises as a result. For example imagine you were collecting usage stats for your web application and were interested in seeing how many visitors you had at different times of the day, but users in your UK and US offices wanted to analyse this data by their local time. In your cube you’d need to have a Time Zone dimension and/or attribute which, when you chose the GMT member, would mean that the selection 3:00 on 1st November 2005 on your Time dimension would show the same values as if you’d chosen the EST Time Zone and selected 22:00 on 31st October 2005. Note that this isn’t the same problem that Ralph Kimball talks about here
, which is doesn’t allow you to analyse data in anything other than the local time zone of the event or the standardised time zone.
The obvious first step towards solving this problem is to hold the data in your fact table at one common time zone, probably GMT. However doing the time zone translation isn’t as simple as finding how many hours + or – each time zone is with regard to GMT, of course. The big complicating factor is Daylight Saving Time, and as Wikipedia shows
it’s a pretty big complicating factor – in my opinion you wouldn’t want to write code to model these rules, you’d be much better off having a table which for every hour of every day in every time zone you were interested in would give the equivalent hour and day in GMT. So if you were interested in 20 time zones and had 5 years of data in your fact table, you would have approximately 5*365*24*20=876000 rows in this table. Populating this table would be a pain though… I wonder if there’s a web service out there which can do this conversion for you, operated by people who keep on top of all the changes surrounding Daylight Saving Time such as the recent ones Wikipedia mentions in Indiana?
How you can then use this table in your AS2005 cube design is the really interesting question. My first thought was that even though this isn’t a many-to-many relationship (unless you wanted the duplicated hours that occur when DST moves backwards to be modelled as one member rather than two, which doesn’t seem sensible) you could model it as such – the table descibed in the previous paragraph would become your intermediate measure group, which joins to the fact table via a GMT Time dimension; this time dimension could then be reused (as a role-playing dimension) as your Time in Time Zone dimension, joined to just the intermediate measure group along with a separate Time Zone dimension. You could then hide your GMT Time dimension and your users would just have to select which ever time zone they wanted to analyse by on the Time Zone dimension and the Time in Time Zone dimension would behave exactly as described in my first paragraph.
However there are some drawbacks to this approach. First and foremost is that you couldn’t make use of any aggregations above the hour attribute, because the many-to-many relationship is resolved at this level. This would mean that if you wanted to run queries at the Month or Year level they might not perform as fast as you’d like. Also, the larger the table you’ve built your intermediate measure group from, the slower it will be to resolve the many-to-many relationship, although partitioning this measure group by Time Zone and possibly Year to will mitigate this effect.
The alternative is to model all this as a single regular dimension. You’d have a GMT Hour attribute, an Hour in Time Zone attribute (with a one-to-many relationship between the two) and a Time Zone attribute; the key thing to note here is that every hour in a time zone becomes a single member, so the overall dimension size is much larger than in the many-to-many approach. Since AS2005 can (so I’m told) handle dimensions of many million members even in 32-bit the size issue wouldn’t be the showstopper it would have been in AS2000, although it would presumably have some impact on overall performance. The fact that you could now use aggregations above the Hour level would, on the other hand, be a big factor in improving performance which I would guess would more than make up for the negative impact of dimension size. Judicious hiding of attributes and the use of user hierarchies (for example Time Zone->Year->Month->Day->Hour) would mean that the complexity of the dimension could be hidden from the user; the only real drawback I can think of is that because every Hour, Month, Year etc would be a separate member on the dimension, it would be difficult for users to create reports in an ad-hoc tool which selected a couple of months on a visible axis and then allowed them to slice by time zone – something that wouldn’t be an issue with the many-to-many approach.
One other approach I thought about was using a stored procedure called from an MDX Script assignment to perform the time zone translation – but as I said earlier, trying to handle all the wrinkles of DST changes in code would be a real nightmare, and calling a stored procedure multiple times to get values for each Hour probably wouldn’t perform well either.
I’d be interested to hear other people’s thoughts on how to solve this problem; even better, it would be good to hear from anyone who’s had to actually implement a solution. So post some comments! It would be useful to know whether the regular dimension approach does in fact perform better than the many-to-many approach, for instance…
UPDATE (March 2015) – almost ten years after writing this post, I’ve been asked to revise it. With rather more experience of SSAS than I had back then, I can say that my proposed solution for a single dimension is just wrong and wouldn’t work, and using a stored proc wouldn’t be feasible either. The only workable solution would be the many-to-many approach.