views:

318

answers:

7

I'm working on a Data Warehouse which, in the end, will require me to create reports based on business hours. Currently, my time dimension is granular to the hour. I'm wondering if I should be modifying my Time dimension to include a bit field for "business hour" or should I be creating some sort of calculated measure for it on the analysis end? Any examples would be super magnificent?

A: 

I'm not sure if this helps, but I'd use UCT to store all the times, and then have a start and end times to specify the business hours. Once that is setup, it would be a simple If (SpecificHour >= BusinessStartingHour) And (SpecificHour <= BusinessEndingHour) Then ... operation.

hmcclungiii
-1, doesn't handle businesses that close after midnight.
Sparr
Thanks for the down vote, and I hate to be a smarta$$ but you should have checked the definition for UTC before taking such action. UTC comparisons actually take into consideration things such as dates, leap years, time zones, etc.
hmcclungiii
In your pseudocode, if BusinessStartingHour is something like "8" (for 8AM) then you have the midnight problem. If BusinessStartingHour is something like "1232402400" (4AM EST today), which your comment seems to imply, then you have to calculate a different timestamp [twice a day] every day.
Sparr
That is what I implied. However, I think the calculation would be a tad more efficient than adding a bit (or an entirely new column) for every single time-stamp stored in the database. However, I could be wrong. I guess I'm just a UTC junkie ;)
hmcclungiii
+1 for a helpful answer, even if not entirely correct @[Sparr]: please note that downvoting is for unhelpful answers, not incomplete ones ;-) @[hmcclungiii]: if you use StartHour and Duration then the midnight problem goes away
Steven A. Lowe
@[Sparr]: but kudos for commenting on why you downvoted, that is a stellar thing to do!
Steven A. Lowe
A: 

You can play and test with your different options if you use Microsoft PerformancePoint 2007. You can modify your dimensions and output your results in charts, pivot-tables, other reporting tools etc.

http://office.microsoft.com/en-us/performancepoint/FX101680481033.aspx

Sheehan Alam
A: 

Could the "business hours" change over time? I guess I'm asking whether each row needs to tie to a business hour flag, or whether just having the reports themselves (or some reference) table decide whether that transaction took place during a business hour or not is enough.

All else equal, I'd probably have the report do it for you, instead of flagging rows, but if business hours are volatile over time, you'd have to flag the rows to make sure your historic data stays correct.

rwmnau
+1  A: 

Is all of your sales data in the same time zone? For example, are you tracking sales for outlets in different time zones, or end users in different time zones? If so, you may want to create that bit field for "business hour" in the sales fact table, because it'll be pretty difficult to calculate that on the fly for users and outlets in different time zones.

Plus, you only want to calculate this once - when the sale is imported into the data warehouse - because this data is not likely to change very often. It's not like you're going to say, "This sale used to be in business hours, but it no longer is."

Brent Ozar
+1  A: 

business hours are business rules, therefore they may change in the future

represent business hours as a base time and a duration, e.g. StartTime 0900, Duration 9.5 hours, that way you can easily change the interval, do what-if scenarios based on different business hours, and business hours can cross date lines without complicating queries

of course, all datetimes should be GMT (UTC), never local time, to avoid daylight savings time complexities

EDIT: I think I misunderstood the question, your data is already granular to the hour... No, I think my answer stands, but with the addition of Effective Start and End dates for the business-hour intervals. That would permit the granularity to change in the future while still preserving history

Steven A. Lowe
A: 

It's a judgement call I think... one that depends on performance testing, system usage, etc. Personally, I'd probably create an indexed field to hold a flag in the interest of dealing with the logic to determine what is and isn't a business hour up-front (i.e. when the data is loaded). If done correctly (and again, depending on the specific usage) I think you might be able to get a performance gain as well.

codemonkey
+5  A: 

Use a bit (or even another column) to specify whether an hour is a business hour at the time it is stored. Otherwise when you change the business hours you will become unable to reproduce historical reports.

Sparr