DAX (Data Analysis Expressions) is a formula language used in Power BI, Excel, and SQL Server Analysis Services (SSAS) for defining custom calculations in your data models. It is designed for creating powerful, flexible, and complex calculations on data that can be visualized, analyzed, and used in reports and dashboards.
DAX is similar to Excel formulas but is much more powerful due to its ability to handle large datasets, relationships, and context. It is used for creating measures, calculated columns, and calculated tables, and it can be leveraged to filter and manipulate data dynamically.
Key Concepts in DAX:
Data Model Context: DAX calculations are influenced by the context in which they are used, which is determined by:
- Row Context: Refers to the context in a single row of data.
- Filter Context: Refers to the filters or slicers applied to data.
- Evaluation Context: A combination of row and filter context, influencing how DAX formulas calculate values.
Measures: Measures are calculations that are typically aggregated over rows of data, like totals, averages, or counts. They are recalculated depending on the filters or slicers applied in reports or visuals.
- Example:
Total Sales = SUM(Sales[SalesAmount])
- Example:
Calculated Columns: These are calculated values added to tables that are computed for each row. Calculated columns become part of the data model and are stored in the table.
- Example:
Profit = Sales[Revenue] - Sales[Cost]
- Example:
Calculated Tables: Calculated tables are tables created by DAX expressions, not directly from the data source. These tables can be used for advanced modeling or to simplify complex models.
- Example:
SalesSummary = SUMMARIZE(Sales, Sales[Product], "Total Sales", SUM(Sales[Amount]))
- Example: