Introduction To DAX
Introduction To DAX
Debangshu Chatterjee 1
What is DAX?
• DAX stands for Data Analysis eXpressions
• A formula language used in Power BI that provides the ability to create columns, tables, and measures.
• It is used in other Microsoft tools including Analysis Services and Power Pivot.
Debangshu Chatterjee 2
DAX functions
• Functions are predefined formulas that perform calculations on specific values, called arguments, in a
particular order.
• Each function has a specific syntax indicating the order of arguments to be expected.
• DAX has over 200 different functions that fall into several categories, including Aggregation, Date and Time,
Logical, Text, and many more.
Debangshu Chatterjee 3
Calculated Columns and Calculated Measures
Debangshu Chatterjee 4
Creating a Calculated Column
• Adventure Works Cycles
• We want to create a Profit column to understand how much profit for each order line
Debangshu Chatterjee 5
Creating a Calculated Measure
• Create a table _Calculations
Debangshu Chatterjee 6
Profit Margin Ratio
• Compares the Total Profit to the Total Sales
• It is expressed as a percentage
Debangshu Chatterjee 7
Context
• Enables dynamic analysis, where the results of a formula change to reflect the selected data
Debangshu Chatterjee 8
Row Context
• Row context can be thought of as "the current row“
• Columns
• In a calculated column the context includes the values from all columns within the current row.
• Row context can also be used in measures, however only when using iterator functions.
Debangshu Chatterjee 9
Row Context
• Measures
• Row context can also be used in measures, however only when using iterator functions.
Debangshu Chatterjee 10
Filter Context
• Filter context is a set of filters that have been applied before the calculation is carried out.
• In order for Power BI to return a value for color blue, it will go to the base table and apply a filter
where color is equal to blue. This is the filter context. It is applying the filter context on each quantity
returned by color.
Debangshu Chatterjee 11
Filter Context
Debangshu Chatterjee 12
Calculate Function
• Calculate allows you to evaluate an expression with one or more filter contexts.
• calculate functions takes two arguments - one argument is required and the other argument is
optional.
• The first argument contains the expression to be evaluated - this must return a single value
• The second argument for adding filters is optional - but you need to ensure that filters evaluate as a
table, and do not clash with one another.
• The filters inside the CALCULATE() function will always override any filters from a visualization.
Debangshu Chatterjee 13
Email Id: [email protected]
Contact Number: +919971366473
Debangshu Chatterjee 14