| DAX Queries, Part 2 |
| Written by Chris Webb | |||
| Friday, 15 July 2011 20:29 | |||
|
Reposted from Chris Webb's blog with the author's permission. Following on from my last post, let’s now see how we can do group-by style in DAX queries. The key to aggregating data is the Summarize() function, which is broadly similar to a Group By in SQL. So if the following query returns every row from the FactInternetSales table: evaluate( The following query just returns a list of all the distinct combinations of values from the OrderDateKey and CustomerKey columns: evaluate( Once we’ve specified the name of the table in the first parameter of Summarize, we can then supply a list of columns in the table to group by. This list can contain any number of columns, but we can also do aggregations inside Summarize by supplying a list of column names and DAX numeric expressions after the list of columns. So, for example: evaluate( Gives us the sum of the SalesAmount column and the number of distinct values in CustomerKey, for each distinct OrderDateKey value, as extra columns in the resultset. We can also reference columns from related tables in our aggregations. So for example this query uses the DimDate table and gives us data aggregated up by year: evaluate( Finally (at least for today), we can do subtotalling by using the Rollup() function inside our list of group by columns; each column we list inside Rollup() will work like a regular group by column but it will also have a subtotal row added for it in the resultset. So here, for example, is the query above with an extra group by on the days of the week: evaluate( I’ve highlighted the subtotals rows here, but we can also identify these rows using the new IsSubTotal() function: evaluate(
|
Author articles
- Controlling the Position of Subtotals in DAX with GenerateAll()
- Self-Service BI Mapping with Microsoft Research’s Layerscape–Part 2
- Self-Service BI Mapping with Microsoft Research’s Layerscape–Part 1
- Aliasing Columns in DAX
- Using Google Docs, Data Explorer and PowerPivot for Questionnaires
Most Popular
- Step by step guide on installing PowerPivot for SharePoint on a single machine
- List of suggested datasets to test PowerPivot
- List of PowerPivot DAX functions with description
- How to install PowerPivot for Excel and list of know issues
- Microsoft Virtual Lab: PowerPivot for Excel 2010 Introduction
- List of PowerPivot DAX functions (short)
- Learning PowerPivot and DAX
- PowerPivot's impact on BI pros?



