108 Practical PowerPivot & DAX Formulas for Excel 2010
D
ata Analysis eXpressions (DAX) is a new language that makes its debut with
PowerPivot for Excel. It is a language designed to use formulas, which in turn
are based on one or more DAX functions. Some of its functions will look
familiar to veteran Excel users, although there are differences between DAX and Excel
functions. These differences are elaborated in this chapter. You will learn where and
how to write DAX functions and formulas, and there are a number of examples to try.
The all-important concept of filter context is discussed in detail. Other topics include
data types and operator precedence. Two of the most popular functions, RELATED() and
CALCULATE(), are covered in depth. The difference between DAX calculated columns
and DAX measures is explained. Hopefully, there is enough DAX in this overview
chapter to get you started. The second part of this book provides a comprehensive
reference, with examples, of all the DAX functions.
C
Key concepts What is DAX, where and how to write DAX, row context, filter
context, data types, operator precedence, calculated columns, measures, RELATED()
function, CALCULATE() function
What Is DAX?
In Chapter 1 and Chapter 2, there were very fleeting glimpses of a couple of DAX
formulas. In this chapter, by contrast, there is rather more DAX. In particular, we
examine the reasons for using DAX and take a look at some useful and popular DAX
formulas. A DAX formula is made up of one or more DAX expressions, functions,
operators, column values, table values, and literal values. DAX formulas can be used in
the PowerPivot window and/or in a PowerPivot pivot report (table or chart) visualized
in an Excel worksheet. In general terms, DAX extends PowerPivot to enhance its BI
capabilities. DAX gives you a great deal of control flexibility—you are not limited
by the composition of the source data. For many users, the already considerable
functionality of PowerPivot and pivot tables may be more than enough. For other users,
especially those of you with an interest in BI, DAX will give you almost unlimited
possibilities.
DAX is not the same as SQL or MultiDimensional eXpressions (MDX), nor is
it meant as a replacement for those languages. DAX is a new, dedicated BI language
and is easier than the “traditional” BI query and script language, MDX—a lot of DAX
syntax looks just like those good old familiar Excel formulas. There is a major difference
between Excel functions and DAX functions: Excel functions normally operate on
values in cells and ranges, while DAX functions can operate on columns, and tables, and
measures as well as relationally across multiple tables. DAX is specifically designed for
self-service or team BI. As such, you can use it to concatenate data, parse data, relate
tables, denormalize data, create hierarchical drill-downs in a pivot table, perform time