Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
TonyBI
Helper I
Helper I

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!

1 ACCEPTED SOLUTION

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.

3.PNG

4.PNG

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.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

7 REPLIES 7
TonyBI
Helper I
Helper I

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!

 

 

sanimesa
Post Prodigy
Post Prodigy

@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.

 

 

amitchandak
Super User
Super User

@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

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:

ResultResult

 

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!!

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.

3.PNG

4.PNG

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.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

Sorry to bother you again my friend, but I have another problem. The chart is working great, but when I try to replicate it with average values, it gives me the exact same chart... The idea is to have both charts, first one with all items an references selected as legend, and then another chart with the average of item selected and the average of refernces selected. Any idea of what could be wrong?

 

Thx in advance!

This is exactly what I was looking for, thx!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.