{"id":1699,"date":"2013-09-23T00:00:00","date_gmt":"2013-09-23T00:00:00","guid":{"rendered":"https:\/\/test.simple-talk.com\/uncategorized\/dax-statistical-functions\/"},"modified":"2021-08-24T13:39:50","modified_gmt":"2021-08-24T13:39:50","slug":"dax-statistical-functions","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/database-administration-sql-server\/dax-statistical-functions\/","title":{"rendered":"DAX Statistical Functions"},"content":{"rendered":"<div class=\"article-content\">\n<p class=\"start\"> \tThe Data Analysis Expressions (DAX) language includes a wide range of functions that help you refine your queries when retrieving data from a SQL Server Analysis Services (SSAS) tabular database. You&#8217;ve seen numerous examples of DAX functions throughout this series on the tabular model. One set of functions that are particularly useful when working with tabular data are the statistical functions, which support various ways to aggregate and analyze data. Statistical functions include not only the typical standbys, such as <code><strong>Min<\/strong><\/code> and <code><strong>Max<\/strong><\/code>, but also those that help structure that data into tables, such as <code><strong>AddColumns<\/strong><\/code> and <code><strong>Summarize<\/strong><\/code>. <\/p>\n<p> \tIn this article, the fifth in our series, we explore many of the DAX statistical functions and provide numerous examples that demonstrate how they work. As with the previous articles (<a href=\"https:\/\/www.simple-talk.com\/sql\/reporting-services\/getting-started-with-the-ssas-tabular-model-\/\">one<\/a> | <a href=\"https:\/\/www.simple-talk.com\/sql\/reporting-services\/using-dax-to-retrieve-tabular-data\/\">two<\/a> | <a href=\"https:\/\/www.simple-talk.com\/sql\/reporting-services\/using-microsoft-excel-to-retrieve-ssas-tabular-data\/\">three<\/a> | <a href=\"https:\/\/www.simple-talk.com\/sql\/database-administration\/using-dax-to-create-ssrs-reports-the-basics\/\">four<\/a>), the examples retrieve data from the <code><strong>AdventureWorks Tabular Model SQL 2012<\/strong><\/code> tabular database, available as a SQL Server Data Tools (SSDT) tabular project from the <a href=\"http:\/\/msftdbprodsamples.codeplex.com\/releases\/view\/55330\">AdventureWorks CodePlex site<\/a>. I implemented the database on a local instance of SSAS 2012 in tabular mode and developed the examples against that database. <\/p>\n<p> \tTo follow along in this article, you should have a basic understanding of how to write a DAX query. The first two articles provide a good starting point if you&#8217;re new to DAX and SSAS tabular databases. Once you&#8217;ve read through those, you should have no problem applying the statistical functions we cover here. <\/p>\n<p> \tGiven the analytical nature of tabular databases, it&#8217;s not surprising that the statistical functions play such a key role; learning them is well worth the effort. <\/p>\n<h2>The Row Function<\/h2>\n<p> \tOften when retrieving and aggregating tabular data, you&#8217;ll want to return only a single row in order to get a quick overview of your data. That&#8217;s where the <code><strong>Row<\/strong><\/code> function comes in. It returns a single-row table made up of one or more columns. You can use the function in conjunction with other functions in order to view different types of information. For example, the following query uses the <code><strong>Sum<\/strong><\/code> and <code><strong>Format<\/strong><\/code> functions in conjunction with the <code><strong>Row<\/strong><\/code> function in order to return the total amount of sales from the <code><strong>Sales Amount<\/strong><\/code> column in the <code><strong>Internet Sales<\/strong><\/code> table: <\/p>\n<pre class=\"listing\">evaluate\n(\n   row\n   (\n         \"Total Sales\", format(sum('Internet Sales'[Sales Amount]), \"Currency\")\n   )\n)\n<\/pre>\n<p> \tAs you&#8217;ve seen in the previous articles, you must use the <code><strong>Evaluate<\/strong><\/code> statement to retrieve data from an SSAS tabular database. The statement takes one argument: a table or table expression. In this example, we use the <code><strong>Row<\/strong><\/code> function to create the table expression. <\/p>\n<p> \tFor each column you want the <code><strong>Row<\/strong><\/code> function to return, you must specify the column name in double quotes followed by an expression that defines the value to be returned, with a comma separating the two components. In the example above, the <code><strong>Row<\/strong><\/code> function returns only one column named <code><strong>Total Sales<\/strong><\/code>, and the column expression uses the <code><strong>Sum<\/strong><\/code> function to return the sales total from <code><strong>Sales Amount<\/strong><\/code>. The expression then uses the <code><strong>Format<\/strong><\/code> function to return the value in a standard currency format (in US dollars). The following table shows the results returned by the <code><strong>Evaluate<\/strong><\/code> statement: <\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td valign=\"top\">\n<p><strong>Total Sales<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>$29,358,677.22<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p> \tIf you want to return more than one column, when using the <code><strong>Row<\/strong><\/code> function, you must include a name\/expression pair for each one, separated by a comma, as shown in the following example: <\/p>\n<pre class=\"listing\">evaluate\n(\n   row\n   (\n      \"Total Sales\", format(sum('Internet Sales'[Sales Amount]), \"Currency\"),\n      \"Average Sales\", format(average('Internet Sales'[Sales Amount]), \"Currency\"),\n      \"Highest Sale\", format(max('Internet Sales'[Sales Amount]), \"Currency\"),\n      \"Lowest Sale\", format(min('Internet Sales'[Sales Amount]), \"Currency\")\n   )\n)<\/pre>\n<p> \tEach column definition follows the same structure: column name followed by column expression. In this case, the column definitions differ only in the column name and the statistical function being applied. The <code><strong>Average<\/strong><\/code> function returns the average sales amount, the <code><strong>Max<\/strong><\/code> function return the highest sales amount, and the <code><strong>Min<\/strong><\/code> function returns the lowest. As the following results show, the <code><strong>Evaluate<\/strong><\/code> statement now returns four columns, but still one row: <\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td><strong>Total Sales<\/strong><\/td>\n<td><strong>Average Sales<\/strong><\/td>\n<td><strong>Highest Sale<\/strong><\/td>\n<td><strong>Lowest Sale<\/strong><\/td>\n<\/tr>\n<tr>\n<td>$29,358,677.22<\/td>\n<td>$486.09<\/td>\n<td>$3,578.27<\/td>\n<td>$2.29<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p> \tWhen using a statistical function such as <code><strong>Average<\/strong><\/code>, it can also be useful to know how many rows are being evaluated. The following example includes both the <code><strong>Count<\/strong><\/code> and <code><strong>DistinctCount<\/strong><\/code> statistical functions: <\/p>\n<pre class=\"listing\">evaluate\n(\n   row\n   (\n      \"Total Sales\", format(sum('Internet Sales'[Sales Amount]), \"Currency\"),\n      \"Average Sales\", format(average('Internet Sales'[Sales Amount]), \"Currency\"),\n      \"Count\", count('Internet Sales'[Sales Amount]),\n      \"Distinct Count\", distinctcount('Internet Sales'[Sales Amount])\n   )\n)<\/pre>\n<p> \tThe <code><strong>Count<\/strong><\/code> function returns the total number of values in the specified column, and the <code><strong>DistinctCount<\/strong><\/code> function returns the number of unique values in that column. The <code><strong>Count<\/strong><\/code> function does not work for string values, only number and date columns. Because we&#8217;re using the function on the <code><strong>Sales Amount<\/strong><\/code> column, it works fine because the column contains numerical data only. The following table shows the results now returned by the <code><strong>Evaluate<\/strong><\/code> statement: <\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td><strong>Total Sales<\/strong><\/td>\n<td><strong>Average Sales<\/strong><\/td>\n<td><strong>Count<\/strong><\/td>\n<td><strong>Distinct Count<\/strong><\/td>\n<\/tr>\n<tr>\n<td>$29,358,677.22<\/td>\n<td>$486.09<\/td>\n<td>60398<\/td>\n<td>42<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p> \tWhen working with the <code><strong>Count<\/strong><\/code> function, be aware that it counts only existing values. If a row is missing a value, that row is not counted. To get a count of all the rows in a table, you must use the <code><strong>CountRows<\/strong><\/code> statistical function, as shown in the following example: <\/p>\n<pre class=\"listing\">evaluate\n(\n   row\n   (\n      \"Average Cost\", format(average('Product'[Standard Cost]), \"Currency\"),\n      \"Count\", count('Product'[Standard Cost]),\n      \"Distinct Count\", distinctcount('Product'[Standard Cost]),\n      \"Row Count\", countrows('Product')\n   )\n)<\/pre>\n<p> \tIn this case, the <code><strong>Standard<\/strong><\/code><code><strong>Cost<\/strong><\/code> column in the <code><strong>Product<\/strong><\/code> table contains a number of empty cells, so a count based on that column returns a number less than the number of rows in the table, but the <code><strong>CountRows<\/strong><\/code> functions includes all rows, as the following results show: <\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td><strong>Average Cost<\/strong><\/td>\n<td><strong>Count<\/strong><\/td>\n<td><strong>Distinct Count<\/strong><\/td>\n<td><strong>Row Count<\/strong><\/td>\n<\/tr>\n<tr>\n<td>$434.27<\/td>\n<td>395<\/td>\n<td>135<\/td>\n<td>606<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p> \tAs you&#8217;ve seen, the <code><strong>Row<\/strong><\/code> function can be useful whenever you need to return only a single row, which is often the case when aggregating data. However, the other statistical functions we&#8217;ve looked at are by no means limited to the <code><strong>Row<\/strong><\/code> function. For example, you can use them with the <code><strong>Summarize<\/strong><\/code> function when grouping data. Nevertheless, more often than not you&#8217;ll find that if you use the <code><strong>Row<\/strong><\/code> function, you&#8217;ll be using the aggregate-type statistical functions as well. <\/p>\n<h2>The Topn Function<\/h2>\n<p> \tThe <code><strong>Topn<\/strong><\/code> function limits the rows returned by a query to the top number of rows specified when you call the function, similar to how a <code><strong>TOP<\/strong><\/code> expression works in T-SQL. When you use the <code><strong>Topn<\/strong><\/code> function, you must include three parameters. The first specifies the number of rows to return. The second is the table or table expression from which you&#8217;re extracting the top rows. And the third is an expression that specifies the order in which the rows in the table should be sorted before returning the top rows. Usually this is one or more columns in the target table. <\/p>\n<p> \tFor example, suppose you want to return the first five rows of the <code><strong>Sales Territory<\/strong><\/code> table, with the data sorted by the <code><strong>SalesTerritoryKey<\/strong><\/code> column. The following example shows how to call the <code><strong>Topn<\/strong><\/code> function and pass in the parameter values: <\/p>\n<pre class=\"listing\">evaluate\n(\n   topn(5, 'Sales Territory', [SalesTerritoryKey])\n)\n<\/pre>\n<p> \tOnce again, we start with an <code><strong>Evaluate<\/strong><\/code> statement and specify the <code><strong>Top<\/strong><\/code><code><strong>n<\/strong><\/code> function as the statement&#8217;s table expression. Into the function, we pass in the three required parameter values, which specify that the top five rows should be returned from the <code><strong>Sales Territory<\/strong><\/code> table, sorted by the <code><strong>SalesTerritoryKey<\/strong><\/code> column. The <code><strong>Evaluate<\/strong><\/code> statement returns the following data: <\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td valign=\"top\">\n<p><strong>SalesTerritoryKey<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Sales    Territory Region<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Sales    Territory Country<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Sales    Territory Group<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Sales    Territory Image<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>7<\/p>\n<\/td>\n<td valign=\"top\">\n<p>France<\/p>\n<\/td>\n<td valign=\"top\">\n<p>France<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Europe<\/p>\n<\/td>\n<td valign=\"top\">\n<p>System.Byte[]<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>9<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Australia<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Australia<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Pacific<\/p>\n<\/td>\n<td valign=\"top\">\n<p>System.Byte[]<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>8<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Germany<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Germany<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Europe<\/p>\n<\/td>\n<td valign=\"top\">\n<p>System.Byte[]<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>10<\/p>\n<\/td>\n<td valign=\"top\">\n<p>United    Kingdom<\/p>\n<\/td>\n<td valign=\"top\">\n<p>United    Kingdom<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Europe<\/p>\n<\/td>\n<td valign=\"top\">\n<p>System.Byte[]<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>11<\/p>\n<\/td>\n<td valign=\"top\">\n<p>NA<\/p>\n<\/td>\n<td valign=\"top\">\n<p>NA<\/p>\n<\/td>\n<td valign=\"top\">\n<p>NA<\/p>\n<\/td>\n<td valign=\"top\">\n<p>System.Byte[]<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p> \tOne thing that might seem odd about the results is that they return rows with the <code><strong>SalesTerritoryKey<\/strong><\/code> values of <code><strong>7<\/strong><\/code> through <code><strong>11<\/strong><\/code>. If you&#8217;re familiar with the data, you know that the first value is <code><strong>1<\/strong><\/code>. We&#8217;ll get into more details about this in a bit, but for now, know that the <code><strong>Topn<\/strong><\/code> function, by default, sorts the data in descending order, unlike most sort operations you&#8217;ll come across. <\/p>\n<p> \tAnother odd aspect of these results is that they&#8217;re not ordered according to the <code><strong>SalesTerritoryKey<\/strong><\/code> column, as you might expect. Although you have to specify the order when calling the <code><strong>Topn<\/strong><\/code> function, that order applies only when determining which rows to return, not when ordering the result set. For that, you need to add an <code><strong>Order<\/strong><\/code><code><strong>By<\/strong><\/code> clause that specifies the <code><strong>SalesTerritoryKey<\/strong><\/code> column, as shown in the following example: <\/p>\n<pre class=\"listing\">evaluate\n(\n   topn(5, 'Sales Territory', [SalesTerritoryKey])\n)\norder by 'Sales Territory'[SalesTerritoryKey]\n<\/pre>\n<p> \tNow our statement will return the data in the specified order, as the following results show: <\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td valign=\"top\">\n<p><strong>SalesTerritoryKey<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Sales    Territory Region<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Sales    Territory Country<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Sales    Territory Group<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Sales    Territory Image<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>7<\/p>\n<\/td>\n<td valign=\"top\">\n<p>France<\/p>\n<\/td>\n<td valign=\"top\">\n<p>France<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Europe<\/p>\n<\/td>\n<td valign=\"top\">\n<p>System.Byte[]<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>8<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Germany<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Germany<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Europe<\/p>\n<\/td>\n<td valign=\"top\">\n<p>System.Byte[]<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>9<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Australia<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Australia<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Pacific<\/p>\n<\/td>\n<td valign=\"top\">\n<p>System.Byte[]<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>10<\/p>\n<\/td>\n<td valign=\"top\">\n<p>United    Kingdom<\/p>\n<\/td>\n<td valign=\"top\">\n<p>United    Kingdom<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Europe<\/p>\n<\/td>\n<td valign=\"top\">\n<p>System.Byte[]<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>11<\/p>\n<\/td>\n<td valign=\"top\">\n<p>NA<\/p>\n<\/td>\n<td valign=\"top\">\n<p>NA<\/p>\n<\/td>\n<td valign=\"top\">\n<p>NA<\/p>\n<\/td>\n<td valign=\"top\">\n<p>System.Byte[]<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p> \tThe <code><strong>Topn<\/strong><\/code> function actually supports a fourth parameter, which determines whether the rows are sorted in ascending or descending order. As mentioned above, by default, they&#8217;re sorted in descending order. However, you can specify ascending or descending my adding a <code><strong>0<\/strong><\/code> for descending or a <code><strong>1<\/strong><\/code> for ascending. For example, the following <code><strong>Evaluate<\/strong><\/code> statement returns the top five rows in ascending order: <\/p>\n<pre class=\"listing\">evaluate\n(\n   topn(5, 'Sales Territory', [SalesTerritoryKey], 1)\n)\nprder by 'Sales Territory'[SalesTerritoryKey]\n<\/pre>\n<p>   The only difference between this example and the previous one is the addition of the fourth parameter for the <code><strong>Topn<\/strong><\/code> function. Now the statement returns the first five rows in the table, as shown in the following results:<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td valign=\"top\">\n<p><strong>SalesTerritoryKey<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Sales    Territory Region<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Sales    Territory Country<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Sales    Territory Group<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Sales    Territory Image<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>1<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Northwest<\/p>\n<\/td>\n<td valign=\"top\">\n<p>United    States<\/p>\n<\/td>\n<td valign=\"top\">\n<p>North    America<\/p>\n<\/td>\n<td valign=\"top\">\n<p>System.Byte[]<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>2<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Northeast<\/p>\n<\/td>\n<td valign=\"top\">\n<p>United    States<\/p>\n<\/td>\n<td valign=\"top\">\n<p>North    America<\/p>\n<\/td>\n<td valign=\"top\">\n<p>System.Byte[]<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>3<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Central<\/p>\n<\/td>\n<td valign=\"top\">\n<p>United    States<\/p>\n<\/td>\n<td valign=\"top\">\n<p>North    America<\/p>\n<\/td>\n<td valign=\"top\">\n<p>System.Byte[]<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>4<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Southwest<\/p>\n<\/td>\n<td valign=\"top\">\n<p>United    States<\/p>\n<\/td>\n<td valign=\"top\">\n<p>North    America<\/p>\n<\/td>\n<td valign=\"top\">\n<p>System.Byte[]<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>5<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Southeast<\/p>\n<\/td>\n<td valign=\"top\">\n<p>United    States<\/p>\n<\/td>\n<td valign=\"top\">\n<p>North    America<\/p>\n<\/td>\n<td valign=\"top\">\n<p>System.Byte[]<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p> \tYou can also use the <code><strong>Topn<\/strong><\/code> function in conjunction with other functions. For example, the following <code><strong>Evaluate<\/strong><\/code> statement returns the top five rows from the table returned by the <code><strong>Summarize<\/strong><\/code> function: <\/p>\n<pre class=\"listing\">evaluate\n(\n   topn(5,\n      summarize\n      (\n         'Internet Sales',\n         'Product'[Product Name],\n         'Date'[Calendar Year],\n         \"Sales Amount\", format(sum('Internet Sales'[Sales Amount]), \"currency\")\n      ),\n   [Sales Amount], 0)\n)\norder by [Sales Amount] desc<\/pre>\n<p> \tIn the previous examples, I specified the <code><strong>Sales<\/strong><\/code><code><strong>Territory<\/strong><\/code> table as the second parameter of the <code><strong>Topn<\/strong><\/code> function, but this time around I&#8217;m using the <code><strong>Summarize<\/strong><\/code> function as the table expression. The function returns the <code><strong>Product Name<\/strong><\/code> and <code><strong>Calendar Year<\/strong><\/code> columns, along with a calculated column that provides a sales total for each group of data. I then use the <code><strong>Topn<\/strong><\/code> function to return only the first five rows of the data returned by the <code><strong>Summarize<\/strong><\/code> function. Notice that I specify the calculated column (<code><strong>Sales<\/strong><\/code><code><strong>Amount<\/strong><\/code>) as the sort column, in descending order. The following table shows the results returned by the <code><strong>Evaluate<\/strong><\/code> statement: <\/p>\n<table>\n<tbody>\n<tr>\n<td valign=\"top\">\n<p><strong>Product Name<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Calendar Year<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Sales Amount<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Mountain-100    Silver, 38<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2006<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$98,599.71<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Mountain-100    Silver, 38<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2005<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$98,599.71<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Mountain-100    Black, 44<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2005<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$97,874.71<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Mountain-100    Black, 38<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2006<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$94,499.72<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Mountain-100    Black, 42<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2006<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$91,124.73<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p> \tAs you can see, the data now includes only the three columns specified in the <code><strong>Summarize<\/strong><\/code> function, with the data sorted in descending order, based on the <code><strong>Sales<\/strong><\/code><code><strong>Amount<\/strong><\/code> column. <\/p>\n<h1>The Rollup Function<\/h1>\n<p> \tYou&#8217;ve already gotten a taste of the <code><strong>Rollup<\/strong><\/code> function in the second article of this series. This time around, however, we&#8217;ll go into the function a little deeper and look at a couple other functions associated with <code><strong>Rollup<\/strong><\/code>. <\/p>\n<p> \tThe <code><strong>Rollup<\/strong><\/code> function is used in conjunction with the <code><strong>Summarize<\/strong><\/code> function. The <code><strong>Summarize<\/strong><\/code> function groups data together by the columns specified when you call the function. The function then returns a table that can be used by other functions, wherever a parameter requires a table value. You can also use the function as the table expression in an <code><strong>Evaluate<\/strong><\/code> statement. <\/p>\n<p> \tThe <code><strong>Summarize<\/strong><\/code> function supports the use of the <code><strong>Rollup<\/strong><\/code> function as part of the <code><strong>Summarize<\/strong><\/code> definition. The <code><strong>Rollup<\/strong><\/code> function adds roll-up rows to the returned table based on the columns used to group the data. The roll-up rows provide an additional layer of aggregation, above what you&#8217;ve already defined in your <code><strong>Summarize<\/strong><\/code> function. Let&#8217;s look at example to better understand how this works. In the following <code><strong>Evaluate<\/strong><\/code> statement, we use the <code><strong>Summarize<\/strong><\/code> function as the statement&#8217;s table expression: <\/p>\n<pre class=\"listing\">evaluate\n(\n   summarize\n   (\n      calculatetable\n      (\n         'Internet Sales',\n         'Product Category'[Product Category Name] = \"Accessories\"\t \n      ),\n      'Product'[Product Name],\n      rollup('Date'[Calendar Year]),\n      \"Total Sales\", format(sum('Internet Sales'[Sales Amount]), \"currency\")\n   )\n)\norder by\n   'Product'[Product Name],\n   'Date'[Calendar Year]<\/pre>\n<p> \tThe first parameter in the <code><strong>Summarize<\/strong><\/code> function requires its own table or table expression as its value. In this case, I&#8217;ve used a <code><strong>CalculateTable<\/strong><\/code> function to create that expression. The function returns the <code><strong>Internet Sales<\/strong><\/code> table, but limits the rows returned to those with a <code><strong>Product Category Name<\/strong><\/code> value equal to <code><strong>Accessories<\/strong><\/code>. <\/p>\n<p> \tThe second parameter value in the <code><strong>Summarize<\/strong><\/code> function specifies the <code><strong>Product Name<\/strong><\/code> column, which means the data will be grouped based on the values in that column. <\/p>\n<p> \tThe third value specifies the <code><strong>Calendar Year<\/strong><\/code> column. As a result, each product will be grouped by the year it was sold. However, I&#8217;ve also included the <code><strong>Rollup<\/strong><\/code> function in this expression. That means an additional row will be returned for each product that rolls up the data into a total for all years. <\/p>\n<p> \tThe last parameter value in the <code><strong>Summarize<\/strong><\/code> function is a calculated column named <code><strong>Total Sales<\/strong><\/code>. The column uses the <code><strong>Sum<\/strong><\/code> aggregate function to total the <code><strong>Sales Amount<\/strong><\/code> values for each grouping. I&#8217;ve also used the <code><strong>F<\/strong><\/code><code><strong>ormat<\/strong><\/code> function to return the data in a currency format. The following table shows the results returned by the <code><strong>Evaluate<\/strong><\/code> statement: <\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td valign=\"top\">\n<p><strong>Product Name<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Calendar Year<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Total Sales<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>All-Purpose    Bike Stand<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$39,591.00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>All-Purpose    Bike Stand<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$18,921.00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>All-Purpose    Bike Stand<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$20,670.00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bike    Wash &#8211; Dissolver<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$7,218.60<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bike    Wash &#8211; Dissolver<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$3,044.85<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bike    Wash &#8211; Dissolver<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$4,173.75<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Fender    Set &#8211; Mountain<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$46,619.58<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Fender    Set &#8211; Mountain<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$19,408.34<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Fender    Set &#8211; Mountain<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$27,211.24<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Hitch    Rack &#8211; 4-Bike<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$39,360.00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Hitch    Rack &#8211; 4-Bike<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$16,440.00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Hitch    Rack &#8211; 4-Bike<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$22,920.00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>HL    Mountain Tire<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$48,860.00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>HL    Mountain Tire<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$20,300.00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>HL    Mountain Tire<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$28,560.00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>HL    Road Tire<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$27,970.80<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>HL    Road Tire<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$12,877.00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>HL    Road Tire<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$15,093.80<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Hydration    Pack &#8211; 70 oz.<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$40,307.67<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Hydration    Pack &#8211; 70 oz.<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$16,771.95<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Hydration    Pack &#8211; 70 oz.<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$23,535.72<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p> \tAs with the previous examples, the results shown here are only part of the returned data, but you can see that totals are returned for each product sold and year it was sold. You can also see the roll-up row for each product-the rows without a <code><strong>Calendar Year<\/strong><\/code> value. <\/p>\n<p> \tThere might be times when you want to mark in some way when a row is a roll-up, other than just depending on blank values in the roll-up column. DAX includes the <code><strong>IsSubtotal<\/strong><\/code> function that you can use in conjunction with the <code><strong>Rollup<\/strong><\/code> function to create a column that indicates when a row is a roll-up. The <code><strong>IsSubtotal<\/strong><\/code> function returns a value of <code><strong>True<\/strong><\/code> if the row is a roll-up. Otherwise, the function returns <code><strong>False<\/strong><\/code>. The following example demonstrates how to use the <code><strong>IsSubtotal<\/strong><\/code> function by creating an additional column named <code><strong>Is<\/strong><\/code><code><strong>Rollup<\/strong><\/code>: <\/p>\n<pre class=\"listing\">evaluate\n(\n   summarize\n   (\n      calculatetable\n      (\n         'Internet Sales',\n         'Product Category'[Product Category Name] = \"Accessories\"\n      ),\n      'Product'[Product Name],\n      rollup('Date'[Calendar Year]),\n      \"Total Sales\", format(sum('Internet Sales'[Sales Amount]), \"currency\"),\n      \"Is Rollup\", IsSubtotal('Date'[Calendar Year])\n   )\n)\norder by\n   'Product'[Product Name],\n   'Date'[Calendar Year]<\/pre>\n<p> \tThe <code><strong>Evaluate<\/strong><\/code> statement is the same as the one shown in the preceding example, except for the addition of the <code><strong>Is Rollup<\/strong><\/code> column. Notice that the expression that defines the column includes the <code><strong>IsSubtotal<\/strong><\/code> function. When calling the function, you need to include the name of the column specified in the <code><strong>Rollup<\/strong><\/code> function, in this case the <code><strong>Calendar Year<\/strong><\/code> column. The <code><strong>Evaluate<\/strong><\/code> statement returns the following results: <\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td valign=\"top\">\n<p><strong>Product Name<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Calendar Year<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Total Sales<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Is Rollup<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>All-Purpose    Bike Stand<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$39,591.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>All-Purpose    Bike Stand<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$18,921.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>All-Purpose    Bike Stand<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$20,670.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bike    Wash &#8211; Dissolver<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$7,218.60<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bike    Wash &#8211; Dissolver<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$3,044.85<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bike    Wash &#8211; Dissolver<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$4,173.75<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Fender    Set &#8211; Mountain<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$46,619.58<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Fender    Set &#8211; Mountain<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$19,408.34<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Fender    Set &#8211; Mountain<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$27,211.24<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Hitch    Rack &#8211; 4-Bike<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$39,360.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Hitch    Rack &#8211; 4-Bike<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$16,440.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Hitch    Rack &#8211; 4-Bike<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$22,920.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>HL    Mountain Tire<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$48,860.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>HL    Mountain Tire<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$20,300.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>HL    Mountain Tire<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$28,560.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>HL    Road Tire<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$27,970.80<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>HL    Road Tire<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$12,877.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>HL    Road Tire<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$15,093.80<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Hydration    Pack &#8211; 70 oz.<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$40,307.67<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Hydration    Pack &#8211; 70 oz.<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$16,771.95<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Hydration    Pack &#8211; 70 oz.<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$23,535.72<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p> \tThe result set now includes the <code><strong>Is<\/strong><\/code><code><strong>Rollup<\/strong><\/code> column and is populated with <code><strong>True<\/strong><\/code> and <code><strong>False<\/strong><\/code> values, with each roll-up row receiving a value of <code><strong>True<\/strong><\/code>. <\/p>\n<p> \tNow suppose that instead of grouping our data by product and then year sold, we group it by product category, then product subcategory, and finally the year sold, as shown in the following example: <\/p>\n<pre class=\"listing\">evaluate\n(\n   summarize\n   (\n      'Internet Sales',\n      'Product Category'[Product Category Name],\n      'Product Subcategory'[Product Subcategory Name],\n      rollup('Date'[Calendar Year]),\n      \"Total Sales\", format(sum('Internet Sales'[Sales Amount]), \"currency\"),\n      \"Is Rollup\", IsSubtotal('Date'[Calendar Year])\n   )\n)\norder by\n   'Product Category'[Product Category Name],\n   'Product Subcategory'[Product Subcategory Name],\n   'Date'[Calendar Year]<\/pre>\n<p> \tAs in the previous examples, we&#8217;re rolling up our data based on the <code><strong>Calendar<\/strong><\/code><code><strong>Year<\/strong><\/code> column. Consequently, the statement will provide a roll-up row for each category\/subcategory grouping, as shown in the following results: <\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td valign=\"top\">\n<p><strong>Product    Category Name<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Product    Subcategory Name<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Calendar Year<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Total Sales<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Is Rollup<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bike    Racks<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$39,360.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bike    Racks<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$16,440.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bike    Racks<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$22,920.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bike    Stands<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$39,591.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bike    Stands<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$18,921.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bike    Stands<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$20,670.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bottles    and Cages<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$56,798.19<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bottles    and Cages<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$23,280.27<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bottles    and Cages<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$33,517.92<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Cleaners<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$7,218.60<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Cleaners<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$3,044.85<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Cleaners<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$4,173.75<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Fenders<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$46,619.58<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Fenders<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$19,408.34<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Fenders<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$27,211.24<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Helmets<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$225,335.60<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Helmets<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$92,583.54<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Helmets<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$132,752.06<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Hydration    Packs<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$40,307.67<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Hydration    Packs<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$16,771.95<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Hydration    Packs<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$23,535.72<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Tires    and Tubes<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$245,529.32<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Tires    and Tubes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$103,259.76<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Tires    and Tubes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$142,269.56<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Mountain    Bikes<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$9,952,759.56<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Mountain    Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2005<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$585,973.27<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Mountain    Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2006<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$1,562,456.76<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Mountain    Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$3,989,638.48<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Mountain    Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$3,814,691.06<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p> \tThis level of roll-up is probably fine for some of your needs, but at times, you might find it handy to return a roll-up row for each category, as well as each category\/subcategory grouping. The easiest way to do that is to add the <code><strong>Product<\/strong><\/code><code><strong>Subcategory<\/strong><\/code><code><strong>Name<\/strong><\/code> column to the <code><strong>Rollup<\/strong><\/code> function, as shown in the following example: <\/p>\n<pre class=\"listing\">evaluate\n(\n   summarize\n   (\n      'Internet Sales',\n      'Product Category'[Product Category Name],\n      rollup('Product Subcategory'[Product Subcategory Name], 'Date'[Calendar Year]),\n      \"Total Sales\", format(sum('Internet Sales'[Sales Amount]), \"currency\"),\n      \"Is Rollup\", IsSubtotal('Date'[Calendar Year])\n   )\n)\norder by\n   'Product Category'[Product Category Name],\n   'Product Subcategory'[Product Subcategory Name],\n   'Date'[Calendar Year]<\/pre>\n<p> \tWhen adding an additional column to the <code><strong>Rollup<\/strong><\/code> function, you must separate the column names with a comma, but that&#8217;s all you&#8217;ll need to do. As the following table shows, the results now include a roll-up row for each product category: <\/p>\n<table>\n<tbody>\n<tr>\n<td valign=\"top\">\n<p><strong>Product    Category Name<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Product    Subcategory Name<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Calendar Year<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Total Sales<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Is Rollup<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$700,759.96<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bike    Racks<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$39,360.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bike    Racks<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$16,440.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bike    Racks<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$22,920.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bike    Stands<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$39,591.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bike    Stands<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$18,921.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bike    Stands<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$20,670.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bottles    and Cages<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$56,798.19<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bottles    and Cages<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$23,280.27<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bottles    and Cages<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$33,517.92<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Cleaners<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$7,218.60<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Cleaners<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$3,044.85<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Cleaners<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$4,173.75<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Fenders<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$46,619.58<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Fenders<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$19,408.34<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Fenders<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$27,211.24<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Helmets<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$225,335.60<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Helmets<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$92,583.54<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Helmets<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$132,752.06<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Hydration    Packs<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$40,307.67<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Hydration    Packs<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$16,771.95<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Hydration    Packs<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$23,535.72<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Tires    and Tubes<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$245,529.32<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Tires    and Tubes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$103,259.76<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Tires    and Tubes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$142,269.56<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$28,318,144.65<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Mountain    Bikes<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$9,952,759.56<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Mountain    Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2005<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$585,973.27<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Mountain    Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2006<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$1,562,456.76<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Mountain    Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$3,989,638.48<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Mountain    Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$3,814,691.06<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p> \tThe <code><strong>Summarize<\/strong><\/code> function supports one other related function worth mentioning: <code><strong>RollupGroup<\/strong><\/code>. When used in conjunction with the <code><strong>Rollup<\/strong><\/code> function, the <code><strong>RollupGroup<\/strong><\/code> function prevents partial subtotals from being included in the result set. Let&#8217;s look at another example to demonstrate how this works. In the following <code><strong>Evaluate<\/strong><\/code> statement, I&#8217;ve added the <code><strong>RollupGroup<\/strong><\/code> function as part of the <code><strong>Rollup<\/strong><\/code> function: <\/p>\n<pre class=\"listing\">evaluate\n(\n   summarize\n   (\n      'Internet Sales',\n      'Product Category'[Product Category Name],\n      rollup(rollupgroup('Product Subcategory'[Product Subcategory Name], 'Date'[Calendar Year])),\n      \"Total Sales\", format(sum('Internet Sales'[Sales Amount]), \"currency\"),\n      \"Is Rollup\", IsSubtotal('Date'[Calendar Year])\n   )\n)\norder by\n   'Product Category'[Product Category Name],\n   'Product Subcategory'[Product Subcategory Name],\n   'Date'[Calendar Year]<\/pre>\n<p> \tThe column names are passed into the <code><strong>RollupGroup<\/strong><\/code> function, and that function is passed to the <code><strong>Rollup<\/strong><\/code> function. As to be expected, the statement now returns slightly different results: <\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td valign=\"top\">\n<p><strong>Product    Category Name<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Product Subcategory    Name<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Calendar Year<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Total Sales<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Is Rollup<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$700,759.96<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bike    Racks<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$16,440.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bike    Racks<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$22,920.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bike    Stands<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$18,921.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bike    Stands<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$20,670.00<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bottles    and Cages<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$23,280.27<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Bottles    and Cages<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$33,517.92<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Cleaners<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$3,044.85<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Cleaners<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$4,173.75<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Fenders<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$19,408.34<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Fenders<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$27,211.24<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Helmets<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$92,583.54<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Helmets<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$132,752.06<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Hydration    Packs<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$16,771.95<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Hydration    Packs<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$23,535.72<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Tires    and Tubes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$103,259.76<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Tires    and Tubes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$142,269.56<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>$28,318,144.65<\/p>\n<\/td>\n<td valign=\"top\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Mountain    Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2005<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$585,973.27<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Mountain    Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2006<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$1,562,456.76<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Mountain    Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$3,989,638.48<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>Mountain    Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$3,814,691.06<\/p>\n<\/td>\n<td valign=\"top\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p> \tA roll-up row is included for each category, but not for the subcategories. As you can see, DAX provides a number of ways to roll up your data so your results include exactly the information you need. <\/p>\n<h2>The Crossjoin Function<\/h2>\n<p> \tThe last function that we&#8217;ll look at is <code><strong>Crossjoin<\/strong><\/code>. You use a <code><strong>Crossjoin<\/strong><\/code> function to join two or more tables in order to return a <em>Cartesian <\/em><em>product<\/em><em>,<\/em> a result set in which each row in each table is joined with each row in each other table. The result set is the product of the number of rows from each table. For example, if one table contains five rows and a second table contains seven rows, the Cartesian product for those two tables will contain 35 rows. <\/p>\n<p> \tThis will all become clearer as we work through our examples. But first, take a look at the following <code><strong>Evaluate<\/strong><\/code> statement, in which we retrieve data from the <code><strong>Internet Sales<\/strong><\/code> table: <\/p>\n<pre class=\"listing\">evaluate\n(\n   summarize\n   (\n      'Internet Sales',\n      'Product Category'[Product Category Name],\n      'Date'[Calendar Year],\n      \"Total Sales\", format(sum('Internet Sales'[Sales Amount]), \"currency\")\n   )\n)\norder by\n   'Product Category'[Product Category Name],\n    'Date'[Calendar Year]<\/pre>\n<p> \tThe statement contains nothing that you haven&#8217;t seen before. It groups data based on the <code><strong>Product<\/strong><\/code><code><strong>Category<\/strong><\/code> and <code><strong>Calendar<\/strong><\/code><code><strong>Year<\/strong><\/code> columns and provides the sales totals for each group, as shown in the following results: <\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td valign=\"top\">\n<p><strong>Product    Category Name<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Calendar Year<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Total Sales<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$293,709.71<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$407,050.25<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2005<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$3,266,373.66<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2006<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$6,530,343.53<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$9,359,102.62<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$9,162,324.85<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Clothing<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$138,247.97<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Clothing<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$201,524.64<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p> \tThe <code><strong>Evaluate<\/strong><\/code> statement returns just what we&#8217;d expect. However, what&#8217;s important about these results are not what they include, but what is missing. For example, the <code><strong>Product Category<\/strong><\/code> column in the source table includes the value <code><strong>Components<\/strong><\/code>, but that value isn&#8217;t included in the results because no sales are associated with that category. In addition, years are displayed only if they have sales associated with them. For instance, the results include information about the Accessories category for 2007 and 2008, but no other years are listed. <\/p>\n<p> \tOften, we&#8217;ll want our results to be more complete than what we&#8217;re able to generate with a simple <code><strong>Summarize<\/strong><\/code> function and for that we need the <code><strong>Crossjoin<\/strong><\/code> function. It returns a Cartesian product, and we can use that data to generate more complete results. <\/p>\n<p> \tLet&#8217;s look at an example to give you an idea of how the <code><strong>Crossjoin<\/strong><\/code> function works. In the following <code><strong>Evaluate<\/strong><\/code> statement, I use the <code><strong>Crossjoin<\/strong><\/code> function as the statement&#8217;s table expression: <\/p>\n<pre class=\"listing\">evaluate\n(\n   crossjoin\n   (\n      values('Product Category'[Product Category Name]),\n      values('Date'[Calendar Year])\n   )\n)\norder by\n   'Product Category'[Product Category Name],\n   'Date'[Calendar Year]<\/pre>\n<p> \tI pass two arguments into the <code><strong>Crossjoin<\/strong><\/code> function. Each argument must return a table. In this case, I use the <code><strong>Values<\/strong><\/code> function for each argument in order to return a one-column table of distinct values. The first <code><strong>Values<\/strong><\/code> function returns a list of values from the <code><strong>Product Category Name<\/strong><\/code> column, and the second <code><strong>Values<\/strong><\/code> function returns a list of values from the <code><strong>Calendar Year<\/strong><\/code> column. (These are the same two columns used to group data in the previous example.) The <code><strong>Evaluate<\/strong><\/code> statement returns the results shown in the following table: <\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td valign=\"top\">\n<p><strong>Product    Category Name<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Calendar Year<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>2005<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>2006<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>2009<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>2010<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2005<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2006<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2009<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2010<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2005<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2006<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2009<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2010<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Clothing<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2005<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Clothing<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2006<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Clothing<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Clothing<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Clothing<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2009<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Clothing<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2010<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Components<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2005<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Components<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2006<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Components<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Components<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Components<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2009<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Components<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2010<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p> \tEach row in each table has been joined with each row in the other table. For example, the <code><strong>Accessories<\/strong><\/code> value in the <code><strong>Product Category Name<\/strong><\/code> column is matched with each year in the <code><strong>Calendar Year<\/strong><\/code> column. The reason that there are blank values in the <code><strong>Product Category Name<\/strong><\/code> column is because the source data-the <code><strong>Product Category<\/strong><\/code> table in the tabular database-includes a blank member, and that blank member is matched with each year, just like the other <code><strong>Product Category Name<\/strong><\/code> values. Because the <code><strong>Product Category<\/strong><\/code> column contains five distinct values, and the <code><strong>Calendar Year<\/strong><\/code> column contains six distinct values, our query returns 30 rows. <\/p>\n<p> \tNow that we know how to use the <code><strong>Crossjoin<\/strong><\/code> function to produce the Cartesian product, we can include it in our <code><strong>Evaluate<\/strong><\/code> statement to return more meaningful data. The following example uses the <code><strong>Crossjoin<\/strong><\/code> function as the table expression within the <code><strong>Summarize<\/strong><\/code> function: <\/p>\n<pre class=\"listing\">evaluate\n(\n   summarize\n  (\n     crossjoin\n     (\n        values('Product Category'[Product Category Name]),\n        values('Date'[Calendar Year])\n     ),\n     'Product Category'[Product Category Name],\n     'Date'[Calendar Year],\n     \"Total Sales\", format(sum('Internet Sales'[Sales Amount]), \"currency\")\n  )\n)\norder by\n    'Product Category'[Product Category Name],\n    'Date'[Calendar Year]<\/pre>\n<p> \tThe <code><strong>Summarize<\/strong><\/code> function is now working with a <code><strong>Cartesian<\/strong><\/code> product as its table. We can then group the data based on the <code><strong>Product<\/strong><\/code><code><strong>Category<\/strong><\/code><code><strong>Name<\/strong><\/code> column and the <code><strong>Calendar<\/strong><\/code><code><strong>Year<\/strong><\/code> column, both of which are including in the Cartesian product. Now the <code><strong>Evaluate<\/strong><\/code> statement returns the following results: <\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td valign=\"top\">\n<p><strong>Product    Category Name<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Calendar Year<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\n<p><strong>Total Sales<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>2005<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>2006<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>2009<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><\/td>\n<td valign=\"top\">\n<p>2010<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2005<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2006<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$293,709.71<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$407,050.25<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2009<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Accessories<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2010<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2005<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$3,266,373.66<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2006<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$6,530,343.53<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$9,359,102.62<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$9,162,324.85<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2009<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Bikes<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2010<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Clothing<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2005<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Clothing<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2006<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Clothing<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$138,247.97<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Clothing<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\">\n<p>$201,524.64<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Clothing<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2009<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Clothing<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2010<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Components<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2005<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Components<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2006<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Components<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2007<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Components<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2008<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Components<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2009<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p>Components<\/p>\n<\/td>\n<td valign=\"top\">\n<p>2010<\/p>\n<\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p> \tAs you can see, all the data is included in the results, whether or not any sales were made for a particular category in a particular year. This way, you know you&#8217;re returning the complete results, which can often give you a better picture of the data-and point to where potential problems might exist. <\/p>\n<h1>DAX Statistical Functions<\/h1>\n<p> \tYou should now have a good sense of how to use the <code><strong>Row<\/strong><\/code>, <code><strong>Topn<\/strong><\/code>, <code><strong>Rollup<\/strong><\/code>, and <code><strong>Crossjoin<\/strong><\/code> functions, along with several of the aggregate statistical functions. Once you know the basics of how to use them, you should be able to apply them to other situations. DAX also supports a number of other statistical functions, as well as additional functions types, such as date and time functions, filter functions, and logical functions. Be sure to check out the TechNet article &#8220;<a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/ee634396.aspx\">DAX Function Reference<\/a>&#8221; for information about those other functions as well as additional details about the functions we&#8217;ve covered. <\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Following on from his first four articles on using Data Analysis Expressions (DAX) with tabular databases, Robert Sheldon dives into some of the DAX statistical functions available, demonstrating which are the most useful and examples of how they work. &hellip;<\/p>\n","protected":false},"author":221841,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[143527],"tags":[4168,4170,5872,4658,4150,5131,5296,5873],"coauthors":[],"class_list":["post-1699","post","type-post","status-publish","format-standard","hentry","category-database-administration-sql-server","tag-database","tag-database-administration","tag-dax","tag-functions","tag-sql","tag-ssas","tag-statistics","tag-tabular-model"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/1699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/221841"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=1699"}],"version-history":[{"count":3,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/1699\/revisions"}],"predecessor-version":[{"id":92235,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/1699\/revisions\/92235"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=1699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=1699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=1699"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=1699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}