SlideShare a Scribd company logo
1 of 16
Download to read offline
QuickStart: Learn DAX Basics in 30
Minutes
Owen Duncan
Summary: This QuickStart is for users new to PowerPivot or tabular model projects
authored in SQL Server Data Tools. It is meant to give you a quick and easy introduction
on how you can use Data Analysis Expressions (DAX) to solve a number of basic data
modeling and analytical problems.
Category: Quick Step-By-Step
Applies to: PowerPivot for Excel (all versions), SQL Server 2008 R2, SQL Server 2012
Source: TechNet Wiki (link to source content)
E-book publication date: May 2012
13 pages
Copyright © 2012 by Microsoft Corporation
All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means
without the written permission of the publisher.
Microsoft and the trademarks listed at
http://www.microsoft.com/about/legal/en/us/IntellectualProperty/Trademarks/EN-US.aspx are trademarks of the
Microsoft group of companies. All other marks are property of their respective owners.
The example companies, organizations, products, domain names, email addresses, logos, people, places, and events
depicted herein are fictitious. No association with any real company, organization, product, domain name, email address,
logo, person, place, or event is intended or should be inferred.
This book expresses the author’s views and opinions. The information contained in this book is provided without any
express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will
be held liable for any damages caused or alleged to be caused either directly or indirectly by this book.
Quic
Min
This QuickS
meant to g
number of
you can co
understand
What is DA
DAX is a co
and return
model.
Why is DA
It’s easy to
PivotCharts
critical sale
inventory d
important c
data. When
line. This is
Prereq
You might
understand
you get sta
We are goi
with funda
Help. You s
PowerPivot
help, which
Example W
The best w
yourself. Th
workbook
downloade
Note:
If you are w
ckStar
utes 
Start is for user
give you a quick
basic data mo
omplete, and a
ding of the mo
AX?
ollection of fun
one or more v
AX so importan
create a Powe
s that display im
es data across s
data from sever
capabilities as w
n you get the in
s Business Intel
uisites
already be fam
ding DAX, but e
arted creating D
ing to focus sp
mental concep
should also be
t, you should fi
h is usually inst
Workbook
way to learn DAX
he examples an
from http://go
ed onto your co
working in the A
rt: Lea
 
rs new to Powe
k and easy intro
deling and ana
few quizzes to
st basic fundam
ctions, operato
values. Stated m
nt?
rPivot workboo
mportant infor
several product
ral tables in dif
well. Learning
nformation you
ligence, and DA
miliar with creat
even if you hav
DAX formulas a
ecifically on un
pts of both calc
familiar with th
irst step throug
alled on your c
X is to create s
nd tasks here u
.microsoft.com
omputer, open
Analysis Servic
arn D
erPivot or tabul
oduction on ho
alytical problem
test what you’
mental concept
ors, and consta
more simply, DA
ok and import
mation withou
t categories an
fferent data sou
how to create e
u need, you can
AX will help yo
ting formulas in
ve no experienc
and solving rea
nderstanding D
ulated column
he PowerPivot
gh the Create Y
computer when
ome basic form
se the Contoso
m/fwlink/?LinkID
it, and then op
es tabular mod
DAX Ba
lar model proje
ow you can use
ms. This topic in
ve learned. Aft
ts in DAX.
nts that can be
AX helps you c
some data into
t using any DA
d for different
urces? DAX for
effective DAX f
n begin to solv
u get there.
n Microsoft Exc
ce with Excel fo
al-world BI prob
DAX formulas u
s and measure
for Excel autho
Your First Powe
n the PowerPivo
mulas, use it wi
o Sample DAX
D=237472&clci
pen the PowerP
del project auth
asics i
ects authored in
e Data Analysis
ncludes concep
er completing
e used in a form
reate new info
o it. You can ev
AX formulas. Bu
date ranges? O
mulas provide
formulas will he
e real business
cel. That knowl
ormulas, the co
blems right awa
sed in calculati
s, both of whic
oring environm
erPivot Workbo
ot for Excel add
th some actual
Formulas.xlsx w
id=0x409. Once
Pivot window.
horing environm
 in 30 
n SQL Server D
Expressions (D
ptual informatio
this topic, you
mula, or expres
rmation from d
ven create Pivot
ut, what if you n
Or, you need co
this capability
elp you get the
s problems that
edge will be he
ncepts describ
ay.
ons. You shoul
ch are described
ment and tools.
ook tutorial incl
d-in is installed
l data, and see
workbook. You
e you have the
ment in SQL Se
 
Data Tools. It is
DAX) to solve a
on, a series of t
should have a
sion, to calcula
data already in
tTables or
need to analyze
ombine importa
and many othe
e most out of y
t affect your bo
elpful in
ed here will he
ld already be fa
d in PowerPivo
If you are new
uded in Power
d.
the results for
can download
e workbook
erver Data Tool
tasks
good
ate
your
e
ant
er
our
ottom
elp
amiliar
ot
to
rPivot
d the
ls
(SSDT), you can import the example workbook by using the Import from PowerPivot template in Visual Studio 2010.
The basic DAX concepts and formulas described here work the same for tabular model projects as they do in
PowerPivot. Only the authoring environment user interface is different. In SSDT, you can test your new formulas by
using the Analyze in Excel feature.
Let’s Begin!
We will frame DAX around three very important fundamental concepts: Syntax, Functions, and Context. Of course,
there are other important concepts in DAX, but understanding these three concepts will provide the best foundation
on which to build your DAX skills.
Syntax
Before you create your own formulas, let’s take a look at DAX formula syntax. Syntax includes the various elements
that make up a formula, or more simply, how the formula is written. For example, let’s look at a simple DAX formula
used to create new data (values) for each row in a calculated column, named Margin, in a FactSales table: (formula
text colors are for illustrative purposes only)
This formula’s syntax includes the following elements:
A. The equals sign operator (=) indicates the beginning of the formula, and when this formula is calculated it
will return a result or value. All formulas that calculate a value will begin with an equals sign.
B. The referenced column [SalesAmount] contains the values we want to subtract from. A column
reference in a formula is always surrounded by brackets []. Unlike Excel formulas which reference a cell, a
DAX formula always references a column.
C. The subtraction (-) mathematical operator.
D. The referenced column [TotalCost] contains the values we want to subtract from values in the
[SalesAmount] column.
When trying to understand how to read a DAX formula, it is often helpful to break down each of the elements into a
language you think and speak every day. For example, you can read this formula as:
In the FactSales table, for each row in the Margin calculated column, calculate (=) a value by subtracting (-) values in
the [TotalCost] column from values in the [SalesAmount] column.
Let’s take a
This formu
A. Th
fo
B. Th
re
C. Th
fu
D. Pa
pa
E. Th
F. Th
kn
You can rea
For the me
FactSales ta
When plac
by each ce
Notice ther
column. In
complex ca
functions la
Unlike the
in which th
preceded b
formula. Th
practice to
Note:
If the name
in single qu
outside the
a look at anoth
la includes the
he measure na
ollowed by a co
he equals sign
eturn a result.
he function SU
unctions later.
arenthesis () s
asses a value to
he referenced t
he referenced c
nows on which
ad this formula
easure named S
able.
ed into the Val
ll in the PivotTa
re are a few thi
particular, we
alculations and
ater.
Margin calcula
he column belo
by the table na
his can make lo
always include
e of a table con
uotation marks
e ANSI alphanu
er type of form
following synt
me Sum of S
olon, followed b
operator (=) in
UM adds up all o
surround one o
o a function.
table FactSal
column [Sale
column to agg
a as:
Sum of Sales Am
ues drop zone
able, for examp
ings different a
introduced a fu
manipulations
ated column ea
ngs. This is kno
me. Columns r
ong formulas th
e the table nam
ntains spaces, r
s. You must also
umeric characte
mula, one that is
tax elements:
Sales Amou
by the calculati
ndicates the be
of the numbers
or more argum
les.
esAmount] in
gregate a SUM
mount, calculat
in a PivotTable
ple, Cell Phones
about this form
unction, SUM. F
s with numbers
rlier, you see th
own as a fully q
eferenced in th
hat reference m
me in your meas
reserved keywo
o enclose table
er range, regard
s used in a mea
unt. Formulas
on formula.
ginning of the
s in the [SalesA
ents. All functio
n the FactSales
.
te (=) the SUM
e Field List, this
s in the USA.
mula compared
Functions are p
s, dates, time, te
he column [Sal
qualified colum
he same table d
many columns s
sure formulas,
ords, or disallow
e names in quo
dless of whethe
asure:
for measures c
calculation for
Amount] column
ons require at
s table. With th
M of values in th
s measure calcu
to the formula
pre-written form
ext, and more.
esAmount] wa
mn name in that
do not require
shorter and eas
even when in t
wed characters,
otation marks if
er your locale s
can include the
rmula. When ca
n. You will learn
least one argum
is argument, th
he [SalesAmoun
ulates and retu
we used for th
mulas that mak
You will learn
s preceded by
t it includes the
the table name
sier to read. Ho
the same table
, you must enc
f the name con
supports the ch
measure name
alculated, it will
n more about
ment. An argum
he SUM functio
nt] column in t
rns values defi
he Margin calcu
ke it easier to d
more about
the table FactS
e column name
e be included in
owever, it is goo
.
lose the table n
tains any chara
haracter set or
e,
ment
on
he
ned
ulated
o
Sales
e
n the
od
name
acters
not.
It is very important your formulas have the correct syntax. In most cases, if the syntax is not correct, a syntax error will
be returned. In other cases, the syntax may be correct, but the values returned might not be what you are expecting.
PowerPivot (and SQL Server Data Tools) includes IntelliSense; a feature used to create syntactically correct formulas by
helping you select the correct elements.
Let’s create a simple formula. This task will help you further understand formula syntax and how the IntelliSense
feature in the formula bar can help you.
Task: Create a simple formula for a calculated column
1. If you are not already in the PowerPivot window, in Excel, on the PowerPivot ribbon, click PowerPivot
Window.
2. In the PowerPivot window, click the FactSales table (tab).
3. Scroll to the right-most column, and then in the column header, click Add Column.
4. Click in the formula bar along the top of the model designer window.
Your cursor now appears in the formula bar. The formula bar is where you can type a formula for a
calculated column or a measure.
Let’s take a moment to look at the three buttons to the left of the formula bar.
When the cursor is active in the formula bar, those three buttons become active. The leftmost button, the X,
is simply a cancel button. Go ahead and click it. Your cursor no longer appears in the formula bar, and the
cancel button and checkmark button no longer appear. Go ahead and click in the formula bar again. The
cancel button and the checkmark button now reappear. This means you are ready to start entering a
formula.
Th
co
C
Fu
fo
ca
5. In
w
Be
co
ca
Yo
6. Ty
7. N
If
ca
Af
bo
th
8. Ri
That’s it! Yo
formula ca
[SalesQuan
in DAX; row
Tip:
Something
arguments
be a text va
formula to
2, DAX read
result is of
based on t
scope of th
Books Onli
Let’s try an
much if you
several elem
Task: Crea
he checkmark b
ome back to it
lick the Fx butt
unction dialog
ormula when w
alculated colum
n the formula b
with all of the co
ecause calculat
olumn name w
an also scroll to
our cursor is no
ype a space, an
ow, type anoth
you get an err
alculated colum
fter you press E
ottom of the P
hree million row
ight click the co
ou just created
lculates a value
ntity] column. N
w context. You w
g really importa
you are using.
alue of “12”. Th
read: Calculate
ds this formula
course “3”, a n
he data type o
his Quick Start.
ne.
nother. This tim
u don’t fully un
ments togethe
ate a measure
button is the ch
in a little bit.
ton. You’ll see t
box is the easie
e create a mea
mn formula. Go
ar, type an equ
olumns in the F
ted columns ar
ith the table na
o the column n
ow active to the
nd then type a
her opening bra
or, look carefu
mn described ea
Enter to compl
owerPivot wind
ws.
olumn header
a simple yet v
e by subtracting
Notice how we
will learn more
ant to understa
. For example, i
his is because t
e a result by tak
a as: Calculate a
numeric value. D
f columns used
To learn more
e, you will crea
nderstand the f
r in correct syn
formula
heck formula b
that a new dial
est way to get
asure a little lat
ahead and clo
uals sign =, the
FactSales table.
e always create
ame. Go ahead
ame you want,
e right of [Sale
subtraction op
acket [. This ti
lly at your synt
arlier.
ete the formula
dow. It goes qu
and rename th
very powerful D
g the value in t
just said “For e
e about row con
nd when typing
if you were to t
he ampersand
king the value
a result by takin
DAX calculates
d in the argume
about data typ
ate a measure b
formula. The im
ntax.
button. It doesn
og box appear
started enterin
er, but for now
ose the Insert F
n type an open
This is IntelliSe
ed in the active
and scroll dow
, and then pres
esQuantity].
erator - (a min
me, select the
tax. If necessary
a, the word Ca
uickly, even tho
e column, Net
DAX formula. Fo
the [ReturnQua
each row”. This
ntext later.
g an operator i
type the follow
(&) operator is
1 as text and a
ng the numeric
resultant value
ent. Data types
pes and operat
by typing the fo
mportant thing
n’t do much un
rs; the Insert Fu
ng a DAX formu
w, you do not n
unction dialog
ning bracket [.
ense in action.
e table you are
wn and then do
ss Tab.
nus sign), and t
[ReturnQuant
y, compare it to
lculating appe
ough you just c
tSales.
or each row in t
antity] column
is a glimpse of
into a DAX form
wing formula, =
s for text conca
dd value 2 as t
c value 1 and ad
es depending o
s in DAX are ve
tors in DAX form
ormula and by
here is to learn
til you’ve enter
unction dialog b
ula. We’ll add a
eed to add a fu
box.
. You’ll see a sm
in, there is no
ouble-click [Sal
then type anoth
tity] column, an
o the formula in
ears in the statu
alculated new
the FactSales ta
from the value
f another very
mula is the dat
1 & 2, the valu
atenation. DAX
text. Now, if yo
dding the num
on the operato
ry important, b
mulas, see the
using IntelliSe
n how to create
red a formula. W
box. The Insert
a function to a
unction to your
mall window ap
need to preced
lesQuantity]. Y
her space.
nd then press E
n the Margin
us bar along th
values for mor
able, the NetSa
in the
important conc
a type in the
ue returned wo
interprets this
u were to type
meric value 2. Th
r in the formula
but outside the
DAX Reference
nse. Don’t wor
e a formula usin
We’ll
r
ppears
de the
You
Enter.
he
e than
ales
cept
ould
= 1 +
he
a, not
e in
ry too
ng
1. In the FactSales table, click in any empty cell in the Calculation Area (also known as the measure grid in the
model designer). This is the area of empty cells just below a table in the PowerPivot window.
2. In the formula bar, type the name Previous Quarter Sales:.
3. Type an equals sign = to begin the calculation formula.
4. Type the first few letters CAL, and then double-click the function you want to use. In this formula, you want
to use the CALCULATE function.
5. Type an opening parenthesis ( to begin the arguments to be passed to the CALCULATE function.
Notice after typing the opening parenthesis, IntelliSense shows you the arguments required for the
CALCULATE function. You will learn about arguments in a little bit.
6. Type the first few letters of the FactSales table, and then in the dropdown list, double-click FactSales[Sales].
7. Type a comma (,) to specify the first filter, then type, PRE, and then double-click the PREVIOUSQUARTER
function.
After selecting the PREVIOUSQUARTER function, another opening parenthesis appears, indicating another
argument is required; this time, for the PREVIOUSQUARTER function.
8. Type the first few letters Dim, and then double-click DimDate[DateKey].
9. Close both the argument being passed to the PREVIOUSQUARTER function and the CALCULATE function by
typing two closing parentheses )).
Your formula should now look like this:
Previous Quarter Sales:=CALCULATE(FactSales[Sales],
PREVIOUSQUARTER(DimDate[DateKey]))
10. C
el
You did it!
the total sa
You were ju
Notice the
can contain
such a form
In this form
an argume
Finally, you
models and
function is
one.
Note:
Typically, in
using the M
the DimDa
Tip:
You may b
have to’. A
model nee
measure yo
functions t
the AutoSu
Extra Cred
1. In the Fa
whole colu
2. On the H
3. Click the
you can us
Immediate
lick the check f
ement of the s
You just create
ales for the pre
ust introduced
PREVIOUSQUA
n up to 64 nest
mula would be
mula, you also u
ent, which is act
u used the CALC
d create more c
outside the sco
n order to use T
Mark as Date Ta
te table is selec
e asking: ‘Wha
nd, that is exac
ds to filter and
ou saw earlier i
hat aggregate
um feature.
dit Task: Create
actSales table,
mn.
Home tab, on t
e down arrow n
e, too).
ly, a new meas
formula button
syntax.
ed a measure u
vious quarter, d
to several imp
ARTER function
ted functions. I
very difficult to
used filters. Filt
tually another f
CULATE functio
complex formu
ope of this Qui
Time Intelligen
able dialog box
cted as the uni
t is the simples
ctly what you ca
calculate on a
s used to add
values as well.
e a measure fo
scroll to the Re
the ribbon, click
next to AutoSu
sure is created w
n on the formul
using DAX, and
depending on
portant aspects
n is nested as a
t is unlikely a fo
o create and de
ers narrow dow
function. You w
on. This is one
ulas, you will lik
ickStart, but as
nce functions in
x. In the Conto
que date colum
st DAX formula
an do by using
ggregated dat
up all the num
You can autom
ormula by usin
eturnQuantity
k the Measure
m, and then cl
with the name
a bar to validat
not an easy on
the filters appl
of DAX formu
n argument pa
ormula would e
ebug, and it pro
wn what will be
will learn more
of the most po
kely use this fun
your knowledg
n DAX formulas
so DAX Formu
mn.
a I can create?’
g a standard ag
a. For example
bers in a partic
matically create
ng the AutoSu
y column, and t
es button.
ick Average (n
Average of
te the formula.
ne at that. Wha
ied in a PivotTa
las. First, this fo
assed to the CA
ever contain so
obably wouldn
e calculated. In
about filters lat
owerful function
nction many tim
ge of DAX grow
s, you must spe
la Samples.xlsx
Well, the answ
gregation func
, the SUM func
cular column. D
e formulas usin
um feature.
then click on th
notice the other
f ReturnQu
. If you get an e
at this formula
able or PivotCh
ormula include
ALCULATE funct
o many nested
n’t be very fast e
this case, you
ter.
ns in DAX. As y
mes. Discussing
ws, pay special
ecify a unique d
x workbook, the
wer to that is ‘th
ction in a meas
ction in the Sum
DAX includes se
g standard agg
he column head
r standard agg
uantity: foll
error, verify eac
will do is calcu
hart.
d two function
tion. DAX form
functions. In fa
either.
selected one fi
you author data
g the CALCULA
attention to th
date column by
e DateKey colu
he formula you
ure. Almost an
m of Sales Amo
everal other
gregations by u
der to select th
regation functi
owed by the
ch
late
s.
mulas
act,
lter as
a
ATE
his
y
umn in
don’t
y data
ount
using
e
ions
formula =AVERAGE([ReturnQuantity]).
Now wasn’t that easy? Of course, not all formulas you create will be so simple. But, by using the AutoSum feature, you
can create quick and easy formulas by using standard aggregation calculations.
This should give you a fairly good understanding of syntax used in DAX formulas. You were also introduced to some
really cool features like IntelliSense and AutoSum to help you create quick, easy, and accurate formulas. Of course
there is a lot more you can learn about syntax. A good place to learn more is the DAX Reference in PowerPivot Help
or SQL Books Online.
Syntax QuickQuiz
1. What does this button on the formula bar do?
2. What always surrounds a column name in a DAX formula?
3. How would you write a formula for the following:
In the DimProduct table, for each row in the UnitMargin calculated column, calculate a value by subtracting
values in the UnitCost column from values in the UnitPrice column?
Answers are provided at the end of this topic.
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:
 A DAX function always references a complete column or a table. If you want to use only particular values
from a table or column, you can add filters to the formula.
 If you need to customize calculations on a row-by-row basis, DAX provides functions that let you use the
current row value or a related value as a kind of argument, to perform calculations that vary by context. You
will learn more about context later.
 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.
 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.
Sometimes it is difficult to know which functions you might need to use in a formula. PowerPivot, and the tabular
model designer in SQL Server Data Tools, include the Insert Function feature, a dialog box that helps you select
functions by category and provides short descriptions for each function.
Let’s create a new formula which includes a function you will select by using the Insert Function feature:
Task: Add a function to a formula by using Insert Function
In the FactSales table, scroll to the right-most column, and then in the column header, click Add Column.
1. In the formula bar, type an equals sign, =.
2. Click the Insert Function button. This opens the Insert Function dialog box.
3. 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.
4. For this formula, you want to return some data that already exists in another table. For that, you are going to
use a function in the Filter category. Go ahead and click the Filter category, and then in Select a function,
scroll down and double-click the RELATED function. Click Ok to close the Insert Function dialog box.
5. Use IntelliSense to help you find and select the DimChannel[ChannelName] column.
6. Close the formula and then press Enter.
7. After you press Enter to complete the formula, the word Calculating appears in the status bar along the
bottom of the PowerPivot window. Now you will see that you just created a new column in the FactSales
table with channel information from the DimChannel table.
8. Rename the column Channel.
Your formula should look like this: =RELATED(DimChannel[ChannelName])
You were just introduced to another very important function in DAX, the RELATED function. The RELATED function
returns values from another table. You can use RELATED provided there is a relationship between the table you are
currently in and the table that contains the values you want to get. Of course, the RELATED function has immense
possibilities. In this case, you can now include the sales channel for each sale in the FactSales table. You can now hide
the DimChannel table from the PivotTable field list, making it easier to navigate and see only the most important
information you really need. Much like the CALCULATE function described earlier, the RELATED function is very
important, and you will likely use it many times.
As you can see, functions in DAX can help you create very powerful formulas. We really only touched on the basics of
functions. As your DAX skills improve, you will create formulas using many different functions. One of the best places
to learn details about all of the DAX functions is in the DAX Function Reference on MSDN.
Functions QuickQuiz
1. What does a function always reference?
2. Can a formula contain more than one function?
3. What category of functions would you use to concatenate two text strings into one string?
Answers are provided at the end of this topic.
Context
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, remember the Margin calculated column you
saw earlier when learning about syntax? 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.
In the selected cell shown below, the value, $49.54 in the current row was calculated by subtracting the value $51.54
in the [TotalCost] column from the value $101.08 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 measures.
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 PivotTables. 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.
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 measures and columns. For
example, let’s look at the following formula in a measure 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.
This formula includes the following syntax elements:
A. The measure name StoreSales, followed by a colon :.
B. The equals sign operator (=) indicates the beginning of the formula.
C. The CALCULATE function evaluates an expression, as an argument, in a context that is modified by the
specified filters.
D. Parenthesis () surround one or more arguments.
E. A measure [Sales] in the same table as an expression. The Sales measure has the formula:
=SUM(FactSales[SalesAmount]).
F. A comma (,) separates each filter.
G. The referenced column and a particular value, DimChannel[ChannelName] =”Store”, as a filter.
This formula will ensure only sales values, defined by the Sales measure, 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.
Context QuickQuiz
1. What are the two types of context?
2. What is filter context?
3. What is row context?
Answers are provided at the end of this topic.
Summary
Now that you have a basic understanding of the most important concepts in DAX, you can begin creating DAX
formulas for calculated columns and measures on your own. DAX can indeed be a little tricky to learn, but there are
many resources available to you. After reading through this topic a few times, and experimenting with a few of your
own formulas, you can learn more about other DAX concepts and formulas that can help you solve your own business
problems. There are many DAX resources available to you in PowerPivot Help, SQL Server Books Online, whitepapers,
and blogs from both Microsoft and leading BI professionals. The DAX Resource Center Wiki at
http://social.technet.microsoft.com/wiki/contents/articles/dax-resource-center.aspx is a great place to start. The Data
Analysis Expressions (DAX) Reference on MSDN is also a great resource. Be sure to save it in your Favorites.
The DAX in the BI Tabular Model whitepaper, available for download at
http://go.microsoft.com/fwlink/?LinkID=237472&clcid=0x409provides a more detailed look at the concepts
introduced here as well as many other advanced concepts and formulas. This whitepaper also uses the same Contoso
DAX Sample Formulas.xlsx workbook you already have.
QuickQuiz Answers
Syntax:
1. Opens the Insert Function feature.
2. Brackets [].
3. =[UnitPrice] - [UnitCost]
Functions:
1. A table and a column.
2. Yes. A formula can contain up to 64 nested functions.
3. Text.
Context:
1. Row context and filter context.
2. One or more filters in a calculation that determines a single value.
3. The current row.
 

More Related Content

What's hot

Mdx Basics
Mdx BasicsMdx Basics
Mdx BasicsALIPPHAR
 
Pass 2018 introduction to dax
Pass 2018 introduction to daxPass 2018 introduction to dax
Pass 2018 introduction to daxIke Ellis
 
Olap Functions Suport in Informix
Olap Functions Suport in InformixOlap Functions Suport in Informix
Olap Functions Suport in InformixBingjie Miao
 
Effective Visualization with Tableau
Effective Visualization with TableauEffective Visualization with Tableau
Effective Visualization with TableauGirija Muscut
 
DATA SCIENCE TRAINING IN HYDERABAD
DATA SCIENCE TRAINING IN HYDERABADDATA SCIENCE TRAINING IN HYDERABAD
DATA SCIENCE TRAINING IN HYDERABADRS Trainings
 
Fact table design for data ware house
Fact table design for data ware houseFact table design for data ware house
Fact table design for data ware houseSayed Ahmed
 
$5 COUPON LINK - Excel Udemy Course: Excel with Excel Dynamic Graphs, Dashboa...
$5 COUPON LINK - Excel Udemy Course: Excel with Excel Dynamic Graphs, Dashboa...$5 COUPON LINK - Excel Udemy Course: Excel with Excel Dynamic Graphs, Dashboa...
$5 COUPON LINK - Excel Udemy Course: Excel with Excel Dynamic Graphs, Dashboa...mellontraining
 
Analysis Services en SQL Server 2008
Analysis Services en SQL Server 2008Analysis Services en SQL Server 2008
Analysis Services en SQL Server 2008Eduardo Castro
 
Dimensional data modeling
Dimensional data modelingDimensional data modeling
Dimensional data modelingAdam Hutson
 
MSBI and Data WareHouse techniques by Quontra
MSBI and Data WareHouse techniques by Quontra MSBI and Data WareHouse techniques by Quontra
MSBI and Data WareHouse techniques by Quontra QUONTRASOLUTIONS
 

What's hot (19)

Mdx Basics
Mdx BasicsMdx Basics
Mdx Basics
 
Pass 2018 introduction to dax
Pass 2018 introduction to daxPass 2018 introduction to dax
Pass 2018 introduction to dax
 
Excel 2007 Unit G
Excel 2007 Unit GExcel 2007 Unit G
Excel 2007 Unit G
 
Excel 2007 Unit J
Excel 2007 Unit JExcel 2007 Unit J
Excel 2007 Unit J
 
Hyperion Planning Overview
Hyperion Planning OverviewHyperion Planning Overview
Hyperion Planning Overview
 
Olap Functions Suport in Informix
Olap Functions Suport in InformixOlap Functions Suport in Informix
Olap Functions Suport in Informix
 
Effective Visualization with Tableau
Effective Visualization with TableauEffective Visualization with Tableau
Effective Visualization with Tableau
 
Excel 2007 Unit L
Excel 2007 Unit LExcel 2007 Unit L
Excel 2007 Unit L
 
DATA SCIENCE TRAINING IN HYDERABAD
DATA SCIENCE TRAINING IN HYDERABADDATA SCIENCE TRAINING IN HYDERABAD
DATA SCIENCE TRAINING IN HYDERABAD
 
Excel.t04
Excel.t04Excel.t04
Excel.t04
 
Fact table design for data ware house
Fact table design for data ware houseFact table design for data ware house
Fact table design for data ware house
 
$5 COUPON LINK - Excel Udemy Course: Excel with Excel Dynamic Graphs, Dashboa...
$5 COUPON LINK - Excel Udemy Course: Excel with Excel Dynamic Graphs, Dashboa...$5 COUPON LINK - Excel Udemy Course: Excel with Excel Dynamic Graphs, Dashboa...
$5 COUPON LINK - Excel Udemy Course: Excel with Excel Dynamic Graphs, Dashboa...
 
MULTIMEDIA MODELING
MULTIMEDIA MODELINGMULTIMEDIA MODELING
MULTIMEDIA MODELING
 
Tableau data types
Tableau   data typesTableau   data types
Tableau data types
 
Analysis Services en SQL Server 2008
Analysis Services en SQL Server 2008Analysis Services en SQL Server 2008
Analysis Services en SQL Server 2008
 
Excel 2007 Unit K
Excel 2007 Unit KExcel 2007 Unit K
Excel 2007 Unit K
 
Dimensional data modeling
Dimensional data modelingDimensional data modeling
Dimensional data modeling
 
MSBI and Data WareHouse techniques by Quontra
MSBI and Data WareHouse techniques by Quontra MSBI and Data WareHouse techniques by Quontra
MSBI and Data WareHouse techniques by Quontra
 
SQLDay2013_ChrisWebb_DAXMD
SQLDay2013_ChrisWebb_DAXMDSQLDay2013_ChrisWebb_DAXMD
SQLDay2013_ChrisWebb_DAXMD
 

Viewers also liked

Introduction to DAX - Part 1
Introduction to DAX - Part 1Introduction to DAX - Part 1
Introduction to DAX - Part 1Alan Koo
 
PowerPivot and Excel in Office 2013
PowerPivot and Excel in Office 2013PowerPivot and Excel in Office 2013
PowerPivot and Excel in Office 2013Jen Stirrup
 
DAX for dummies / DAX pour les NULS !
DAX for dummies / DAX pour les NULS !DAX for dummies / DAX pour les NULS !
DAX for dummies / DAX pour les NULS !Microsoft
 
spiritual-warfare-the-invisible-invasion-tom-horn
 spiritual-warfare-the-invisible-invasion-tom-horn spiritual-warfare-the-invisible-invasion-tom-horn
spiritual-warfare-the-invisible-invasion-tom-hornKaturi Susmitha
 
Mantic Point at e-volve Barcelona
Mantic Point at e-volve BarcelonaMantic Point at e-volve Barcelona
Mantic Point at e-volve BarcelonaMike Atherton
 
IP and Media In The Digital Age
IP and Media In The Digital AgeIP and Media In The Digital Age
IP and Media In The Digital AgeCeline77
 
Optimización costes y eficiencia utilizando Lean
Optimización costes y eficiencia utilizando LeanOptimización costes y eficiencia utilizando Lean
Optimización costes y eficiencia utilizando LeanIñaki González Rodríguez
 
Giant Step - Engaging Audiences Online
Giant Step - Engaging Audiences OnlineGiant Step - Engaging Audiences Online
Giant Step - Engaging Audiences Onlinegiantstep
 
Grupo CGI. Colaboración Tributaria. Presentación de empresa - 2015
Grupo CGI. Colaboración Tributaria. Presentación de empresa - 2015Grupo CGI. Colaboración Tributaria. Presentación de empresa - 2015
Grupo CGI. Colaboración Tributaria. Presentación de empresa - 2015Grupo CGI - Colaboración Tributaria
 
Telefonos Interes FormacióN Privada
Telefonos Interes FormacióN PrivadaTelefonos Interes FormacióN Privada
Telefonos Interes FormacióN Privadarafael
 
Avances sistemas informáticos
Avances sistemas informáticosAvances sistemas informáticos
Avances sistemas informáticosDavid Gallardo
 

Viewers also liked (20)

Introduction to DAX - Part 1
Introduction to DAX - Part 1Introduction to DAX - Part 1
Introduction to DAX - Part 1
 
PowerPivot and Excel in Office 2013
PowerPivot and Excel in Office 2013PowerPivot and Excel in Office 2013
PowerPivot and Excel in Office 2013
 
DAX for dummies / DAX pour les NULS !
DAX for dummies / DAX pour les NULS !DAX for dummies / DAX pour les NULS !
DAX for dummies / DAX pour les NULS !
 
1922.2.17 2 3 cante jondo granada
1922.2.17 2 3 cante jondo granada1922.2.17 2 3 cante jondo granada
1922.2.17 2 3 cante jondo granada
 
Infor logistica v.z.z.
Infor logistica v.z.z.Infor logistica v.z.z.
Infor logistica v.z.z.
 
spiritual-warfare-the-invisible-invasion-tom-horn
 spiritual-warfare-the-invisible-invasion-tom-horn spiritual-warfare-the-invisible-invasion-tom-horn
spiritual-warfare-the-invisible-invasion-tom-horn
 
Hochschule - Strukturen, Rahmen und Modelle für die Lehre mit Technologien
Hochschule - Strukturen, Rahmen und Modelle für die Lehre mit TechnologienHochschule - Strukturen, Rahmen und Modelle für die Lehre mit Technologien
Hochschule - Strukturen, Rahmen und Modelle für die Lehre mit Technologien
 
Mantic Point at e-volve Barcelona
Mantic Point at e-volve BarcelonaMantic Point at e-volve Barcelona
Mantic Point at e-volve Barcelona
 
IP and Media In The Digital Age
IP and Media In The Digital AgeIP and Media In The Digital Age
IP and Media In The Digital Age
 
Optimización costes y eficiencia utilizando Lean
Optimización costes y eficiencia utilizando LeanOptimización costes y eficiencia utilizando Lean
Optimización costes y eficiencia utilizando Lean
 
H30 imi health ag pro (2)
H30 imi health ag pro (2)H30 imi health ag pro (2)
H30 imi health ag pro (2)
 
7 email marketing refreshes
7 email marketing refreshes7 email marketing refreshes
7 email marketing refreshes
 
Optix company profile
Optix company profileOptix company profile
Optix company profile
 
Giant Step - Engaging Audiences Online
Giant Step - Engaging Audiences OnlineGiant Step - Engaging Audiences Online
Giant Step - Engaging Audiences Online
 
Grupo CGI. Colaboración Tributaria. Presentación de empresa - 2015
Grupo CGI. Colaboración Tributaria. Presentación de empresa - 2015Grupo CGI. Colaboración Tributaria. Presentación de empresa - 2015
Grupo CGI. Colaboración Tributaria. Presentación de empresa - 2015
 
Tenis jdf
Tenis jdfTenis jdf
Tenis jdf
 
E miracle
E miracleE miracle
E miracle
 
Telefonos Interes FormacióN Privada
Telefonos Interes FormacióN PrivadaTelefonos Interes FormacióN Privada
Telefonos Interes FormacióN Privada
 
CR consultation socle Strasbourg
CR consultation socle StrasbourgCR consultation socle Strasbourg
CR consultation socle Strasbourg
 
Avances sistemas informáticos
Avances sistemas informáticosAvances sistemas informáticos
Avances sistemas informáticos
 

Similar to Quick start learn dax basics in 30 minutes

Funções DAX.pdf
Funções DAX.pdfFunções DAX.pdf
Funções DAX.pdfJoao Vaz
 
Top 20 microsoft excel formulas you must know
Top 20 microsoft excel formulas you must knowTop 20 microsoft excel formulas you must know
Top 20 microsoft excel formulas you must knowAlexHenderson59
 
Model Assistant Suite
Model Assistant SuiteModel Assistant Suite
Model Assistant SuiteYsrael Mertz
 
Windows, MS office.pptx
Windows, MS office.pptxWindows, MS office.pptx
Windows, MS office.pptxNeena Naidu
 
Windows, MS office.pptx
Windows, MS office.pptxWindows, MS office.pptx
Windows, MS office.pptxNeena Naidu
 
ADVANCED EXCEL COURSE IN LAXMI NAGAR
ADVANCED EXCEL COURSE IN LAXMI NAGARADVANCED EXCEL COURSE IN LAXMI NAGAR
ADVANCED EXCEL COURSE IN LAXMI NAGARRajatSharma210839
 
Fact table design for data ware house
Fact table design for data ware houseFact table design for data ware house
Fact table design for data ware houseSayed Ahmed
 
ISOT Presentation.pptx
ISOT Presentation.pptxISOT Presentation.pptx
ISOT Presentation.pptxsirtBhopal1
 
E-Book 25 Tips and Tricks MS Excel Functions & Formulaes
E-Book 25 Tips and Tricks MS Excel Functions & FormulaesE-Book 25 Tips and Tricks MS Excel Functions & Formulaes
E-Book 25 Tips and Tricks MS Excel Functions & FormulaesBurCom Consulting Ltd.
 
Base sas interview questions
Base sas interview questionsBase sas interview questions
Base sas interview questionsDr P Deepak
 
Spreadsheet nina
Spreadsheet ninaSpreadsheet nina
Spreadsheet ninaNinaAnzaldo
 

Similar to Quick start learn dax basics in 30 minutes (20)

Funções DAX.pdf
Funções DAX.pdfFunções DAX.pdf
Funções DAX.pdf
 
Getting power bi
Getting power biGetting power bi
Getting power bi
 
maple project.pptx
maple project.pptxmaple project.pptx
maple project.pptx
 
Top 20 microsoft excel formulas you must know
Top 20 microsoft excel formulas you must knowTop 20 microsoft excel formulas you must know
Top 20 microsoft excel formulas you must know
 
Model Assistant Suite
Model Assistant SuiteModel Assistant Suite
Model Assistant Suite
 
Windows, MS office.pptx
Windows, MS office.pptxWindows, MS office.pptx
Windows, MS office.pptx
 
Windows, MS office.pptx
Windows, MS office.pptxWindows, MS office.pptx
Windows, MS office.pptx
 
Basic matlab for beginners
Basic matlab for beginnersBasic matlab for beginners
Basic matlab for beginners
 
ADVANCED EXCEL COURSE IN LAXMI NAGAR
ADVANCED EXCEL COURSE IN LAXMI NAGARADVANCED EXCEL COURSE IN LAXMI NAGAR
ADVANCED EXCEL COURSE IN LAXMI NAGAR
 
Vba primer
Vba primerVba primer
Vba primer
 
Fact table design for data ware house
Fact table design for data ware houseFact table design for data ware house
Fact table design for data ware house
 
ISOT Presentation.pptx
ISOT Presentation.pptxISOT Presentation.pptx
ISOT Presentation.pptx
 
Excel intermediate
Excel intermediateExcel intermediate
Excel intermediate
 
E-Book 25 Tips and Tricks MS Excel Functions & Formulaes
E-Book 25 Tips and Tricks MS Excel Functions & FormulaesE-Book 25 Tips and Tricks MS Excel Functions & Formulaes
E-Book 25 Tips and Tricks MS Excel Functions & Formulaes
 
Automating SolidWorks with Excel
Automating SolidWorks with ExcelAutomating SolidWorks with Excel
Automating SolidWorks with Excel
 
Base sas interview questions
Base sas interview questionsBase sas interview questions
Base sas interview questions
 
Spreadsheet nina
Spreadsheet ninaSpreadsheet nina
Spreadsheet nina
 
22_presentation.ppt
22_presentation.ppt22_presentation.ppt
22_presentation.ppt
 
Excel tips and tricks you should try
Excel tips and tricks you should tryExcel tips and tricks you should try
Excel tips and tricks you should try
 
A excel analysis toolpack -best
A excel analysis toolpack -bestA excel analysis toolpack -best
A excel analysis toolpack -best
 

More from Компания Робот Икс

Microsoft sql server analysis services multidimensional performance and opera...
Microsoft sql server analysis services multidimensional performance and opera...Microsoft sql server analysis services multidimensional performance and opera...
Microsoft sql server analysis services multidimensional performance and opera...Компания Робот Икс
 
Deployment guide for Microsoft Office 2010 for IT professionals.
Deployment guide for Microsoft Office 2010 for IT professionals.Deployment guide for Microsoft Office 2010 for IT professionals.
Deployment guide for Microsoft Office 2010 for IT professionals.Компания Робот Икс
 
Microsoft SQL Server always on solutions guide for high availability and dis...
Microsoft  SQL Server always on solutions guide for high availability and dis...Microsoft  SQL Server always on solutions guide for high availability and dis...
Microsoft SQL Server always on solutions guide for high availability and dis...Компания Робот Икс
 
Руководство по эксплуатации для Microsoft Office 2010 (для ИТ-специалистов)
Руководство по эксплуатации для Microsoft Office 2010 (для ИТ-специалистов)Руководство по эксплуатации для Microsoft Office 2010 (для ИТ-специалистов)
Руководство по эксплуатации для Microsoft Office 2010 (для ИТ-специалистов)Компания Робот Икс
 
Руководство по SQL Server 2012: Многомерное моделирование шаг за шагом.
Руководство по SQL Server 2012: Многомерное моделирование шаг за шагом.Руководство по SQL Server 2012: Многомерное моделирование шаг за шагом.
Руководство по SQL Server 2012: Многомерное моделирование шаг за шагом.Компания Робот Икс
 
Windows8 для малого и среднего бизнеса
Windows8 для малого и среднего бизнесаWindows8 для малого и среднего бизнеса
Windows8 для малого и среднего бизнесаКомпания Робот Икс
 

More from Компания Робот Икс (15)

Microsoft sql server analysis services multidimensional performance and opera...
Microsoft sql server analysis services multidimensional performance and opera...Microsoft sql server analysis services multidimensional performance and opera...
Microsoft sql server analysis services multidimensional performance and opera...
 
Myths about adobe creative cloud
Myths about adobe creative cloudMyths about adobe creative cloud
Myths about adobe creative cloud
 
Office exchange 2013
Office exchange 2013Office exchange 2013
Office exchange 2013
 
Deployment guide for Microsoft Office 2010 for IT professionals.
Deployment guide for Microsoft Office 2010 for IT professionals.Deployment guide for Microsoft Office 2010 for IT professionals.
Deployment guide for Microsoft Office 2010 for IT professionals.
 
Microsoft SQL Server always on solutions guide for high availability and dis...
Microsoft  SQL Server always on solutions guide for high availability and dis...Microsoft  SQL Server always on solutions guide for high availability and dis...
Microsoft SQL Server always on solutions guide for high availability and dis...
 
Руководство по эксплуатации для Microsoft Office 2010 (для ИТ-специалистов)
Руководство по эксплуатации для Microsoft Office 2010 (для ИТ-специалистов)Руководство по эксплуатации для Microsoft Office 2010 (для ИТ-специалистов)
Руководство по эксплуатации для Microsoft Office 2010 (для ИТ-специалистов)
 
Руководство по SQL Server 2012: Многомерное моделирование шаг за шагом.
Руководство по SQL Server 2012: Многомерное моделирование шаг за шагом.Руководство по SQL Server 2012: Многомерное моделирование шаг за шагом.
Руководство по SQL Server 2012: Многомерное моделирование шаг за шагом.
 
Гид по работе с Pinpoint
Гид по работе с Pinpoint Гид по работе с Pinpoint
Гид по работе с Pinpoint
 
Sql server 2012 tutorials analysis services tabular modeling
Sql server 2012 tutorials   analysis services tabular modelingSql server 2012 tutorials   analysis services tabular modeling
Sql server 2012 tutorials analysis services tabular modeling
 
Office exchange 2013
Office exchange 2013Office exchange 2013
Office exchange 2013
 
Windows intune
Windows intuneWindows intune
Windows intune
 
Windows Azure.Возможности для бизнеса
Windows Azure.Возможности для бизнесаWindows Azure.Возможности для бизнеса
Windows Azure.Возможности для бизнеса
 
Windows8 для малого и среднего бизнеса
Windows8 для малого и среднего бизнесаWindows8 для малого и среднего бизнеса
Windows8 для малого и среднего бизнеса
 
Новые возможности Office 365
Новые возможности Office 365Новые возможности Office 365
Новые возможности Office 365
 
Office 365
Office 365Office 365
Office 365
 

Recently uploaded

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 

Quick start learn dax basics in 30 minutes

  • 1.
  • 2. QuickStart: Learn DAX Basics in 30 Minutes Owen Duncan Summary: This QuickStart is for users new to PowerPivot or tabular model projects authored in SQL Server Data Tools. It is meant to give you a quick and easy introduction on how you can use Data Analysis Expressions (DAX) to solve a number of basic data modeling and analytical problems. Category: Quick Step-By-Step Applies to: PowerPivot for Excel (all versions), SQL Server 2008 R2, SQL Server 2012 Source: TechNet Wiki (link to source content) E-book publication date: May 2012 13 pages
  • 3. Copyright © 2012 by Microsoft Corporation All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. Microsoft and the trademarks listed at http://www.microsoft.com/about/legal/en/us/IntellectualProperty/Trademarks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property of their respective owners. The example companies, organizations, products, domain names, email addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book.
  • 4. Quic Min This QuickS meant to g number of you can co understand What is DA DAX is a co and return model. Why is DA It’s easy to PivotCharts critical sale inventory d important c data. When line. This is Prereq You might understand you get sta We are goi with funda Help. You s PowerPivot help, which Example W The best w yourself. Th workbook downloade Note: If you are w ckStar utes  Start is for user give you a quick basic data mo omplete, and a ding of the mo AX? ollection of fun one or more v AX so importan create a Powe s that display im es data across s data from sever capabilities as w n you get the in s Business Intel uisites already be fam ding DAX, but e arted creating D ing to focus sp mental concep should also be t, you should fi h is usually inst Workbook way to learn DAX he examples an from http://go ed onto your co working in the A rt: Lea   rs new to Powe k and easy intro deling and ana few quizzes to st basic fundam ctions, operato values. Stated m nt? rPivot workboo mportant infor several product ral tables in dif well. Learning nformation you ligence, and DA miliar with creat even if you hav DAX formulas a ecifically on un pts of both calc familiar with th irst step throug alled on your c X is to create s nd tasks here u .microsoft.com omputer, open Analysis Servic arn D erPivot or tabul oduction on ho alytical problem test what you’ mental concept ors, and consta more simply, DA ok and import mation withou t categories an fferent data sou how to create e u need, you can AX will help yo ting formulas in ve no experienc and solving rea nderstanding D ulated column he PowerPivot gh the Create Y computer when ome basic form se the Contoso m/fwlink/?LinkID it, and then op es tabular mod DAX Ba lar model proje ow you can use ms. This topic in ve learned. Aft ts in DAX. nts that can be AX helps you c some data into t using any DA d for different urces? DAX for effective DAX f n begin to solv u get there. n Microsoft Exc ce with Excel fo al-world BI prob DAX formulas u s and measure for Excel autho Your First Powe n the PowerPivo mulas, use it wi o Sample DAX D=237472&clci pen the PowerP del project auth asics i ects authored in e Data Analysis ncludes concep er completing e used in a form reate new info o it. You can ev AX formulas. Bu date ranges? O mulas provide formulas will he e real business cel. That knowl ormulas, the co blems right awa sed in calculati s, both of whic oring environm erPivot Workbo ot for Excel add th some actual Formulas.xlsx w id=0x409. Once Pivot window. horing environm  in 30  n SQL Server D Expressions (D ptual informatio this topic, you mula, or expres rmation from d ven create Pivot ut, what if you n Or, you need co this capability elp you get the s problems that edge will be he ncepts describ ay. ons. You shoul ch are described ment and tools. ook tutorial incl d-in is installed l data, and see workbook. You e you have the ment in SQL Se   Data Tools. It is DAX) to solve a on, a series of t should have a sion, to calcula data already in tTables or need to analyze ombine importa and many othe e most out of y t affect your bo elpful in ed here will he ld already be fa d in PowerPivo If you are new uded in Power d. the results for can download e workbook erver Data Tool tasks good ate your e ant er our ottom elp amiliar ot to rPivot d the ls
  • 5. (SSDT), you can import the example workbook by using the Import from PowerPivot template in Visual Studio 2010. The basic DAX concepts and formulas described here work the same for tabular model projects as they do in PowerPivot. Only the authoring environment user interface is different. In SSDT, you can test your new formulas by using the Analyze in Excel feature. Let’s Begin! We will frame DAX around three very important fundamental concepts: Syntax, Functions, and Context. Of course, there are other important concepts in DAX, but understanding these three concepts will provide the best foundation on which to build your DAX skills. Syntax Before you create your own formulas, let’s take a look at DAX formula syntax. Syntax includes the various elements that make up a formula, or more simply, how the formula is written. For example, let’s look at a simple DAX formula used to create new data (values) for each row in a calculated column, named Margin, in a FactSales table: (formula text colors are for illustrative purposes only) This formula’s syntax includes the following elements: A. The equals sign operator (=) indicates the beginning of the formula, and when this formula is calculated it will return a result or value. All formulas that calculate a value will begin with an equals sign. B. The referenced column [SalesAmount] contains the values we want to subtract from. A column reference in a formula is always surrounded by brackets []. Unlike Excel formulas which reference a cell, a DAX formula always references a column. C. The subtraction (-) mathematical operator. D. The referenced column [TotalCost] contains the values we want to subtract from values in the [SalesAmount] column. When trying to understand how to read a DAX formula, it is often helpful to break down each of the elements into a language you think and speak every day. For example, you can read this formula as: In the FactSales table, for each row in the Margin calculated column, calculate (=) a value by subtracting (-) values in the [TotalCost] column from values in the [SalesAmount] column.
  • 6. Let’s take a This formu A. Th fo B. Th re C. Th fu D. Pa pa E. Th F. Th kn You can rea For the me FactSales ta When plac by each ce Notice ther column. In complex ca functions la Unlike the in which th preceded b formula. Th practice to Note: If the name in single qu outside the a look at anoth la includes the he measure na ollowed by a co he equals sign eturn a result. he function SU unctions later. arenthesis () s asses a value to he referenced t he referenced c nows on which ad this formula easure named S able. ed into the Val ll in the PivotTa re are a few thi particular, we alculations and ater. Margin calcula he column belo by the table na his can make lo always include e of a table con uotation marks e ANSI alphanu er type of form following synt me Sum of S olon, followed b operator (=) in UM adds up all o surround one o o a function. table FactSal column [Sale column to agg a as: Sum of Sales Am ues drop zone able, for examp ings different a introduced a fu manipulations ated column ea ngs. This is kno me. Columns r ong formulas th e the table nam ntains spaces, r s. You must also umeric characte mula, one that is tax elements: Sales Amou by the calculati ndicates the be of the numbers or more argum les. esAmount] in gregate a SUM mount, calculat in a PivotTable ple, Cell Phones about this form unction, SUM. F s with numbers rlier, you see th own as a fully q eferenced in th hat reference m me in your meas reserved keywo o enclose table er range, regard s used in a mea unt. Formulas on formula. ginning of the s in the [SalesA ents. All functio n the FactSales . te (=) the SUM e Field List, this s in the USA. mula compared Functions are p s, dates, time, te he column [Sal qualified colum he same table d many columns s sure formulas, ords, or disallow e names in quo dless of whethe asure: for measures c calculation for Amount] column ons require at s table. With th M of values in th s measure calcu to the formula pre-written form ext, and more. esAmount] wa mn name in that do not require shorter and eas even when in t wed characters, otation marks if er your locale s can include the rmula. When ca n. You will learn least one argum is argument, th he [SalesAmoun ulates and retu we used for th mulas that mak You will learn s preceded by t it includes the the table name sier to read. Ho the same table , you must enc f the name con supports the ch measure name alculated, it will n more about ment. An argum he SUM functio nt] column in t rns values defi he Margin calcu ke it easier to d more about the table FactS e column name e be included in owever, it is goo . lose the table n tains any chara haracter set or e, ment on he ned ulated o Sales e n the od name acters not.
  • 7. It is very important your formulas have the correct syntax. In most cases, if the syntax is not correct, a syntax error will be returned. In other cases, the syntax may be correct, but the values returned might not be what you are expecting. PowerPivot (and SQL Server Data Tools) includes IntelliSense; a feature used to create syntactically correct formulas by helping you select the correct elements. Let’s create a simple formula. This task will help you further understand formula syntax and how the IntelliSense feature in the formula bar can help you. Task: Create a simple formula for a calculated column 1. If you are not already in the PowerPivot window, in Excel, on the PowerPivot ribbon, click PowerPivot Window. 2. In the PowerPivot window, click the FactSales table (tab). 3. Scroll to the right-most column, and then in the column header, click Add Column. 4. Click in the formula bar along the top of the model designer window. Your cursor now appears in the formula bar. The formula bar is where you can type a formula for a calculated column or a measure. Let’s take a moment to look at the three buttons to the left of the formula bar. When the cursor is active in the formula bar, those three buttons become active. The leftmost button, the X, is simply a cancel button. Go ahead and click it. Your cursor no longer appears in the formula bar, and the cancel button and checkmark button no longer appear. Go ahead and click in the formula bar again. The cancel button and the checkmark button now reappear. This means you are ready to start entering a formula.
  • 8. Th co C Fu fo ca 5. In w Be co ca Yo 6. Ty 7. N If ca Af bo th 8. Ri That’s it! Yo formula ca [SalesQuan in DAX; row Tip: Something arguments be a text va formula to 2, DAX read result is of based on t scope of th Books Onli Let’s try an much if you several elem Task: Crea he checkmark b ome back to it lick the Fx butt unction dialog ormula when w alculated colum n the formula b with all of the co ecause calculat olumn name w an also scroll to our cursor is no ype a space, an ow, type anoth you get an err alculated colum fter you press E ottom of the P hree million row ight click the co ou just created lculates a value ntity] column. N w context. You w g really importa you are using. alue of “12”. Th read: Calculate ds this formula course “3”, a n he data type o his Quick Start. ne. nother. This tim u don’t fully un ments togethe ate a measure button is the ch in a little bit. ton. You’ll see t box is the easie e create a mea mn formula. Go ar, type an equ olumns in the F ted columns ar ith the table na o the column n ow active to the nd then type a her opening bra or, look carefu mn described ea Enter to compl owerPivot wind ws. olumn header a simple yet v e by subtracting Notice how we will learn more ant to understa . For example, i his is because t e a result by tak a as: Calculate a numeric value. D f columns used To learn more e, you will crea nderstand the f r in correct syn formula heck formula b that a new dial est way to get asure a little lat ahead and clo uals sign =, the FactSales table. e always create ame. Go ahead ame you want, e right of [Sale subtraction op acket [. This ti lly at your synt arlier. ete the formula dow. It goes qu and rename th very powerful D g the value in t just said “For e e about row con nd when typing if you were to t he ampersand king the value a result by takin DAX calculates d in the argume about data typ ate a measure b formula. The im ntax. button. It doesn og box appear started enterin er, but for now ose the Insert F n type an open This is IntelliSe ed in the active and scroll dow , and then pres esQuantity]. erator - (a min me, select the tax. If necessary a, the word Ca uickly, even tho e column, Net DAX formula. Fo the [ReturnQua each row”. This ntext later. g an operator i type the follow (&) operator is 1 as text and a ng the numeric resultant value ent. Data types pes and operat by typing the fo mportant thing n’t do much un rs; the Insert Fu ng a DAX formu w, you do not n unction dialog ning bracket [. ense in action. e table you are wn and then do ss Tab. nus sign), and t [ReturnQuant y, compare it to lculating appe ough you just c tSales. or each row in t antity] column is a glimpse of into a DAX form wing formula, = s for text conca dd value 2 as t c value 1 and ad es depending o s in DAX are ve tors in DAX form ormula and by here is to learn til you’ve enter unction dialog b ula. We’ll add a eed to add a fu box. . You’ll see a sm in, there is no ouble-click [Sal then type anoth tity] column, an o the formula in ears in the statu alculated new the FactSales ta from the value f another very mula is the dat 1 & 2, the valu atenation. DAX text. Now, if yo dding the num on the operato ry important, b mulas, see the using IntelliSe n how to create red a formula. W box. The Insert a function to a unction to your mall window ap need to preced lesQuantity]. Y her space. nd then press E n the Margin us bar along th values for mor able, the NetSa in the important conc a type in the ue returned wo interprets this u were to type meric value 2. Th r in the formula but outside the DAX Reference nse. Don’t wor e a formula usin We’ll r ppears de the You Enter. he e than ales cept ould = 1 + he a, not e in ry too ng
  • 9. 1. In the FactSales table, click in any empty cell in the Calculation Area (also known as the measure grid in the model designer). This is the area of empty cells just below a table in the PowerPivot window. 2. In the formula bar, type the name Previous Quarter Sales:. 3. Type an equals sign = to begin the calculation formula. 4. Type the first few letters CAL, and then double-click the function you want to use. In this formula, you want to use the CALCULATE function. 5. Type an opening parenthesis ( to begin the arguments to be passed to the CALCULATE function. Notice after typing the opening parenthesis, IntelliSense shows you the arguments required for the CALCULATE function. You will learn about arguments in a little bit. 6. Type the first few letters of the FactSales table, and then in the dropdown list, double-click FactSales[Sales]. 7. Type a comma (,) to specify the first filter, then type, PRE, and then double-click the PREVIOUSQUARTER function. After selecting the PREVIOUSQUARTER function, another opening parenthesis appears, indicating another argument is required; this time, for the PREVIOUSQUARTER function. 8. Type the first few letters Dim, and then double-click DimDate[DateKey]. 9. Close both the argument being passed to the PREVIOUSQUARTER function and the CALCULATE function by typing two closing parentheses )). Your formula should now look like this: Previous Quarter Sales:=CALCULATE(FactSales[Sales], PREVIOUSQUARTER(DimDate[DateKey]))
  • 10. 10. C el You did it! the total sa You were ju Notice the can contain such a form In this form an argume Finally, you models and function is one. Note: Typically, in using the M the DimDa Tip: You may b have to’. A model nee measure yo functions t the AutoSu Extra Cred 1. In the Fa whole colu 2. On the H 3. Click the you can us Immediate lick the check f ement of the s You just create ales for the pre ust introduced PREVIOUSQUA n up to 64 nest mula would be mula, you also u ent, which is act u used the CALC d create more c outside the sco n order to use T Mark as Date Ta te table is selec e asking: ‘Wha nd, that is exac ds to filter and ou saw earlier i hat aggregate um feature. dit Task: Create actSales table, mn. Home tab, on t e down arrow n e, too). ly, a new meas formula button syntax. ed a measure u vious quarter, d to several imp ARTER function ted functions. I very difficult to used filters. Filt tually another f CULATE functio complex formu ope of this Qui Time Intelligen able dialog box cted as the uni t is the simples ctly what you ca calculate on a s used to add values as well. e a measure fo scroll to the Re the ribbon, click next to AutoSu sure is created w n on the formul using DAX, and depending on portant aspects n is nested as a t is unlikely a fo o create and de ers narrow dow function. You w on. This is one ulas, you will lik ickStart, but as nce functions in x. In the Conto que date colum st DAX formula an do by using ggregated dat up all the num You can autom ormula by usin eturnQuantity k the Measure m, and then cl with the name a bar to validat not an easy on the filters appl of DAX formu n argument pa ormula would e ebug, and it pro wn what will be will learn more of the most po kely use this fun your knowledg n DAX formulas so DAX Formu mn. a I can create?’ g a standard ag a. For example bers in a partic matically create ng the AutoSu y column, and t es button. ick Average (n Average of te the formula. ne at that. Wha ied in a PivotTa las. First, this fo assed to the CA ever contain so obably wouldn e calculated. In about filters lat owerful function nction many tim ge of DAX grow s, you must spe la Samples.xlsx Well, the answ gregation func , the SUM func cular column. D e formulas usin um feature. then click on th notice the other f ReturnQu . If you get an e at this formula able or PivotCh ormula include ALCULATE funct o many nested n’t be very fast e this case, you ter. ns in DAX. As y mes. Discussing ws, pay special ecify a unique d x workbook, the wer to that is ‘th ction in a meas ction in the Sum DAX includes se g standard agg he column head r standard agg uantity: foll error, verify eac will do is calcu hart. d two function tion. DAX form functions. In fa either. selected one fi you author data g the CALCULA attention to th date column by e DateKey colu he formula you ure. Almost an m of Sales Amo everal other gregations by u der to select th regation functi owed by the ch late s. mulas act, lter as a ATE his y umn in don’t y data ount using e ions
  • 11. formula =AVERAGE([ReturnQuantity]). Now wasn’t that easy? Of course, not all formulas you create will be so simple. But, by using the AutoSum feature, you can create quick and easy formulas by using standard aggregation calculations. This should give you a fairly good understanding of syntax used in DAX formulas. You were also introduced to some really cool features like IntelliSense and AutoSum to help you create quick, easy, and accurate formulas. Of course there is a lot more you can learn about syntax. A good place to learn more is the DAX Reference in PowerPivot Help or SQL Books Online. Syntax QuickQuiz 1. What does this button on the formula bar do? 2. What always surrounds a column name in a DAX formula? 3. How would you write a formula for the following: In the DimProduct table, for each row in the UnitMargin calculated column, calculate a value by subtracting values in the UnitCost column from values in the UnitPrice column? Answers are provided at the end of this topic. 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:  A DAX function always references a complete column or a table. If you want to use only particular values from a table or column, you can add filters to the formula.  If you need to customize calculations on a row-by-row basis, DAX provides functions that let you use the current row value or a related value as a kind of argument, to perform calculations that vary by context. You will learn more about context later.  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.  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. Sometimes it is difficult to know which functions you might need to use in a formula. PowerPivot, and the tabular model designer in SQL Server Data Tools, include the Insert Function feature, a dialog box that helps you select functions by category and provides short descriptions for each function.
  • 12. Let’s create a new formula which includes a function you will select by using the Insert Function feature: Task: Add a function to a formula by using Insert Function In the FactSales table, scroll to the right-most column, and then in the column header, click Add Column. 1. In the formula bar, type an equals sign, =. 2. Click the Insert Function button. This opens the Insert Function dialog box. 3. 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. 4. For this formula, you want to return some data that already exists in another table. For that, you are going to use a function in the Filter category. Go ahead and click the Filter category, and then in Select a function, scroll down and double-click the RELATED function. Click Ok to close the Insert Function dialog box. 5. Use IntelliSense to help you find and select the DimChannel[ChannelName] column. 6. Close the formula and then press Enter. 7. After you press Enter to complete the formula, the word Calculating appears in the status bar along the bottom of the PowerPivot window. Now you will see that you just created a new column in the FactSales table with channel information from the DimChannel table. 8. Rename the column Channel. Your formula should look like this: =RELATED(DimChannel[ChannelName]) You were just introduced to another very important function in DAX, the RELATED function. The RELATED function returns values from another table. You can use RELATED provided there is a relationship between the table you are currently in and the table that contains the values you want to get. Of course, the RELATED function has immense possibilities. In this case, you can now include the sales channel for each sale in the FactSales table. You can now hide
  • 13. the DimChannel table from the PivotTable field list, making it easier to navigate and see only the most important information you really need. Much like the CALCULATE function described earlier, the RELATED function is very important, and you will likely use it many times. As you can see, functions in DAX can help you create very powerful formulas. We really only touched on the basics of functions. As your DAX skills improve, you will create formulas using many different functions. One of the best places to learn details about all of the DAX functions is in the DAX Function Reference on MSDN. Functions QuickQuiz 1. What does a function always reference? 2. Can a formula contain more than one function? 3. What category of functions would you use to concatenate two text strings into one string? Answers are provided at the end of this topic. Context 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, remember the Margin calculated column you saw earlier when learning about syntax? 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. In the selected cell shown below, the value, $49.54 in the current row was calculated by subtracting the value $51.54 in the [TotalCost] column from the value $101.08 in the [SalesAmount] column.
  • 14. 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 measures. 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 PivotTables. 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. 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 measures and columns. For example, let’s look at the following formula in a measure named StoreSales:
  • 15. 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. This formula includes the following syntax elements: A. The measure name StoreSales, followed by a colon :. B. The equals sign operator (=) indicates the beginning of the formula. C. The CALCULATE function evaluates an expression, as an argument, in a context that is modified by the specified filters. D. Parenthesis () surround one or more arguments. E. A measure [Sales] in the same table as an expression. The Sales measure has the formula: =SUM(FactSales[SalesAmount]). F. A comma (,) separates each filter. G. The referenced column and a particular value, DimChannel[ChannelName] =”Store”, as a filter. This formula will ensure only sales values, defined by the Sales measure, 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. Context QuickQuiz 1. What are the two types of context? 2. What is filter context? 3. What is row context? Answers are provided at the end of this topic. Summary Now that you have a basic understanding of the most important concepts in DAX, you can begin creating DAX formulas for calculated columns and measures on your own. DAX can indeed be a little tricky to learn, but there are many resources available to you. After reading through this topic a few times, and experimenting with a few of your own formulas, you can learn more about other DAX concepts and formulas that can help you solve your own business problems. There are many DAX resources available to you in PowerPivot Help, SQL Server Books Online, whitepapers, and blogs from both Microsoft and leading BI professionals. The DAX Resource Center Wiki at
  • 16. http://social.technet.microsoft.com/wiki/contents/articles/dax-resource-center.aspx is a great place to start. The Data Analysis Expressions (DAX) Reference on MSDN is also a great resource. Be sure to save it in your Favorites. The DAX in the BI Tabular Model whitepaper, available for download at http://go.microsoft.com/fwlink/?LinkID=237472&clcid=0x409provides a more detailed look at the concepts introduced here as well as many other advanced concepts and formulas. This whitepaper also uses the same Contoso DAX Sample Formulas.xlsx workbook you already have. QuickQuiz Answers Syntax: 1. Opens the Insert Function feature. 2. Brackets []. 3. =[UnitPrice] - [UnitCost] Functions: 1. A table and a column. 2. Yes. A formula can contain up to 64 nested functions. 3. Text. Context: 1. Row context and filter context. 2. One or more filters in a calculation that determines a single value. 3. The current row.