Question

I've got what I believe would be a fairly common scenario in OLAP but a really great way of addressing it isnt jumping out at me:

ive got say a sales transaction with multiple items, with different products for each one..

enter image description here

What I want to do is assign the product group combinations into a categories i.e. 'dog only', 'cat only', 'cat and dog'

So you'd end up with something like..

enter image description here

If possible I'm hoping to achieve this in Transact-SQL or SSIS, I found calculated members/measures to be slow, put I'm open to that solution if that is the best way to do it

Any help much appreciated

Was it helpful?

Solution

If you want to follow best practices for dimensional modeling (Kimball methodology), you should only have one dimension table for products which also contains all product groupings. In other words, you denormalize all product attributes in one dimension. This Product dimension would have a surrogate key, ProductKey (use an Identity column in SQL Server). This key which is the PK, would be the FK in your fact table which has all the transations. So based on your simple model you would have one fact table for your sales info which has all your measures (amount, qty) and one FK to your Product dimension (ProductKey). Your product dimension would have all product attributes including categories.

In SSAS simply bring the two tables in your DSV and create one dimension (product) and everyting is taken care of for you.

OTHER TIPS

Well, if you want to do it in T-SQL and you have only one table (like your second example) then something like this will do the trick:

update [transactions_table] set [product_group] = 'dog only'
where [product] in ('labrador', 'st bernard')

update [transactions_table] set [product_group] = 'cat and dog'
where [product] in ('chihuahua', 'tabby')

update [transactions_table] set [product_group] = 'cat only'
where [product] in ('persian')

But I'd suggest to have the information split into different tables:

  1. transactions, having a product ID only, not the name
  2. products, having id, name and category ID
  3. categories, having id and name

That saves space and quicker on large tables.

ideally you should have a table for product group and add this info on your product dimension.

If you already have and your problem to populate this info, you should use a lookup transformation on SSIS to get the product group

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top