Microsoft Docs

DAX Overview

Category: Data Analysis Expressions (DAX) | Product: SQL Server Analysis Services, Power BI, Excel

This document provides a comprehensive introduction to Data Analysis Expressions (DAX), a formula expression language used in Power Pivot in Excel, SQL Server Analysis Services, and Power BI. Learn about its core concepts, syntax, and common use cases.

What is DAX?

Data Analysis Expressions (DAX) is a collection of functions, operators, and constants that can be used in a formula, in Power Pivot in Excel, SQL Server Analysis Services (SSAS) tabular models, and Power BI. DAX enables you to create custom calculations for tabular data models using existing data, including calculations, aggregations, and custom data-shaping.

DAX is designed for business intelligence and data modeling, allowing you to:

Key Concepts

Understanding the following key concepts is crucial for working effectively with DAX:

Formulas

DAX formulas are used to define calculations. They begin with an equals sign (=) and consist of functions, operators, and values.

Tables and Columns

DAX operates on tables and columns within a tabular data model. Formulas often reference tables and columns by their names.

Evaluation Context

This is perhaps the most important concept in DAX. The evaluation context determines how a DAX formula is evaluated, and it can be modified by functions such as CALCULATE, row context, and filter context.

Measures vs. Calculated Columns

DAX formulas can create two primary types of calculations:

Basic DAX Syntax

A typical DAX formula structure looks like this:

FunctionName(Argument1, Argument2, ...)

Common Functions

DAX provides a rich library of functions for various purposes. Some of the most fundamental include:

Example: Calculating Total Sales

Here's a simple example of a DAX measure to calculate the total sales from a table named Sales with a column named Amount:

Total Sales = SUM(Sales[Amount])

In this example:

Example: Calculating Sales Year-to-Date (YTD)

A more complex example, calculating YTD sales, showcases the power of DAX's time intelligence functions:

Sales YTD =
TOTALYTD(
    SUM(Sales[Amount]),
    'Date'[Date]
)

This requires a dedicated Date table marked as a date table in your model.

Resources

For further learning and in-depth information, explore these resources:

DAX is a powerful language that, once mastered, can unlock deep insights from your data. Practice and exploration are key to becoming proficient.