DAX: The Complete Guide
Master Data Analysis Expressions (DAX) — the powerful formula language behind Microsoft Power BI, Excel Power Pivot, and SQL Server Analysis Services Tabular models. This comprehensive guide covers core concepts, essential functions, and real-world examples.
Table of Contents
- 1. What is DAX?
- 2. Calculated Columns vs. Measures
- 3. Row Context & Filter Context
- 4. Essential DAX Functions
- 5. Aggregation Functions
- 6. Logical Functions
- 7. Text Functions
- 8. Date & Time Functions
- 9. Time Intelligence Functions
- 10. Iterator (X) Functions
1. What is DAX?
Data Analysis Expressions (DAX) is a library of functions and operators used to build formulas and expressions in Microsoft’s tabular data modeling tools. It powers dynamic calculations in:
- Power BI (Desktop & Service)
- Excel Power Pivot
- SQL Server Analysis Services (SSAS) Tabular
DAX enables analysts and data professionals to create calculated columns, measures, and calculated tables for advanced analytics, time-based comparisons, and contextual aggregations.
2. Calculated Columns vs. Measures
Calculated Column
Computed row-by-row during data refresh. Results are stored in the model and consume memory.
Measure
Evaluated dynamically at query time based on current filter context (slicers, visuals, rows/columns in a matrix).
3. Row Context & Filter Context
Row Context
Automatically created when a formula evaluates an expression for each row in a table — common in calculated columns and iterator functions (e.g., SUMX).
Filter Context
Defined by the current selection in visuals, slicers, filters, or explicitly modified using CALCULATE().
4. Essential DAX Functions
4.1 CALCULATE() — The Most Powerful Function
Modifies or replaces the existing filter context. It is the cornerstone of nearly all advanced DAX expressions.
4.2 FILTER() — Row-Level Filtering
Returns a table filtered row-by-row. Used inside CALCULATE for complex conditions.
5. Aggregation Functions
Perform summary calculations over a column or expression.
SUM()– TotalAVERAGE()– MeanMIN(),MAX()– ExtremesCOUNT(),COUNTA()– Count valuesCOUNTROWS()– Count table rowsDIVIDE(numerator, denominator, [alternate_result])– Safe division
6. Logical Functions
IF(logical_test, value_if_true, value_if_false)SWITCH(expression, value1, result1, ..., [default])AND(),OR()NOT()
7. Text Functions
CONCATENATE(text1, text2)or&operatorLEFT(),RIGHT(),MID()UPPER(),LOWER(),PROPER()FORMAT(value, format_string)
8. Date & Time Functions
TODAY(),NOW()YEAR(),MONTH(),DAY()DATE(year, month, day)DATEDIFF(start_date, end_date, interval)
9. Time Intelligence Functions
Require a properly marked Date table with continuous dates.
SAMEPERIODLASTYEAR()DATEADD()PARALLELPERIOD()TOTALYTD(),CLOSINGBALANCEMONTH()
10. Iterator (X) Functions
Iterate over a table, evaluate an expression for each row, then aggregate results. Create row context manually.
SUMX(table, expression)AVERAGEX(),MINX(),MAXX()COUNTX(),FILTER()with iterators
Comments
Post a Comment