Level: Beginners
I helped a couple of people this week on the topic of creating multiple relationships between two tables. There is not a lot of information on this topic on the web so I thought I would write about it here.
Power Pivot is not the Same a Relational DB
For those of you that have used SQL Server or MS Access, you will be aware that when using these relational database programs, it is perfectly acceptable to create multiple relationships between tables. Power Pivot is not a relational database but a reporting database. It needs data structured in a certain way to optimise the speedy process of finding the data needed and displaying it in your reports. Microsoft had to make compromises in the design to make this process fast, and one compromise is that there can only be 1 active relationship between 2 tables. In addition, the relationship MUST be one to many – no exceptions (although this is changing in Excel 2016 edit: and has already changed in Power BI Desktop as mentioned by Kevin in the comments). You can read more about 1 to many relationships and data shape in this article from my knowledge base.
Why would you need Multiple Relationships at All?
The most common scenario I have come across is when you have two date columns in your data table (eg Order Date and Ship Date) and you want to join both of these columns to the Calendar table. If there were only 1 date column, then you would typically set up your data like this (shown below). Note the relationship is between the Calendar[Date] and Sales[Order Date]
The immediate temptation is to then create a second relationship between Sales[Ship Date] and Calendar[Date]. When you do this, you will get the following behavior as shown below.
Note there are now 2 relationships, but one of them (the second one added) is a dashed line. If you hover the mouse over this new relationship with the dashed line and then right click, you will see a menu pop up as shown below.
Notice that one of the menu options (#1 above) is “Mark as Active”. This is a clue that the relationship with the dashed line is currently “inactive”. When you hover the mouse over the other relationship with a solid line and right click, the menu (#1 below) now shows the option to “Mark as Inactive” indicating this one is currently active.
This is really the only information you will see in Power Pivot that refers to active and inactive relationships. If you change the inactive relationship and make it active, then the active relationship will automatically switch to inactive.
How to Use Inactive Relationships
For this blog post, I will keep the relationship between Sales[Order Date] and Calendar[Date] as the active relationship and leave the other relationship as inactive. I then set up the following Pivot Table – the Row Labels are coming from the Calendar[Date] column.
The formula [Count of Orders] is simply as follows
Count of Orders := COUNTROWS(Sales)
So now the problem is, how to count the orders that shipped on each day? DAX allows you to override the active relationship and use the inactive relationship in your formulas instead. To do this, you must use the DAX function USERELATIONSHIP inside a CALCULATE function as shown below.
Count of Orders Shipped := CALCULATE( [Count of Orders], USERELATIONSHIP(Calendar[Date], Sales[Ship Date]) )
The relationship MUST exist in the data model and be set as inactive for the above to work. You can’t simply use the function USERELATIONSHIP and specify two columns and expect it to work – you must have the inactive relationship set up first.
The Pivot Table now will look like this, showing for each date, how many orders were taken and how many orders were shipped.
Alternatively You Could Load Two Calendar Tables
Another approach to this problem would be to simply load a second Calendar Table and call it ShipCalendar (or similar). This would mean that you have 2 calendar tables and can use the one you need for the problem at hand. Which approach you use is really down to personal preference and also how you are planning to report on your data. In the Pivot Table above, you can see that it is easy to look at any date and see how many orders came in and how many orders were shipped out. However the orders counted in these two columns are not the same orders (orders coming in on any date will ship either the next day or 2 days later in this test data).
If you want to be able to filter on orders that were taken on a certain date and then see when they shipped, you would need to change the pivot table layout like shown below.
The date (#1 above) comes from the Calendar Table and the dates on Rows (#2) come from the Sales[Shipped Date] column. So this Pivot Table allows you to select an “Order Date” and see there were 9 orders, 4 shipped the next day and 5 shipped the day after. The only problem with this approach is that the Shipped Date is coming from the Sales table. Clearly it is working, but it is not best practice. It is much better (particularly in large data models) to always use a Lookup Table to filter your Pivot Table (the filter on Rows in this case). So better practice is to bring in a second ShipCalendar and remove Sales[Date] on Rows in the pivot table and replace it with ShipCalendar[Date]. (Note: I have now removed the inactive relationship so the DAX formulas above will not work any more).
The result with this new lookup table added will be the same as using the Sales[Date] column in the Pivot Table, but this second approach with a second lookup table will be much more performant and optimised for Power Pivot (which is important when you have a lot of data or 32bit Excel).
You can download my sample workbook here if you like.
A Final Word
In summary, you have a choice to either create multiple relationships between two tables, or alternatively you can bring in a second copy of your lookup table.
If you opt for multiple relationships:
- Only one of the relationships will be active
- The other relationships can be accessed by using the USERELATIONSHIP function inside of CALCULATE
- There is a limitation with this approach because you can only use a column from your lookup table once in your Pivot Tables. In the example above this meant you could not use the Calendar[Date] column twice in the one Pivot Table.
If you opt for multiple lookup tables:
- You will have 2 sets of columns that CAN be used together in the one Pivot Table.
- You will need to be careful that users are not confused, and should consider naming the columns in the lookup tables with unique names like Calendar[Order Date] and ShipCalendar[Ship Date] for clarity.
This is really interesting, You’re a very skilled blogger. I’ve joined your rss feed and look forward to seeking more of your wonderful post. Also, I’ve shared your web site in my social networks!
With havin so much content do you ever run into any problems of plagorism or copyright violation? My blog has a lot of completely unique content I’ve either created myself or outsourced but it appears a lot of it is popping it up all over the web without my permission. Do you know any methods to help stop content from being stolen? I’d really appreciate it.
Wow, awesome blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your web site is magnificent, as well as the content!
As a Newbie, I am permanently exploring online for articles that can be of assistance to me. Thank you
I really like your writing style, fantastic information, appreciate it for putting up :D. “You can complain because roses have thorns, or you can rejoice because thorns have roses.” by Ziggy.
Thanks a lot for sharing this with all of us you really know what you’re talking about! Bookmarked. Kindly also visit my web site =). We could have a link exchange agreement between us!
Rattling superb visual appeal on this internet site, I’d value it 10 10.
My spouse and I stumbled over here different web address and thought I should check things out. I like what I see so now i’m following you. Look forward to looking over your web page yet again.
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across. It extremely helps make reading your blog significantly easier.
I will immediately clutch your rss as I can’t find your e-mail subscription link or newsletter service. Do you have any? Please permit me recognise so that I may just subscribe. Thanks.
I?¦ve been exploring for a little bit for any high-quality articles or weblog posts in this kind of house . Exploring in Yahoo I finally stumbled upon this web site. Reading this information So i?¦m glad to express that I have an incredibly excellent uncanny feeling I found out exactly what I needed. I so much surely will make sure to do not forget this website and provides it a glance regularly.
You are my inhalation, I own few blogs and sometimes run out from to brand.
You are my inhalation, I own few web logs and often run out from to post .
F*ckin’ tremendous things here. I’m very glad to see your article. Thanks a lot and i am looking forward to contact you. Will you kindly drop me a e-mail?
Super-Duper site! I am loving it!! Will come back again. I am taking your feeds also
You have remarked very interesting points! ps decent site.
I’d forever want to be update on new articles on this website , saved to favorites! .
I was reading some of your content on this site and I believe this web site is rattling instructive! Continue putting up.
I visited a lot of website but I believe this one holds something extra in it in it
comprar carta de conduçao preço, comprar carta de condução verdadeira, comprar carta de conduçao, comprar carta de condução lisboa, comprar carta de condução legal, comprar carta de condução, carta de condução comprar, comprar carta de conduçao, comprar carta de condução em Portugal, comprar carta, comprar carta de condução portugal, comprar carta de condução online, comprar a carta de condução, carta de condução, comprar carta de carro, imt carta de condução, comprar carta de condução no porto,Comprar carta de conduçao legalmente, Comprar carta de condução sem pré-pagamento, uma carteira de motorista registrada compre experiências, comprar experiências de carta de condução, Comprar carta de condução sem exame Colônia, Comprar carta de condução porto, Comprar carta de condução sem exame portugal, Comprar carta de condução em portugal, comprar carta de condução lisboa, comprar carta de condução portugal. 98uh
gdzie można kupic prawo jazdy z wpisem do rejestru, kupić prawo jazdy, legalne prawo jazdy do kupienia, kupię prawo jazdy, jak załatwić prawo jazdy, bez egzaminu, jak kupić prawo jazdy, czy można kupić prawo jazdy, legalne prawo jazdy do kupienia 2025, pomogę zdać egzamin na prawo jazdy, prawo jazdy bez egzaminu, gdzie kupić prawo jazdy bez egzaminu, gdzie kupić prawo jazdy na lewo, jak kupić prawo jazdy w niemczech, gdzie kupic prawo jazdy legalnie, kupić prawo jazdy b, pomogę zdać egzamin na prawo jazdy, gdzie można kupić prawo jazdy z wpisem do rejestru forum, prawo jazdy płatne przy odbiorze, prawo jazdy czechy kupno, w jakim kraju można kupić prawo jazdy, pomogę załatwić prawo jazdy w uk, sprzedam prawo jazdy z wpisem bez zaliczek, jak kupić prawo jazdy w uk, ile kosztuje prawo jazdy na lewo?, 98i4
rijbewijs kopen, rijbewijs b kopen, vals rijbewijs kopen, rijbewijs b kopen in belgie, rijbewijs kopen prijs, rijbewijs kopen legaal, rijbewijs kopen 247 ervaringen, rijbewijs kopen online, rijbewijs kopen belgie, nep rijbewijs, motorrijbewijs kopen, kan je een rijbewijs kopen, koop een rijbewijs, motor rijbewijs kopen, rijbewijs kopen betrouwbaar, neppe rijbewijs kopen, auto zonder rijbewijs kopen belgie, rijbewijs koop, rijbewijs kopen nederland, auto zonder rijbewijs kopen, rijbewijs kopen belgië, rijbewijs kopen belgie, rijbewijs kopen in nederland, rijbewijs b belgie, rijbewijs kopen met registratie. 9876hb
you might have an ideal weblog right here! would you wish to make some invite posts on my weblog?
It’s the best time to make a few plans for the long run and it’s time to be happy. I’ve read this post and if I may just I want to recommend you some attention-grabbing issues or suggestions. Maybe you can write next articles referring to this article. I desire to learn even more issues approximately it!
The very core of your writing whilst appearing agreeable originally, did not really settle properly with me personally after some time. Somewhere throughout the paragraphs you were able to make me a believer unfortunately only for a short while. I nevertheless have a problem with your leaps in assumptions and you might do nicely to fill in those gaps. In the event you actually can accomplish that, I would certainly end up being fascinated.
Throughout this great scheme of things you’ll get an A with regard to effort. Where exactly you misplaced us ended up being on your facts. You know, people say, details make or break the argument.. And that couldn’t be more true right here. Having said that, allow me say to you what did work. Your writing is actually rather persuasive which is most likely why I am taking an effort in order to comment. I do not really make it a regular habit of doing that. Second, despite the fact that I can see the leaps in reasoning you come up with, I am not confident of exactly how you seem to unite your ideas that make your final result. For right now I will subscribe to your position however trust in the future you link your facts much better.
I have been exploring for a little for any high-quality articles or blog posts in this sort of space . Exploring in Yahoo I finally stumbled upon this web site. Studying this information So i am glad to show that I’ve a very excellent uncanny feeling I found out just what I needed. I most definitely will make certain to don’t put out of your mind this website and give it a glance regularly.
I truly enjoy looking through on this site, it has got excellent blog posts.
Woh I love your blog posts, saved to my bookmarks! .
Hi my friend! I want to say that this post is amazing, nice written and include almost all significant infos. I would like to see more posts like this.
Я не могу не отметить качество исследования, представленного в этой статье. Она обогатила мои знания и вдохновила меня на дальнейшее изучение темы. Благодарю автора за его ценный вклад!
I went over this site and I think you have a lot of wonderful information, saved to bookmarks (:.
Hello my friend! I want to say that this post is amazing, great written and come with approximately all significant infos. I would like to see extra posts like this .
I dugg some of you post as I thought they were extremely helpful extremely helpful
Spot on with this write-up, I really suppose this web site needs far more consideration. I’ll probably be once more to read much more, thanks for that info.
amei este site. Para saber mais detalhes acesse o site e descubra mais. Todas as informações contidas são conteúdos relevantes e únicos. Tudo que você precisa saber está está lá.
Este site é realmente fascinate. Sempre que acesso eu encontro coisas diferentes Você também pode acessar o nosso site e descobrir detalhes! informaçõesexclusivas. Venha saber mais agora! 🙂
I like what you guys are up also. Such intelligent work and reporting! Carry on the superb works guys I’ve incorporated you guys to my blogroll. I think it’ll improve the value of my site :).
Have you ever considered creating an ebook or guest authoring on other websites? I have a blog based on the same information you discuss and would really like to have you share some stories/information. I know my audience would appreciate your work. If you are even remotely interested, feel free to shoot me an e mail.
I¦ve recently started a blog, the information you provide on this web site has helped me greatly. Thank you for all of your time & work.
I reckon something genuinely special in this website.
A person essentially help to make seriously articles I would state. This is the very first time I frequented your web page and thus far? I surprised with the research you made to make this particular publish extraordinary. Magnificent job!
Perfectly composed subject matter, Really enjoyed studying.
Hi Matt, in your first approach, you could only filter by the same date (for Ship Date and Order Date). And for the second approach, you could filter by both dates independently.
Now, in my case, I need to be able to filter both dates independently. I’m worried about having to duplicate tables in the model. In 2024, is this still the solution to the problem?
Thank you.
What makes you concerned about 2 tables? I can’t think of any issue with this approach, and yes, it’s still the approach if you need to filter on 2 dates.
Saved my day.
Dear Matt, good work there.
my question is: how do I use both activate both active relationship and inactive relationship?
Let’s say I need to display in a table elements both from the two relationship together… Thanks.
It depends what you are trying to do. I can’t really answer without more detail.
It’s a great article.. simple to understand. I am deliberating on relationship design options as I have to show top 5 accounts by Opportunity (1st fact) and by Revenue (2nd fact) and show them for single selection of Date filter – by Year, Quarter, Month. I can’t seem to find much direction from various posts how I can connect date hierarchy to these facts. Should i consolidate to a single fact and use date hierarchy on one table? But, merged set will have issues with scale. Any suggestions on modelling is much appreciated.
I think the best way to get help on this is to post at question at community.powerbi.com, provide some sample data and ask for help there. You can post a link back here if you like, but I only help out on the community when I get spare time (rarely these days)
Correct Matt, with slicer groups it works. Appreciate for your help.
You need slicer groups. https://youtu.be/qPDjCuvKWCw?t=290
Thanks Matt, for the alternate option how we can sync 2 slicers that using different fields( e.g. one uses FY from Calendar and another FY from ShipCalendar) in one page? I thought Sync is replicating a slicer in different pages.
If you want the user to select only 1 date table filter, then create 2 relationships between the one date table and the 2 date columns in your data table. One will be inactive and needs to be activated in the measure. Alternatively you can create 2 date tables and sync them in Power BI using Sync Slicers
It is one Date table but used by 2 dimension similar to Calendar and ShipCalendar in your example.
Why do you have 2 Date Tables?
Hi Matt,
Thanks for sharing this post. I was looking for the best practices for using Role dimensions in Power BI model. Using 2 dimensions sounds to give more flexibility in Power Bi reports but the issue comes when a slicers get used on Date e.g. for selecting FY as 2 slicers must be used (one for each Date dimension) and this makes the users confused.
Do you have any suggestion to use one slicer to filter 2 Date tables?
Cheers,
Excellent explanation and example Matt.
I appreciate your work and find your style easy to understand.
Thank you.
Thank you , very useful information
Hi Matt
I am new to power BI and Dax. I have been following your blogs and the articles.
I can see what you are suggesting here about the multiple dates and date table. As you mentioned that we can achive the active and inactive relationship using DAX USERELATIONSHIP function and thus we dont have to duplicate the date table.
The problem I have is that I have a task to build a data model and deploy it as a content pack on the service and the end user will use the model to create the reports. In the service you cant write DAX or create measures. So I cant use DAX ‘USERELATIONSHIP’ function. Does this mean that I have to create multiple DIm date table to link the dates?
Can you please advice.
Thanks
correct, you can’t add measures in the service (yet). But this doesn’t imply you must use multiple tables, just that you must complete the data modelling work before publishing. So decided which approach is best and deploy that before publishing to the service. If USERELATIONSHIP is better for you, then do that.
I am starting with power Bi and I found this very interesting, maybe my questions is a little dumb but I have to ask, the calendar table is like a predefined table? or it is necessary to create it in order to start working?
Thank you!
It is possible to create one automatically in Power BI, but I personally don’t do it, nor recommend it. I cover calendar tables extensively here. https://exceleratorbi.com.au/power-pivot-calendar-tables/
Is there any word on if the 2016 engine will natively support role playing dimensions?
It’s very frustrating having to load multiple dimension tables. One of my SSAS tabular models currently has 6 identical dimension tables of 50,000 employees! It’s a performance killer.
I am not aware of any changes to this. I am intrigued as to why you need 6 identical dimension tables. This implies that there must be 6 non identical key columns that need to join to the same fact table. Or am I missing something? Can you post a pic of the data model connections?
Thanks! Very good post. Necessary info right in time.
Another, excellent one, you’ve demystified the dotted line for me
Bedridden with flu catching up on all of this highly useful info
The relationships appears to allow users to do M to M, 1 to M in Power BI Desktop. Any comment on this?
Yes, this is the same new functionality that is available in Excel 2016. I am holding out on having an opinion whether this is a good change or not, as I haven’t really used it yet. As long as performance and behaviour can be controlled, I guess I will be happy.