Forum Discussion

Hanspw's avatar
Hanspw
Helper I
5 years ago
Solved

Time dependent relationship

Hi.   So i have a fact table, which includes a project/product. And then i have a dim table with project/product groups. So this works fine. However i want the flexibility to change the releationss...
  • Hanspw's avatar
    Hanspw
    5 years ago

    So i finally figured this out. I add my solution in case anyone wants to know how i solved this.

     

    Thank you Anonymous for pointing me in the right direction, this article made me realise my problem was a Type 2 Slowly Changing Dimension table:

    https://docs.microsoft.com/en-us/power-bi/guidance/star-schema#slowly-changing-dimensions

     

    Not easy when im new to Power BI and dont know what all problems are called. Once i figured this out it was much more easy to try and find a solution on google and youtube.

     

    My dimension table is based on an excel spread so it does not have timestamps or version logs. So the solution was indeed to add multiple rows for a project, with two colums for "dato_from" and "date_to". Since project no longer was uniqe ID i made a index column. I then added a column in the fact table (for same index_column_ID), and i had to to a filter lookup to the dim table (based on project_ID, date_from and date_to), to add right index_ID to fact table. 

     

    I tried two versions of this in power query, however when i try to add the column in the fact table with lookup for each row, the data refresh takes longer time than i would like. I finally found a method in dax which avoided that, so it solved my lookup problem and still kept the low refresh time. It is based on this youtube video:

    https://www.youtube.com/watch?v=BGcfaROCcto&t

     

    My dax fomula in the end, for adding the index column in the fact table:

     

    dim_prosjekt_index = 
        CALCULATE(
            VALUES(x_LookupTable_z_ark[dim_prosjekt_index]),
            FILTER(x_LookupTable_z_ark,
                Datagrunnlag[dim_prosjekt_ID]=x_LookupTable_z_ark[dim_prosjekt_ID] && 
                Datagrunnlag[transaction_date]>=x_LookupTable_z_ark[date_from] && 
                Datagrunnlag[transaction_date] <= x_LookupTable_z_ark[date_to]
            )
        )

     

     

    I first tried to make this lookup from the dim_project table, which i want to tie to the fact table with relationship. But it gave me a circular reference. So i had to do the same thing as in the youtube video: i made a copy of the dim_project table (lookuptable), made the lookup to this lookuptable to fint the correct index_ID to add to fact table, and then made the reference to dim_project table.

     

    Problem solved 🙂