Skip to main content
hic
Former Employee
Former Employee

 

A common situation when modeling the data for a Qlik application is that you have several fact tables and the fact tables have mixed granularity. An example is budget vs. actual numbers, where the budget typically is made on a higher level than the actual numbers, e.g. the budget has regions instead of specific customers and months or quarters instead of specific dates.

It could also be that you want to have different granularity in a mixture, e.g. you want full details for the numbers for the current year, but – due to the amounts of data – you want to compare these to aggregated numbers from previous years.

In a Qlik data model, it is possible and not very difficult to use a fact table with mixed granularity. Say for instance that you have a detailed fact table with the numbers for current year:

Original fact tables.png

In addition, you have an aggregated fact table for previous years: Instead of CustomerID, ProductID and OrderDate, you have Country, CategoryID and OrderMonth as foreign keys.

The solution is to concatenate these two tables into one common fact table and use generic keys for the three dimensions.

Consolidated fact table.png

The generic keys contain information about both the higher and lower levels of the dimensional hierarchy and can be used for either the higher level only or for both levels. This way, the detailed records of the fact table link to customer, product, and date, while the records with aggregated numbers link to country, but not to customer; to product category but not to individual products; and to order month but not to individual dates.

It can sometimes be tricky to create the generic keys because the detailed fact table lacks direct information about the higher levels in the dimensional hierarchies, e.g. country and product category. But this can be solved using the function Applymap. For the detailed part of the fact table, the generic keys can be defined as:

     Applymap('MapCustomerToCountry',CustomerID) & '|' & CustomerID as %CustomerID,
     Applymap('MapProductToCategory',ProductID) & '|' & ProductID as %ProductID,
     'Date:' & Num(OrderDate)) as %OrderDate

And in the aggregated part of the fact table, the corresponding definitions could be:

     Country & '|' & Null() as %CustomerID,
     CategoryID & '|' & Null() as %ProductID,
     'Month:' & Num(MonthStart(OrderMonth)) as %OrderDate

The generic keys must be mapped to the real keys using a dimensional link table, but once this is done the application will work like a normal QlikView app.

Dimensional link table.png

This method can be used in a number of cases where you want to define keys that link to several values simultaneously, the most common one being comparison of actual numbers with budget.

Read more about generic keys in the Technical brief on Generic Keys.

HIC

33 Comments
Not applicable

With this method, how do you accommodate slowly changing dimensions (SCDs)?  I cannot see how ApplyMap() could be used with that in mind.  Maybe I am missing something.

0 Likes
10,233 Views
hic
Former Employee
Former Employee

I must admit that I have never done that. But I don't think it is impossible. You just need to create the keys using IntervalMatch instead. (and maybe nested ApplyMaps(), so it might be complicated scripting...)

HIC

0 Likes
10,233 Views
Not applicable

I have a post at:

http://community.qlik.com/thread/105050

which proposes never to use concatenate.  It is based on true dimensional modeling.  However, maybe my logic is flawed.  I need to test out with your scenario to see if the numbers add up correctly at the different levels.  They should  - famous last words

10,110 Views
hic
Former Employee
Former Employee

In my experience, you should concatenate. To keep the original tables as they are, will create circular references. See more in my reply to your post: Re: I see no need to ever use concatenate, or to use link tables..

HIC

10,110 Views
christian77
Partner - Specialist
Partner - Specialist

Real data and Budget are same nature events. I always concatenate them.

If budget comes by the month, I can place a monthstart(Date) to see -month to date- comparisons.

Sometimes I divide monthly budget by the days on each month. Then I get a Budget by the date. Doing that you can convert months to weeks, or weeks to months.

I like to cancat all fact tables that I can. That is simplifying.

0 Likes
10,110 Views
Not applicable

For the budget fact,  do you code to the first day of the month? 

From my Android phone on T-Mobile. The first nationwide 4G network.

0 Likes
10,110 Views
Not applicable

Thx I am a bit confused about mixed granularity and generic keys vs hierarchies?

0 Likes
10,110 Views
hic
Former Employee
Former Employee

The two concepts are similar, yes.

One difference is that with Generic keys you can define keys with a symbolic meaning, like "all values" or "no values". This is not possible with Hierachies - or rather, it is not as easy.

I use Hierarchy Load if there already is an Adjacent nodes table defined. Otherwise I (usually) use Generic keys.

HIC

10,110 Views
Not applicable

Hi Henric,

Replying to a very old post but, need to clear some doubts. Aren't we required to have mapping tables for mapping aggregated dimensions to detailed dimensions?

Thanks,

Madhura

0 Likes
10,030 Views
hic
Former Employee
Former Employee

No, I don't see why you would need that.

HIC

0 Likes
10,030 Views