Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

How to create dimension table for item without primary key

Hi everyone,

 

I'm trying to create a dimension table for MailingCity that will be linked to my fact table. The goal for my fact table is to have ContactID and all other dimensions indexed so they link to their respective dimension tables (i.e. MailingCityID in fact table will link with MailingCityID in the MailingCity dimension table, etc). 

 

MailingCity (and other dimensions associated with Contact) does not already have an ID, hence for each dimension, I'm creating a separate dimension table with that dimension being indexed. Only thing is I would have to merge the index tables back to the fact table using the qualitative dimension as the common denominator (i.e. MailingCity index table with Contact fact table using the MailingCity value). And repeat the merges for all other dimensions...which have been very costing on performance for me (Mashup container Out of Memory issues - cannot even open the old file now).

 

Hence, I'm trying to avoid merging dimension indexes back to the fact table to optimize model performance. So now I'm trying to create an index within dimension tables that contain both the ContactID and the MailingCity value itself.

 

In this screenshot below, many contacts can have a MailingCity (MC) value of London, Toronto, etc. So for each of these repeating MC values, I want to do a repeating index value for it as well. i.e. 1 for London, 2 for Toronto, etc.

 

 

Initially I followed RADACAD's tutorial but the result wasn't what I'm looking for: Create Row Number for Each Group in Power BI using Power Query - RADACAD

Result should be 1 for London, 2 for Toronto, etc. 

 

Ideally it will say 0 for null or invalid MC values (i.e. like "--", etc), and start in chronological order with MC values beginning with A as 1, etc.

 

Also, please feel free to give me feedback on my approach to creating the dimension tables & fact table this way.

 

Thank you!

 

4 Replies

  • edhans's avatar
    edhans
    Community Champion

    Don't use IDs or indexes. your mailing city table should be on the MailingCity text value. That will filter the MailingCity field in your fact table.

    In the background, the Vertipaq engine will substitute an index for you and create a data dictionary. All behind the scenes, all automatically, and smoking fast.

    What you are talking about makes sense in a SQL database, but not a tabular model in Analysis Services. I see this all of the time and the first thing I do is get rid of all of that. Unnecessary, and make the model much larger.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi edhans,

       

      Thank you for your quick reply. I really appreciate it!

       

      If I'm trying to create a fact table with less columns (as per the star schema), I don't think it's good practice to leave all the contact details - including MailingCity in the fact table?

       

      I had left all contact details in one table in the beginning and I still ended up with a very slow dashboard.

       

      So do you suggest in my MailingCity dimension table I would just need the ContactID and MailingCity text value, same goes for the other dimensions with text values?

       

      • edhans's avatar
        edhans
        Community Champion

        Based in your image I thought Mailing City was the dimension. If contact is the dimension, then you just need your Contact ID (contact number, name, whatever) that is your unique key in the Contact table also be the foreign key in the FACT table. Don't create arbitrary IDs. I cannot figure out why you have an ID next to the mailing city. Maybe post more info instead of tiny snippets that make it hard to see the overall goal.

        But you are right, if contact is the DIM table, then nothing from contacts should be in the fact table except the contact key itself, which should be the key from your system, not a new key you create in Power BI - not an index, integer, anything. Just what comes from your system.