Use of Multiple 'USERELATIONSHIP' in a single measure

pjmorris

Well-known Member
Joined
Aug 2, 2012
Messages
2,172
Office Version
  1. 365
Platform
  1. Windows
I have a complex problem at work. Currently the dimension table runs to over 100,000 lines. I need to include a 3 dimension which would simply render the current solution unworkable (way too slow). Having discussed it with colleagues who use SQL (I don't) they suggested applying multiple filters (derived from the dimension table) to the fact table. Although you can define multiple relationships in Powerpivot only one can be active at a time. I therefore thought to use 'USERELATIONSHIP'. In the help guide to this function it alludes to being able to use this multiple times in a single measure, but provides no examples. It also says that in certain circumstances if they're nested then the inner most takes precedence. This has left me somewhat confused and I'd be grateful for any advice. I've created a test scenario as follows:

1. Fact Table:

Book1
ABC
2Key 1Key AValue
31a1
41b2
52c4
62a8
73b16
83a32
Sheet1



2. Dimension Table:

Book1
GHI
2GroupKey 1Key A
3House1b
4Boats2c
5Stuff3a
Sheet1


3. Required Output:

Book1
LM
2Expected Results
3House2
4Boats4
5Stuff16
Sheet1


4. Clip of the relationships established in Powerpivot. (qryTable1 is Fact Table, qryTable2 is Dimension Table)

1640797121042.png


5. My attempt at a measure, which does not work:

Power Query:
=CALCULATE(SUM((qryTable1[Value]),
    USERELATIONSHIP(qryTable1[Key 1],qryTable2[Key 1]),
    USERELATIONSHIP(qryTable1[Key A],qryTable2[Key A])
    )

Any advice on how to make this work would be gratefully received.

Many thanks.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Wouldn't it be easier to create a composite key column?
 
Upvote 0
Hi Rory,

That's the current solution, but the dimension table is already over a 100,000 rows. I did contemplate that option, but if I add in another dimension which requires at least 40 options I end up with about 4,000,000 and I just can't see Excel working quickly enough to satisfy users. The example above is an extremely simplified version of the problem.

Regards

Peter
 
Upvote 0
Well, as far as I know, you cannot use two USERELATIONSHIP functions to activate multiple relationships between the same tables, so I think you will have to either restructure your model (my general feeling is that when something gets horrendously complicated, it usually means your design could be better) or work with something like composite keys.
 
Upvote 0
Hmmm, sadly, that's what I've suspected. I would agree that a redesign of the structure would probably make sense, but I'm stuck with the current data sources and I don't know enough to conceive a different structure. I have discussed this with someone who has some formal training in data management and we remain with what we've got.

You do give me a suggestion though and that is to try and separate the dimension table into separate parts. I'll let you know how I get on.

Regards
 
Upvote 0
well that turned out to be simpler than I imagined. And I think its a solution I can use in my work problem.

I created two additional tables based on the original Dimension Table. I then linked them as shown below. The relevant measure is here and uses cross table filtering by the inclusion of qryTable2 in the CALCULATE expression, which interestingly is how a many-to-many relationship can be managed.

Power Query:
=CALCULATE(SUM(qryTable1[Value]), qryTable2)

1640869938235.png
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top