Forum Discussion

TonyBI's avatar
TonyBI
Helper I
6 years ago
Solved

Comparing two fact tables

Hello my friend, I´d really appreciate some help regarding a data modeling issue. I´ll try to explain myself:

 

I have two fact tables that contain many items that I need to be able to compare. Table A contains items and values for every day, and Table B contains Reference Items and values for every day. I need to be able to select many items from table A and compare them with a selected Reference Item from table B. This need to happen in a line chart (with the legend of every item selected and, if possible, the referenceItem too). 

 

Thx in advance!

  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi TonyBI ,

     

    Here's the thing, If we put Item column in Legend field then the Values field can contain only one column. So generally, we need to union these two table as one.

    My advice is to create a calculated table with below formula then create a measure and add it to visual filter to judge if the item is selected.

    Table = UNION('Item table','Refernce table')
    
    Measure = IF(SELECTEDVALUE('union'[Item]) in VALUES('Item table'[Item])||SELECTEDVALUE('union'[Item]) in VALUES('Refernce table'[Item]),1,0)

    Here's the result and the slicers are from two different fact tables.

    Pbix as attached.

     

    Best Regards,

    Jay

     

    Community Support Team _ Jay Wang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

7 Replies

  • TonyBI , Need more information.  You can create common dimensions.  Like item

     

    Item = distinct(union(all(Table1[Item]),all(Table2[Item]))).

     

    Join both tables and use them.

    Also, create a common date dimension

     

    For Rank Refer these links
    https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
    https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
    https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale

    • TonyBI's avatar
      TonyBI
      Helper I

      Amitchandak, thx for your reply! unfortunately this is not what Im looking for, because the problem is that the tables contains so many items that mergin them is ok, but then select a small number is a pain. I can build a dimension table but item and reference tables have diferent grouping columns. Here is an example:

       

      Item table:

       

      ItemDayValue
      A112
      A231
      A323
      A412
      A531
      A642
      A710
      A840
      A953
      A1050
      A1136
      B140
      B210
      B334
      B430
      B523
      B64
      B734
      B854
      B989
      B1056
      C174
      C242
      C345
      C469
      C547
      C655
      C745
      C840

       

      Refernce table

      ItemDayValue
      Refrence 117
      Refrence 1226
      Refrence 1318
      Refrence 1470
      Refrence 1534
      Refrence 1665
      Refrence 1787
      Refrence 1812
      Refrence 1933
      Refrence 11022
      Refrence 11131
      Refrence 2145
      Refrence 2267
      Refrence 2354
      Refrence 2425
      Refrence 2518
      Refrence 26-1
      Refrence 2729
      Refrence 2849
      Refrence 2984
      Refrence 21051
      Refrence 21169
      Refrence 21237
      Refrence 21340
      Refrence 21464
      Refrence 21542
      Refrence 21650
      Refrence 21740
      Refrence 21835

       

      Expected result:

      Result

       

      I can do this by mergin item and reference fact tables, but the problem is that I want to be able to select an item from its own dimension table, and a reference from its own reference dimension table (this is a must because of the amount of items and references, and because of the many different grouping that this two dimensions tables have).

       

      Little example for dimension tables:

       

      Item dimension:

      ItemColourShapeCountry
      ABlueSquareArgentina
      BRedTriangleBrasil

       

      Reference dimension:

      ReferenceSizeWeightapproved
      Refrence 1BigLightYes
      Refrence 2SmallHeavyYes

       

      Thx!!

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi TonyBI ,

         

        Here's the thing, If we put Item column in Legend field then the Values field can contain only one column. So generally, we need to union these two table as one.

        My advice is to create a calculated table with below formula then create a measure and add it to visual filter to judge if the item is selected.

        Table = UNION('Item table','Refernce table')
        
        Measure = IF(SELECTEDVALUE('union'[Item]) in VALUES('Item table'[Item])||SELECTEDVALUE('union'[Item]) in VALUES('Refernce table'[Item]),1,0)

        Here's the result and the slicers are from two different fact tables.

        Pbix as attached.

         

        Best Regards,

        Jay

         

        Community Support Team _ Jay Wang

        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • TonyBI   Without seeing a bit of the data and expected results, My best guess about your requiement:

     

    1. Assuming items andd refence items all have distinct names. If not, you will need to apply a prefix to the ref items. 

    2. Merge the two tables. 

    3. Create a line chart where X axis is date from the merged table. Add the value to the value.

    4. Add the merged item number to the legend of the chart.

    4.  Add a slicer with the item name - user can select multiple items and ref items - and since the ref items are differentiated by name, you know which ones they are.

     

     

  • Hello folks, sorry to bother you again, but I´m really strugling with this problem. Original solution was really fine until I have to calculate cumulatives, they are really really slow. It seems to be checking for every item if the condition is ok (the metric in the solution), and then calculating the cumulative. The main issue is that I need to select items and references (the have their own dimension and fact tables), and show them in the same line chart with legend (the reason here is because I need to compare any or many items with any or many references).

     

    Do you have any other work around? Thx very much!