in this video we'll look at small multiples or trellis charts a small multiple sometimes called trellis chart lattice chart grid chart or panel chart is a series of similar graphs or charts using the same scale and axis allowing them to be easily compared it uses multiple views to show different partitions of a data set this term was popularized by edward tukti let us take this big chart for example you may have multiple values you want to compare and while it may seem to be a good idea to put all these values in one big chart comparing the values of each individual line can become so confusing and unwieldy this is when we can consider creating small multiples a small multiple is taking that one big chart and creating smaller versions of it so that we can compare them side by side when we create small multiples we sacrifice having bigger graphs we don't see as many details but we are able to compare multiple slices of the same graph in a smaller format side by side you see them all at one glance and even though we don't get the same details we get to compare the general patterns side by side in this video we will look at how to create these small multiples in tableau i'll see you in a bit creating a small multiple in tableau can be straightforward or it can be a little bit complicated if you already have the dimensions you want to use for your partitions this can be straightforward so for example in this chart if we simply wanted to partition this by date we can take that date put that in either row or column and it will create smaller versions of the same chart if we wanted to further slice this by category we can take that category and then put that in the other shelf again this is an example of a very simple small multiple but what if we wanted to create a small multiple based on only a single dimension value for example let's create a brand new sheet and in here let's create a time series graph right click drag order date continuous month click on ok let's take sales onto rows and for this demonstration i'm going to put subcategory on caller so instead of slicing and dicing this by other dimensions maybe we simply wanted to see all subcategories in one panel in one grid we have some challenges for us to create a small multiple we need some discrete dimensions that allow us to create the grid so we are going to have to create calculated fields that allow us to create these grids this is the small multiple we are going to create in this demo this allows us to compare subcategory sales side by side in one view this chart might seem so colorful but i'm going to explain later on why we're using color and how it can help us validate our data your final small multiple or trellis chart does not need to be this colorful i just want to note that there are a lot of strategies to create these small multiples in tableau i'm going to show you one but i'm pretty sure you're going to find other strategies from a lot of fantastic resources out there let's go over the high level steps first on how we can create this small multiple there's two general big steps the first one is we need to be able to create the grid or the matrix the second step is we want to be able to add labels so that we know exactly what we're looking at each of the bigger steps have smaller sub steps though to create the matrix or the grid we have to create a few calculated fields first one is an index the second one is columns and we are going to derive this from the index calculated field third one is rows and fourth one we are going to need a new date and i'm going to demonstrate later on why we need to create a new date and once we create a new date we simply need to use it there's also a few steps we need to create and display the label first we need to calculate the sales for each panel we also need to find out the maximum sales in any one panel next we need to find a midpoint or a halfway mark where we can put these labels and lastly once we have all of these pieces we can display our label let's now jump back to tableau and create the small multiple step by step let's create our first calculated field so on the drop down create calculated field and let's call this index and this simply uses the table calculation function index so what is index if you place your cursor in the function name and if you expand on this calculated field window you're going to see a description of this function it says here it returns the index of the current row in the partition the index function again this is a table calculation function it simply returns a sequential number based on the direction and the scope that you specify for that table calculation let's click on ok first and let's just demonstrate what index is or what it does because i think it's important for us to understand before we move forward let's also just change this index into a discrete field let's create a new sheet let's place subcategory onto columns and let's simply display index in text so we can see in here that the index function simply gives us a sequential number it gives us a number from 1 to n so starts from 1 all the way to the maximum number of distinct values we have for subcategory in our small multiple we may want to simply display let's say five columns so the subcategories with the index six to ten we may decide to put that and stack that on top of the previous values which means that for chairs instead of column number six we want this to be column number one again in copiers we want this to be called number two number three number four number five so how can we do that so our second calculated field where we can calculate the column number can be based on the index we just need to make sure that the calculation gives us these values instead of the original index number let's first create a parameter that will hold the number of columns we want to use in our small multiple let's call this parameter number of columns this is going to be an integer and let's say we start with five the reason we are creating a parameter is because we don't want to hard code this in any of the next calculations we're creating if we hard code this value it's going to make it harder for us to maintain and change this in the future should we change our minds and make this 10 columns for example so let's click on ok and now let's create our second calculated field so on the drop down create calculated field and let's call this one columns we are going to use our index calculated field in here and we are going to use the operator called modulo and the modulo operator is a percent sign and in here we're going to use the number of columns let me click on apply first and display this and let's talk about this a little bit more let's also just convert columns into a discrete field so right click convert to discrete so let's take a look at what's happening the modulo operator gets the remainder after a division so in this case we have the value number one modulo and then the number of columns we have set right now is five so one modulo five if we divide one by five the remainder is one so this is the number that we're seeing for the next set of values let's start with six six modulo five six divided by five the remainder is also one so we're very close to what we need to accomplish we're seeing that the sixth value is now reassigned to column number one seventh value reassigned to column number two we do have one final change that we need to apply because in here we can see that value number five is actually receiving a column zero and it's because five modulo 5 if we divide 5 by 5 there is no remainder therefore the modulo is 0 the remainder is 0. so we simply need to reassign 0 with the number of columns so let's add that so i will use an if else statement in this case so if this value is zero then we simply want to display the number of columns otherwise we want the original value and then end there are simpler ways to do this but i'm going to use the if else statement because it makes it easier to follow the logic especially when you're just trying to understand what's happening under the hood so let's click on apply and in here we can now see that we have successfully created our columns so the second set of values have been reassigned to columns 1 all the way to 5. so now we're ready to create rows what we want to do is we want to leave the first five values in the first row with the second five values we want to shift this over so it goes to the next row the next five values onto the third row so how do we create this calculated field so let's create a new calculated field let's call this rows we're still going to base this off of the index calculated field let's drag index over and let's divide this by the number of columns let's click on apply first and display the values convert rows to discrete and display it so what we want to achieve is we want to make sure that the first five records have exactly the same value and the next five records will also have the exact same value so if we take a look at these values we have a couple options we can either round the values up so that all of these will get a value of 1 all of these will get a value of 2.
your other option is to round the values down so all of these values will get a value of 0 and the next 5 records will get a value of 1. there is a function in tableau called ceiling that will help us round the values up the problem is the ceiling function cannot be applied to table calculations so we need to find a different way to either round the values up or down so what we can do is we can force the values to be all rounded down so in here we can subtract one from our index let's click on apply again and we can see that the first five records can now be rounded down to zero so what we can do is we can convert the data type of these values to an integer value which means values of zero to zero point eight will be evaluated to zero so to convert the data type we simply need to add int to make it an integer and once we click and apply this allows us now to have a single row number for the first five records and another value for the next five records so these will be in row zero and the next one will be row number one and it's up to you if you want to add one more if you want to start the row numbers to one let's go back to our chart and create our initial small multiples let's add columns to columns and rows to rows because these are table calculation functions we need to make sure we specify the direction and the scope and in this case for now we're simply going to make sure that we're computing so we're computing a long subcategory and same thing for the rows and this is why i wanted to use color normally we don't want to use this many colors colors are used for highlighting or emphasizing something however for this particular exercise collar is very helpful in identifying if we have the correct value if we simply had one caller for all these lines or if we used a bar instead it's very easy to miss the fact that actually we have some wrong information in here let us take a look at row one column one notice this chart this chart actually has three different colors which means this one chart is not representing just a single subcategory there's two other subcategories in here that small dot over there and this small dot over here somehow they're in this same chart so we need to fix this first i hope you're enjoying this video so far if you haven't subscribed yet please consider subscribing i publish weekly tutorials on this channel so let's try to understand why is this even happening so i'm just going to duplicate this chart first so right click duplicate let's just leave this row and column keep only keep only let's also just leave these subcategories and now let's take away the rows and columns take away sales so what we need to understand in this scenario is that the index table calculation function simply gives us a sequential number regardless of what values are there and in this case some subcategories may not have sales for specific months therefore another subcategory value may be given the next sequential number if we have missing values this really throws off the index function so one way we can fix this is by creating another calculated field for date that will be populated regardless of whether that subcategory had sales in that month or not so let's create a new calculated field let's call this new order date we are going to base this on our existing continuous date field so we can just drag this over we're also just going to cast this again to a date so if there's any time component we're going to remove that let's click on ok let's add the new order date in detail so we're going to right click drag and add the individual values so in your drop field window we are going to use the discrete date we're not going to use any of the aggregated dates we're also going to replace the continuous date we have on columns so let's right click drag our new order date put this on top of the existing pill and because we want to visualize this as a continuous time series graph this time around we're going to use the continuous date for display there's a few more things we need to do since this pill is actually each individual order date from our data source we still want this aggregated somehow so we're going to encapsulate this with the adder function or the attr so if we have five orders in one day we're getting just one value instead of five different values so we can use an ad hoc calculation in this case let's double click on this new order date and we're going to place attr around this field name we're going to convert this to continuous because again we want this continuous time series graph but it doesn't feel like we've solved our problem yet but it's because remember for table calculation functions we need to specify the dimensions that we are considering in this calculation and in this case we have a brand new field that we want to consider in our table calculation function so let's click on columns edit table calculation we are going to add the new order date in our specific dimensions so that it's considered in that calculation and each calculation is at the level of or at the group of subcategory we're going to do the same thing for rows so on the drop down edit table calculation we're going to add the new order date and at the level of subcategory so now even just by visually looking at this we know that we have the correct results there's only a single set of values from the same subcategory that's being displayed in this small chart now let's work on the labels we're going to create two calculated fields one is for the total sales for that individual subcategory so in here let's create a calculated field let's call this subcategory sales and we are going to use a table calculation function called windows sum and when we place this on our canvas later on this window sum we need to make sure that the scope is actually just at the subcategory level it's going to calculate each one of these points and it's going to add up based on this one window or this one group the second calculation we're going to create is really just for aesthetics when we place our labels later on we want to make sure we place our labels in a consistent place and that it doesn't overlap any of our other marks and for us to do this we need to know what the highest mark is so in this case we can see that the highest sales for all of these is actually for this subcategory so we want to find this maximum value and this will allow us to approximate where we're going to place our label so for this label we're going to use a fixed lod create a new calculated field let's call this max sales and this is going to use a nested level of detail expression or a nested lod so let's start with the innermost level first we're going to use fixed and based on each subcategory and new order date we want to figure out the sales first so this will be sum of sales now what this does is it figures out each of these dots each of the values but out of all of those we need to find the highest peak so we can pass this to another level of detail expression and this time around we're going to use the table scoped fixed lod we're simply going to put a curly brace and the aggregate function max and we pass our previous lod into this max function let me just quickly reorder this so we can see what's happening so what we're saying in here is we want to find all individual sales for each month because remember our new order date is only at the monthly level we want to find all of these sales but only retain the maximum value so let's click on ok now in terms of placement there are a lot of strategies to do this and the way i'm going to show you may not work for some cases but right now the range of values we have are pretty even so i can simply find the number of points we have and get the midpoint the halfway mark in between the first point and the last point so let's create a calculated field let's call this halfway mark and what we're saying is if the index is equal to half of the points there is another table calculation function called size that allows us to get this divided by two and we're just going to convert this to the integer equivalent so if the index is at the halfway mark then we want to display one mark and that's going to be our maximum sales and end notice that at this point we are getting an error saying cannot mix aggregate and non-aggregate comparisons and the reason for that is even though we know in the expression we're doing aggregation the fixed level of detail expression returns a scalar value and we cannot mix and match table calculations and aggregates with non-aggregated values so we can simply enclose max sales with one other aggregation function it could be the minimum the maximum the sum the average it will not make a difference it will give the same result back to us so let's enclose this with a sum and click on okay so let's now put everything together let's take our halfway mark put that on rows now for the halfway mark we want this to be only based on the new order date so on the drop down compute using and this is going to be a long new order date and we can see that there's a dot right there at the midpoint we can also now display subcategory as the label so we can copy subcategory over to label and now we can also place our subcategory sales onto label this is still a table calculation so we still need to specify the scope and direction so on the drop down edit table calculation let's move sub category to the top let's select both subcategory and new order date and we're going to restart the totals for every subcategory so now we simply just need to adjust our formatting and polish our view so we can adjust the size of this dot make that really small so it's not visible we can change the color so it is fully transparent if you want we can change the label so it matches the mark color and maybe adjust the font style and then we can make this into a dual axis chart now so click on the drop down on the halfway mark pill make this a dual axis chart take away the extra measure names that has been introduced in both marks cards so take this out and in the sum of sales take out measure names as well since we have a dual axis chart we want to make sure we synchronize and some additional adjustments that we may need to do is we may need to add additional padding just to make sure that the labels actually don't overlap so in this case a common strategy is to go back to that max sales and just add some padding so for example we may just want to multiply this by 1. 2 or 1.
5 or whatever that factor is so once we click on apply you can see that the labels will go up maybe let's make this a 1.