Search code examples
sqlssasdata-warehousedimensions

Can a dimension ID record, also be used as a column (attribute)?


Can a dimension ID record, also be used as a column (attribute)? I do not know if this will work, or if it is against best practices if i do. Here is a more detailed explanation of why i am asking this, and what i am looking for: I have a dimension with only 6 records, called a Past Due Dimension. It looks like the following:

    PastDueBandDimID     PastDueMin     PastDueMax     PastDueDesc
    _____________________________________________________________________
    1                    0              0              Current
    _____________________________________________________________________
    2                    1              29             1-29 Days Past Due

And on it goes with 30-59 days / 60 - 89 days / 90-180 days. This pattern all in all works fine, but i would like to create a User Hierarchy with this data, so i can group it different ways. So what i thought of doing, was creating in the DSV, additional fields called 1-29 / 30-59.... and reference the DimID in these fields, so i could create my Hierarchy. I do not feel this is a good way of doing it, but i have no othher ideas. Any suggestions is appreciated! I would like to group (in not all but in some) of my reports 0-59 days, and 60-180 days, and a user hierarchy would enable the users to do this.


Solution

  • When doing bucketing like this, I almost always create physical bucket columns on an aggregated fact rather than a "past due" dimension.

    I can understand the temptation in building this dimension like this since it's very "flexible", but as you are discovering it makes using automated tools (such as ssas) more difficult, as well as forcing you to constantly update your fact tables to reflect the new "past due" dimension value.

    Instead, why not just build an aggregate that sits on top of your fact and is rebuilt daily (or even a view if your DB is strong enough). Using invoices as an example:

    Invoice
    Invoice Due Date
    PastDueLTE29 (1 if <= 29, 0 otherwise)
    PastDue30to59 (1 if >= 30 and <= 59, 0 otherwise)
    PastDue60to89 (1 if >= 60 and <= 89, 0 otherwise)
    PastDue90to180 (1 if >= 90 and <= 179, 0 otherwise)
    PastDueGTE180 (1 if >= 180, 0 otherwise)
    

    If you then want to group on, say all invoices < 60 days past due, you would just filter where either of the first two columns = 1.

    If you really want a hierarchy, couldn't you just add a few columns to your table?

    I really don't like using "Level" in the names of columns... but:

    PastDueBandDimID
    PastDueLevel1Name ("Past Due" or "Current")
    PastDueLevel2Name ("1-60" or "61-180" or "180+")
    PastDueLevel3Name ("1-30", "31-60", "61-90", "90+"
    PastDueLevel3Min
    PastDueLevel3Max