More On DAX - Using Advanced DAX Functions - DAT206x Courseware - EdX
More On DAX - Using Advanced DAX Functions - DAT206x Courseware - EdX
Microsoft: DAT206x
Analyzing and Visualizing Data with Excel
Help Taiwancoolboy !
More on DAX
DAX Functions
Functions are predefined formulas that perform calculations by using specific
values, called arguments, in a particular order or structure. Arguments can be
other functions, another formula, column references, numbers, text, logical
values such as TRUE or FALSE, or constants.
DAX includes the following categories of functions: Date and Time, Information,
Logical, Mathematical, Statistical, Text, and Time Intelligence Functions. If you are
familiar with functions in Excel formulas, many of the functions in DAX will
appear similar to you; however, DAX functions are unique in the following ways:
DAX includes many functions that return a table rather than a value. The table
is not displayed, but is used to provide input to other functions. For example,
you can retrieve a table and then count the distinct values in it, or calculate
dynamic sums across filtered tables or columns.
https://courses.edx.org/courses/course-v1)Microsoft+DAT206x+3T2…e99f54dd43d949eb5/8fa35ffd65e249c589e595ba6ffe4af6/?child=first Page 1 of 5
More on DAX | Using Advanced DAX Functions | DAT206x Courseware | edX 2018/10/22, 17)31
DAX includes a variety of time intelligence functions. These functions let you
define or select date ranges, and perform dynamic calculations based on
them. For example, you can compare sums across parallel periods.
1. In the FactSales table, scroll to the right-most column, and then in the column
header, click Add Column.
4. In the Insert Function dialog box, click the Select a category list box. By default,
All is selected, and all of the functions in the All category are listed below.
That’s a lot of functions, so you will want to filter the functions to make it
easier to locate the type of function you are looking for.
Context
https://courses.edx.org/courses/course-v1)Microsoft+DAT206x+3T2…99f54dd43d949eb5/8fa35ffd65e249c589e595ba6ffe4af6/?child=first Page 2 of 5
More on DAX | Using Advanced DAX Functions | DAT206x Courseware | edX 2018/10/22, 17)31
Context is one of the most important DAX concepts to understand. There are
two types of context in DAX; row context and filter context. We will first look at
row context.
Row Context
Row context is most easily thought of as the current row. For example, let's
assume we have a simple DAX formula used to create new data (named Margin)
for each row in a calculated column, defined as follows: Margin:=[SalesAmount]-
[TotalCost]. The formula =[SalesAmount] - [TotalCost] calculates a value in the
Margin column for each row in the table. Values for each row are calculated from
values in two other columns, [SalesAmount] and [TotalCost] in the same row.
DAX can calculate the values for each row in the Margin column because it has
the context: For each row, it takes values in the [TotalCost] column and subtracts
them from values in the [SalesAmount] column.
Row context doesn’t just apply to calculated columns. Row context also applies
whenever a formula has a function that applies filters to identify a single row in a
table. The function will inherently apply a row context for each row of the table
over which it is filtering. This type of row context most often applies to calculated
fields.
Filter Context
Filter context is a little more difficult to understand than row context. You can
most easily think of filter context as: One or more filters applied in a calculation
that determines a result or value.
Filter context does not exist in place of row context; rather, it applies in addition
to row context. For example, to further narrow down the values to include in a
calculation, you can apply a filter context which not only specifies the row
context, but also specifies only a particular value (filter) in that row context.
Filter context is easily seen in pivot tables. For example, when you add TotalCost
to the Values area, and then add Year and Region to the Row or Columns, you
are defining a filter context that selects a subset of data based on a given year
and region.
https://courses.edx.org/courses/course-v1)Microsoft+DAT206x+3T2…99f54dd43d949eb5/8fa35ffd65e249c589e595ba6ffe4af6/?child=first Page 3 of 5
More on DAX | Using Advanced DAX Functions | DAT206x Courseware | edX 2018/10/22, 17)31
Why is filter context so important to DAX? Because, while filter context can most
easily be applied by adding column and row labels and slicers in a PivotTable,
filter context can also be applied in a DAX formula by defining a filter using
functions such as ALL, RELATED, FILTER, CALCULATE, by relationships, and by
other calculated fields and columns. For example, let’s look at the following
formula in a calculated field named StoreSales:
Clearly this formula is more complex than some of the other formulas you’ve
seen. However, to better understand this formula, we can break it down, much
like we’ve done with other formulas.
B. The equals sign operator (=) indicates the beginning of the formula.
https://courses.edx.org/courses/course-v1)Microsoft+DAT206x+3T2…99f54dd43d949eb5/8fa35ffd65e249c589e595ba6ffe4af6/?child=first Page 4 of 5
More on DAX | Using Advanced DAX Functions | DAT206x Courseware | edX 2018/10/22, 17)31
This formula will ensure only sales values, defined by the Sales calculated field,
as a filter, are calculated only for rows in the DimChannel[ChannelName] column
with the value “Store”, as a filter.
As you can imagine, being able to define filter context within a formula has
immense and powerful capability. Being able to reference only a particular value
in a related table is just one such example. Don’t worry if you do not completely
understand context right away. As you create your own formulas, you will better
understand context and why it is so important in DAX.
Add a Post
https://courses.edx.org/courses/course-v1)Microsoft+DAT206x+3T2…99f54dd43d949eb5/8fa35ffd65e249c589e595ba6ffe4af6/?child=first Page 5 of 5