How to write queries in DAX to interrogate SSAS tabular models
Part four of an eight-part series of blogs

As well as creating measures to aggregate data in tabular models using DAX, you can also write queries to extract data - this blog shows you how!

  1. Writing DAX queries
  2. DAX and SQL compared
  3. The EVALUATE command in the DAX query language
  4. Using SUMMARIZE to group or aggregate DAX query data (this blog)
  5. Filtering in DAX queries using CALCULATETABLE or FILTER
  6. Adding columns in a DAX query using ADDCOLUMNS
  7. Combining the results of two or more tables
  8. Other useful DAX functions

This blog is part of our online SSAS Tabular tutorial; we also offer lots of other Analysis Services training resources.

Posted by Andy Brown on 12 February 2016

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Using SUMMARIZE to group or aggregate DAX query data

It's rare that you'll want to list all of the rows in a table: more commonly, you'll want to summarise data.

The DAX SUMMARIZE function is so similar to the concept of SELECT ... GROUP BY in SQL that you may wonder why Microsoft couldn't have merged the two language features!

Syntax of the SUMMARIZE command

In DAX you can summarise by one or more fields in a table, and then show an aggregation for each unique combination of values. Here's the basic syntax:



Table whose columns you want to display,

First column you want to aggregate or group by,
Last column you want to aggregate or group by,

Name of first aggregated expression,
Expression formula to use for this,


Name of last aggregated expression,
Expression formula to use for this


By far the easiest way to understand this is to look at the examples which follow below.

Summarising by a single column

This query would show the total quantity sold by species:

-- show total quantity by species





"Quantity sold",

SUM ( 'Transaction'[Quantity] )


This query should give the following results:

Quantity sold by species

The total quantity column has been renamed to Quantity sold, as requested.


Summarising by more than one column

The following query would show the number of transactions and quantity sold by species, animal and product:

-- show two statistics

-- summarised by 3 columns







"Number of transactions",

COUNTROWS ( 'Transaction' ),

"Quantity sold",

SUM ( 'Transaction'[Quantity] )


Here's what you should get when you run this query:

Totals by species, animal and product

The query groups by 3 columns, and shows two statistics.

Using ROLLUP to get all possible subtotal combinations

Just as in SQL, you can use the ROLLUP function to force DAX to calculate all subtotals and totals.  For example:

-- show total sales for each

-- year and species








"Total qty",

SUM ( 'Transaction'[Quantity] )


Here's what this would show:

Totals by year and species

You can include as many or as few columns as you like in the ROLLUP function. 


You can use the ISSUBTOTAL function with ROLLUP to determine for any column whether it is being used for grouping, subtotalling or totalling (although you'd have to care a lot more than this owl about the roll-up feature to do so).

So far we've been considering all the rows in tables; what I'll do in the next part of this blog is to show how to filter data.

This blog has 0 threads Add post