Forum Discussion

EVEAdmin's avatar
EVEAdmin
Icon for Post Patron rankPost Patron
7 years ago
Solved

Date table linked to 2 tables

Hi all,   in my query, I have the following main tables: customers table invoices table products sold table I then created a Datetable, with a record for each day, from the date of the first ...
  • MFelix's avatar
    MFelix
    7 years ago

    Hi EVEAdmin ,

     

    Let's assume you have a sales table with 3 simple columns - Sales Quantity, Sales Date, Sales Order Date.

     

    If you want to create a visual that compares the Sales quantity by sales date and Sales order, depending on the column you use on the chart will give you the calculation based on the month of order or of sales, bu having this information in a single table you are not abble to calculate the two measures so by order date or by sales date.

     

     

     

    In this case you can use a calendar table to make the link however you can only have one active relation between two table at once. Then you will get a active relation and an inactive:

     

    In this case since the active relationship is the Sales Date - Date all calculations withouth any additional syntax will be made with that date in use.

     

    If you want to calculate the Sales Quantity be Sales Date and by Order date in the same visual you need to create two measures:

    Sales by Date = SUM(Sales[Quantity])
    
    Sales by Order Date = CALCULATE(Sales[Sales by Date]; USERELATIONSHIP(Sales[Order Date];'Calendar'[Date]))

    As you can see the second measure is using the first measure but with the USERELATIONSHIP we are "activanting" the relationship between both table but this time based on Order date and not sales, so if you place both measures on a visual you will get:

     

    If you compare the image above you will see it's the matching between the two previous bar charts.

     

    See attach a PBIX file with this example and with two table (one with the relationship another without) so you can have the comparision.

     

    If you google it on DAX USERELATIONSHIP  or DAX inactive relationship you will find further examples and uses for this.

     

    Check also this post:

     

    https://radacad.com/userelationship-or-role-playing-dimension-dealing-with-inactive-relationships-in-power-bi

     

    Regards,

    MFelix