 What's going on everybody? Welcome back to the Power BI Tutorial Series. Today, we're going to be taking a look at building relationships. Now, when you import multiple tables from either the same data source or multiple data sources, you want to tie them together so that when you're creating your visualizations, everything is connected. So in this tutorial, we'll be walking through how to create those relationships to make sure that all of your tables are connected properly. And without further ado, let's jump on my screen and you start with the tutorial. All right. So before we jump over to Power BI and start creating our relationships and our model, I want to take a look at the data in Excel. We realized we were buying so many products for the apocalypse that we decided to start our own store and we have several customers and some client information down here. And so I wanted to take a look at some of the columns and these tables that we're going to be looking at. First thing we have is the apocalypse store. These are the things that we are selling. I know it's a very limited inventory, but these are the really high sellers. These are the ones that I wanted to sell. So we have this product ID, our product name, price and production cost. Then we have this apocalypse sales. This is how many sales we've actually made to our customers. So we have this customer ID, our customer name, product ID, order ID, unit sold and the data was purchased. And then we have our customer information right here. Here are all of our clients. So we have this customer ID, customer, address, city, state and zip code. So now that we've taken a look at our data, let's go and load it into Power BI. So we're going to say import data from Excel. We're going to choose this model right here. I'm going to click open. And we are going to want all three of these. So I'm going to click on all of them. And we're just going to load it. We're not going to transform the data at all. So now the data has been loaded. Let's go right over here on the left hand side to our model tab. And let's scoot this over just a little bit and move back. And we're going to move these tables up to where it's a little bit easier to see. So right off the bat, you can already see that there are these lines between these tables. So there are already relationships that Power BI has automatically detected and created. From my experience, Power BI actually does a really good job at creating these relationships automatically. But we're going to go in and take a look at these and kind of see what everything means. And then we're going to go back and create these relationships from scratch just to make sure that we know how to do every single part. So to get us started, let's double click on this line connecting the customer information table to the apocalypse sales table. And it's going to bring up this edit relationship page right here. So this line right here connecting these two tables actually gives us quite a bit of information without actually having to click into this edit relationship page. What this is showing is that we have a one to many relationship. And there's only one or a single cross filter direction. And you can find both of those things right down here. And I'm going to go walk through what those mean in just a little bit. On this page, you can also see the columns that Power BI decided to choose in order to tie these two tables together. Now for our example, they decided to use the customer and customer right here from the customer information table, as well as the apocalypse sales. But I don't really want to use those specifically because on this apocalypse sales table, I might remove this customer information and just keep the customer ID and may have chosen these customer columns because they have the exact same name and really the same information. But I want to use this customer ID anyways. So what I'm going to do is I'm going to click on that column and click on this column. And then I'm going to click OK. And if we go back into it by double clicking again, we're going to see that and now save that. And if we did what we just did before, which is kind of hover over it, it's going to show us what those two tables are joined on. So opening this backup, let's go down here to this cardinality and cross filter direction. Cardinality has several different options that you can choose from. You have one to many, one to one, one to many, and many to many. Now for this example, we're looking at apocalypse sales and we're going apocalypse sales down to customer information. Now there are a lot of rows in the apocalypse sales, but there's very few in this customer information. And there's only one customer per row. Whereas in the apocalypse sales up here, the customer can have several rows for several different orders. So that's why the cardinality is many to one. Now if we flip this and we say we want the customer information here and we want the apocalypse sales down here, we tie that together. Now it's going to flip and it's going to say one to many. Now let's look at the cross filter direction. And there's only two options here. It's either single or both. And if we choose both and we click OK, this now goes from a single arrow pointing in one direction to two arrows pointing in both directions. But what does this really mean? So in order to demonstrate this, I'm going to put this back to a single direction. And what we're going to try to do is connect the data over here or the columns over here to the columns in this apocalypse store. So let's go over here to build a visualization. And what we're going to do is we're going to take this customer information and let's just say we want to look at state. So I'm going to click on state right here. And I'm just going to make this into a table. And the customer information table is only tied right now to this sales table. So we're actually going to go over to the apocalypse store. And we want to see how many product IDs are being bought in these different states. So really quickly, we're going to come up here and create a new measure. And all we're going to say is this measure is the count of apocalypse store product ID. And we're going to create that. And now we're going to select it. So it's added to that table. So what this is showing is that there are 10 product IDs, which there are 10 products for each of these states, but that's not actually technically correct because not every state purchased these 10 different items. If we go back to our model and we change both of these to a both direction, then we're going to go back and see what changed in our numbers. So now let's go back to our visualization. And now we can see that Minnesota actually only ordered seven different product IDs, Missouri eight, New York nine and Texas 10. This is actually much more accurate than before. When you use the both option, it takes these tables and treats them as if they are a single table, but the single option is not going to do that. And so for our example, if we're trying to connect this table to this table, and one of the last things that I want to show you is this option right down here, which says make this relationship active. Now, if we don't click lists, and there are other options in here that connect these things like the customer to the customer, then that may be the active relationship. But if I select this is the active relationship, that means this is going to become the default relationship between these two tables. So now let's come out of here, we're going to click cancel. We're going to zoom in just a little bit and bring these tables a little bit closer. So we can zoom in just a little bit more. Now we are going to go ahead and delete these. So we're going to say delete yes, and delete yes. So just for demonstration purposes, we're going to build these relationships from scratch. So we're going to come over to the customer information table, and we're going to drag it all the way over here and put it on top of this cust ID or the customer ID and apocalypse sales. And it's going to automatically create that relationship. And we can open this up. And as you can see, it created the relationship between this customer ID and the apocalypse sales and the customer ID and the customer information. It also defaulted the cardinality from many to one and the cross filter direction to single. So we're going to go ahead and change that to both and click okay. And then we're going to come over here to the product ID and apocalypse store and drag this over the product ID and the apocalypse sales. And again, if we open it up, it created that relationship for us. It created the cardinality automatically. And we're going to change this cross filter direction to both and click okay. And so on a really small scale, that is how it works. Of course, it becomes a little bit more complex, the more tables that you add and the more relationships that are created. But this is how you're going to actually create the relationships in the model tab within power BI. I hope that this tutorial has helped you understand this concept a little bit better. Thank you guys so much for watching. I really appreciate it. If you liked this video, be sure to like and subscribe below. I'll see you in the next video.