Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

joining across multiple fact tables with a dimension in between

What's a good approach to data warehouse design if requested reports require summarized information about the same dimensions (and at the same granularity) but the underlying data is stored in separate fact tables?

For example, a report showing total salary paid and total expenses reported for each employee for each year, when salary and expenses are recorded in different fact tables. Or a report listing total sales per month and inventory received per month for each SKU sold by a company, when sales comes from one fact table and receiving comes from another.

Solving this problem naively seems pretty easy: simply query and aggregate both fact tables in parallel, then stitch together the aggregated results either in the data warehouse or in the client app.

But I'm also interested in other ways to think about this problem. How have others solved it? I'm wondering both about data-warehouse schema and design, as well as making that design friendly for client tools to build reports like the examples above.

Also, does this "dimension sandwich" use-case have a name in canonical data-warehousing terminology? If yes that will make it easier to research via Google.

We're working with SQL Server, but the questions I have at this point are hopefully platform-neutral.

like image 933
Justin Grant Avatar asked Jan 13 '14 06:01

Justin Grant


2 Answers

I learned today that this technique is called Drilling Across:

Drilling across simply means making separate queries against two or more fact tables where the row headers of each query consist of identical conformed attributes. The answer sets from the two queries are aligned by performing a sort-merge operation on the common dimension attribute row headers. BI tool vendors refer to this functionality by various names, including stitch and multipass query.

Sounds like the naive solution above (query multiple fact tables in parallel and stitch together the results) is also the suggested solution.

More info:

  • Drilling Across - Kimball overview article
  • http://blog.oaktonsoftware.com/2011/12/three-ways-to-drill-across.html - SQL implementation suggestions for drilling across

Many thanks to @MarekGrzenkowicz for pointing me in the right direction to find my own answer! I'm answering it here in case someone else is looking for the same thing.

like image 179
Justin Grant Avatar answered Sep 23 '22 07:09

Justin Grant


The "naive solution" you described is most of the times the preferred one.

A common exception is when you need to filter the detailed rows of one fact using another fact table. For example, "show me the capital-tieup (stock inventory) for the articles we have not sold this year". You cannot simply sum up the capital-tieup in one query. In this case a consolidated fact can be a solution, if you are able to express both measures on a common grain.

like image 33
Ronnis Avatar answered Sep 20 '22 07:09

Ronnis