The
NERD'S GUIDE TO
DAX
TABLE OF CONTENTS
DAX Fundamentals 03
DAX Calculation Types 04
DAX Functions 08
Row Level Security 11
DAX Tips 12
THE NERD'S GUIDE TO DAX | 02
DA X
FUNDAMENTALS
DAX i s a f u n c t i o n a l l a n g u a g e , wh i c h me a n s
DA X , OR DA T A A NA L Y S I S E X P R E S S I ONS , f o r mu l a s a r e c o n s t r u c t e d b y a p p l y i n g a n d
i s a n e l e g a n t a n d e a s y t o l e a r n f o r mu l a c o mp o s i n g v a r i o u s f u n c t i o n s . T h e f u n c t i o n s
l a n g u a g e u s e d i n P o we r B I , P o we r P i v o t a n d can contain other nested functions,
S S AS T a b u l a r t o a d d a n a l y t i c a l v a l u e t o y o u r c o n d i t i o n a l s t a t e me n t s , a n d v a l u e
d a t a mo d e l . DAX i mp r o v e s d a t a mo d e l s b y references. Execution starts from the
a l l o wi n g u s e r s t o e x t r a c t mo r e v a l u e f r o m i n n e r mo s t f u n c t i o n , o r p a r a me t e r , a n d
t h e i r d a t a a n d ma k e mo r e i n f o r me d b u s i n e s s wo r k s o u t wa r d , ma k i n g f o r ma t t i n g
decisions. i mp o r t a n t .
Mi c r o s o f t s p e c i f i c a l l y d e v e l o p e d DAX t o DAX wo r k s wi t h d a t a t h a t i s s t o r e d i n a
s u p p o r t a l a r g e u s e r b a s e . DAX i s mu c h t a b u l a r d a t a mo d e l . T h e s e mo d e l s a r e
easier to learn than traditional technical c o mp r i s e d o f o n e o r mo r e t a b l e s , e a c h t a b l e
l a n g u a g e s , ma k i n g i t a n i d e a l l a n g u a g e f o r c o n t a i n i n g c o l u mn s a n d
u s e r s wh o d o n ’ t c o me f r o m a t e c h n i c a l r o ws o f d a t a . T h e r e a r e t wo p r i ma r y d a t a
b a c k g r o u n d b u t wa n t t o d o t h e i r o wn S e l f - t y p e s : Nu me r i c a n d n o n - n u me r i c o r o t h e r .
S e r v i c e B u s i n e s s I n t e l l i g e n c e . DAX i s o f t e n Nu me r i c i n c l u d e s i n t e g e r s , d e c i ma l s , d a t e s ,
c o mp a r e d t o a n a d v a n c e d v e r s i o n o f E x c e l , a n d c u r r e n c y , wh i l e o t h e r i n c l u d e s s t r i n g s
h a v i n g h i g h - e n d c a p a b i l i t y o f ma n a g i n g a n d a n d b i n a r y o b j e c t s . I f a f u n c t i o n wo r k s o n a
ma n i p u l a t i n g d a t a . Ma n y DAX f u n c t i o n s a r e n u mb e r , i t wo r k s f o r a n y n u me r i c d a t a t y p e .
s i mi l a r t o f u n c t i o n s i n E x c e l , wh i c h me a n s
new users can leverage their existing Wh i l e y o u c a n c r e a t e P o we r B I r e p o r t s t h a t
k n o wl e d g e t o ma k e a n e a s y t r a n s i t i o n s h o w v a l u a b l e i n s i g h t s wi t h o u t u s i n g DAX
t o wr i t i n g a n d a u t h o r i n g DAX f o r mu l a s . f o r mu l a s , c r e a t i n g e f f e c t i v e DAX f o r mu l a s
Wh i l e t h e r e a r e s i mi l a r i t i e s b e t we e n DAX wi l l h e l p y o u g e t t h e mo s t o u t o f y o u r d a t a ,
a n d E x c e l , t h e t wo l a n g u a g e s a r e n o t p r o v i d i n g i n s i g h t a n d s o l u t i o n s t h a t mi g h t
interchangeable. b e mi s s e d wi t h t y p i c a l a n a l y s i s .
THE NERD'S GUIDE TO DAX | 03
DAX CALCULATION TYPES
The two most common uses for DAX are
calculated columns and calculated measures.
Calculated Calculated
Columns Measures
C A L C UL A T E D C OL UMNS A R E P R I MA R I L Y C A L C UL A T E D ME A S UR E S A R E DY NA MI C
u s e d t o a d d n e w c o l u mn s t o a t a b l e p r o v i d i n g calculations that recalculate depending
mo r e wa y s t o d e s c r i b e a n d b r e a k d o wn t h e o n h o w a r e p o r t i s v i e we d o r f i l t e r e d . F o r
d a t a . F o r e x a mp l e , y o u ma y a d d a n a g e e x a mp l e , i f a u s e r c h a n g e d a t i me - r a n g e
c o l u mn t o a c u s t o me r t a b l e s o t h a t s a l e s s l i d e r o n a r e p o r t , t h e me a s u r e s o n t h a t
a n d p r o f i t ma r g i n c a n b e a n a l y z e d a n d r e p o r t wo u l d b e r e c a l c u l a t e d t o r e f l e c t
b r o k e n d o wn b y a g e d e mo g r a p h i c . An o t h e r t h e t i me - r a n g e s e l e c t e d . Un l i k e c a l c u l a t e d
c o mmo n u s e c a s e f o r c r e a t i n g c a l c u l a t e d c o l u mn s wh i c h a r e c a l c u l a t e d d u r i n g
c o l u mn s i s t o c r e a t e a u n i q u e k e y o n a p r o c e s s i n g o f t h e d a t a mo d e l , me a s u r e s
t a b l e , wh i c h ma y b e n e c e s s a r y t o d e f i n e a a r e c a l c u l a t e d a t r u n t i me wh e n a r e p o r t
r e l a t i o n s h i p b e t we e n t wo t a b l e s . i s o p e n e d o r wh e n a u s e r i n t e r a c t s wi t h
the filters on a report. Therefore, the results
o f a me a s u r e a r e a l wa y s c h a n g i n g a n d a r e
not stored in your database. Calculated
Me a s u r e s a r e d i f f e r e n t f r o m c o l u mn s i n
q u i t e a f e w wa y s .
TIP!
It is generally considered best practice to create new columns in your data model in
the original source or in the Power Query editor, before the data is loaded in Power BI
Desktop. This gives the user the best possible compression for the data.
THE NERD'S GUIDE TO DAX | 04
COLUMNS MEASURES
The results of calculated The results of calculated
columns are immediately measures are not stored
viewable in the table. in the database.
Calculated columns can The results of calculated
be used in filters and measures are not stored
slicers. in the database.
Calculated columns are Calculated measures can
updated when the data not be used in filters and
model is refreshed. slicers.
Calculated columns take Calculated measures do
up more space in the not take up space in the
data model. model.
Calculated measures are
Calculated columns are dynamic and always
not dynamic. changing based on the
filters applied.
THE NERD'S GUIDE TO DAX | 05
HOW TO CREATE
CALCULATED COLUMNS
C R E A T I NG A NE W C A L C UL A T E D C OL UMN I S Figure 1.1 – Creating a
calculated column on a table
DONE B Y A DDI NG A NE W C OL UMN T O A N
e x i s t i n g t a b l e a n d t h e n c o mp l e t i n g t h e d e s i r e d
e x p r e s s i o n i n t h e f o r mu l a b a r . On c e a g a i n , t h i s
e x p e r i e n c e i s v e r y s i mi l a r t o u s e r s f a mi l i a r t o wi t h
E x c e l . T h e e x a mp l e p r e s e n t e d h e r e i s s p e c i f i c t o
P o we r B I De s k t o p b u t a l s o a p p l i e s t o P o we r P i v o t
a n d S S AS t a b u l a r . T o c r e a t e a n e w c a l c u l a t e d
c o l u mn o n a t a b l e , r i g h t c l i c k o n t h e t a b l e n a me
a n d s e l e c t Ne w c o l u mn . S e e F i g u r e 1 . 1 .
On c e Ne w c o l u mn i s s e l e c t e d , t h e p o we r u s e r c a n
n o w wr i t e t h e DAX e x p r e s s i o n i n t h e a c t i v e f o r mu l a
bar. See Figure 1.2.
Figure 1.2 – DAX Expression for new calculated column
The expression in Figure 1.2 creates a new Full
Na me c o l u mn o n t h e c u s t o me r t a b l e b y c o mb i n i n g
t h e f i r s t a n d l a s t n a me s e p a r a t e d b y a s p a c e . L e t ’ s
take a closer look at the steps:
1) The text that appears before the = is the name of the column.
2) The text that appears after the = is the DAX expression.
C a l c u l a t e d c o l u mn s a p p e a r i n t h e F i e l d s l i s t o f a t a b l e wi t h a s p e c i a l i c o n
i n d i c a t i n g t h a t t h e c o l u mn wa s c a l c u l a t e d wi t h DAX.
THE NERD'S GUIDE TO DAX | 06
HOW TO CREATE
CALCULATED MEASURES
C A L C UL A T E D ME A S UR E S A R E C R E A T E D I N MUC H Figure 1.3 – Create new
Calculated Measure
t h e s a me wa y t h a t c a l c u l a t e d c o l u mn s a r e . F i r s t ,
r i g h t c l i c k o n t h e t a b l e t h a t y o u wa n t t h e me a s u r e
t o b e a s s i g n e d t o a n d s e l e c t Ne w me a s u r e f r o m t h e
d r o p d o wn me n u . S e e F i g u r e 1 . 3 .
On c e Ne w me a s ur e i s s e l e c t e d , t h e p o we r u s e r c a n
n o w wr i t e t h e DAX e x p r e s s i o n i n t h e a c t i v e f o r mu l a
bar. See Figure 1.4.
Figure 1.4 – DAX Expression for new calculated measure
T h e DAX e x p r e s s i o n i n F i g u r e 1 . 4 c r e a t e s a n e w
c a l c u l a t e d T o t a l S a l e s me a s u r e wh i c h i s s i mp l y t h e
S UM o f t h e s a l e s a mo u n t c o l u mn . T h e f i r s t p a r t o f
t h i s e x p r e s s i o n i s t h e n a me o f t h e c a l c u l a t e d
me a s u r e a n d t h e s e c o n d p a r t i s t h e DAX e x p r e s s i o n .
Yo u ma y a l r e a d y k n o w t h a t i n P o we r B I De s k t o p ,
n u me r i c c o l u mn s c a n b e a d d e d t o a v i s u a l i z a t i o n
a n d b e a u t o ma t i c a l l y a g g r e g a t e d u s i n g a d e f a u l t
s u mma r i z a t i o n l i k e s u m, ma x , c o u n t , e t c . T h e s e
default aggregations can offer quick insights into
y o u r d a t a . Ho we v e r , we r e c o mme n d y o u a l wa y s e x p l i c i t l y c r e a t e y o u r o wn c a l c u l a t e d
me a s u r e s b e c a u s e t h e r e a r e ma n y a d v a n t a g e s t o d o i n g s o . L e t ’ s t a k e a l o o k a t s o me o f
t h e a d v a n t a g e s o f e x p l i c i t l y c r e a t i n g c a l c u l a t e d me a s u r e s :
1. The formatting can be set on the measure, creating consistency across report visuals.
2. The complex business logic is saved in a single location, making logic changes easier.
3. Calculated measures can be leveraged in other calculated measures, making the code
easier to read and reducing rework.
THE NERD'S GUIDE TO DAX | 07
DAX FUNCTIONS
DA X I S A F OR MUL A L A NG UA G E T HA T US E S A C OL L E C T I ON OF F UNC T I ONS
wh i c h c a n b e u s e d t o a u t h o r c o l u mn s , me a s u r e s a n d t a b l e s a s p r e v i o u s l y
d i s c u s s e d . T h e r e a r e ma n y d i f f e r e n t f u n c t i o n c a t e g o r i e s i n DAX wh i c h we wi l l
t a k e a l o o k a t i n t h i s s e c t i o n . F u n c t i o n s h a v e r e q u i r e d p a r a me t e r s a n d o p t i o n a l
p a r a me t e r s a s i n p u t s . T h e s e DAX f u n c t i o n s , wh i c h p e r f o r m v a r i o u s t a s k s f r o m
ma t h e ma t i c a l c a l c u l a t i o n s t o t i me i n t e l l i g e n c e , a r e wh a t ma k e DAX s u c h a
p o we r f u l a n d s i mp l e l a n g u a g e t o l e a r n . T h o s e f a mi l i a r wi t h E x c e l f o r mu l a s
wi l l s e e s i mi l a r i t i e s i n ma n y o f t h e s e f u n c t i o n s , a l t h o u g h DAX f o r mu l a s d o
d i f f e r i n i mp o r t a n t wa y s . T h e y a l wa y s r e f e r e n c e a c o mp l e t e c o l u mn o r a t a b l e
and require filters to focus on specific values. There are functions that use the
c u r r e n t r o w v a l u e o r a r e l a t e d v a l u e a s a p a r a me t e r t o p e r f o r m c a l c u l a t i o n s
t h a t v a r y b y c o n t e x t t o c u s t o mi z e c a l c u l a t i o n s o n a r o w- b y - r o w b a s i s . An d
a s i d e f r o m r e t u r n i n g a s i n g l e v a l u e , ma n y DAX f u n c t i o n s r e t u r n a t a b l e , wh i c h
can be used as an input to other functions.
Aggregation Functions
Aggregation functions are probably the most common in DAX.
Aggregations group together multiple values to create a single
value. DAX has numerous aggregation functions available. Here
are some, not all, of the available aggregate functions: SUM, MIN,
MAX, AVERAGE, COUNT, etc.
Calculate Function
The CALCULATE function is one of the most powerful and widely used DAX
functions as it helps evaluate functions by modifying the filter context of the
expression. The CALCULATE function is similar to the Excel SUMIF & COUNTIF
functions, however CALCULATE is not limited to a single aggregation.
Date and Time Functions
These functions perform calculations on dates and time values. They
are like Excel date and time functions, but DAX functions use a datetime
data type and do not necessarily apply to time intelligence. Common
examples include TOTALYTD, SAMEPERIODLASTYEAR, and
DATESINPERIOD.
THE NERD'S GUIDE TO DAX | 08
DAX FUNCTIONS CONTINUED
Filter Functions
Filter functions return specific data types, look up values in related tables, and
filter by related values. They differ greatly from Excel functions. Lookup functions
work by using tables and relationships, like a database. Filter functions can
manipulate data context to make dynamic calculations. Filter functions are
similar to the calculate function except for the fact that they are not mutable
and are most commonly used to return a subset of an expression or table.
Financial Functions
Financial functions are used in formulas that perform
calculations such as net present value and rate of return.
They’re comparable to financial functions in Excel.
Information Functions
These functions look at a data within a table, column, or row provided as an
argument to another function and confirm whether the value matches the
expected type. For instance, the function ISERROR returns TRUE if the
data evaluated contains an error. While these functions can be helpful,
it’s recommended to know the data type of your columns, rather
than depending solely on these functions.
Logical Functions
Logical functions evaluate an expression or argument and return TRUE or FALSE if
the condition is met or not. For example, the TRUE function confirms whether an
expression being evaluated returns a TRUE value. These functions can be
expressed with operators when more than two conditions are needed in a
formula, such as AND being replaced with &&, although for readability it is
best practice use the function name itself where possible.
Math & Trig Functions
Mathematical and trig functions perform various mathematical
functions on referred values, including basic arithmetic,
conditional sums & products, exponents & logarithms, and
the trigonometric ratios.
THE NERD'S GUIDE TO DAX | 09
DAX FUNCTIONS CONTINUED
Other Functions
These functions don’t fall into other categories as they perform actions that aren’t
defined by any of the categories most functions belong to.
Parent and Child Functions
These functions assist users with managing data that’s presented
as a parent/child hierarchy in data models.
Relationship Management Functions
These functions manage and utilize relationships between tables.
Statistical Functions
These functions perform statistical and aggregation functions
on data values, such as finding sums and averages and minimum
and maximum values. In DAX, you can filter a column before
aggregating or create aggregations based on related tables.
Table Manipulation Functions
The table functions apply operations and conditions on entire tables. The output is
then used as inputs for other expressions or arguments in a DAX formula. The results
of these functions retain the relationships between columns of that table.
Text Functions
Text functions can return part of a string, search for text within a string, or
concatenate string values. They can also control the formats for dates, times, and
numbers. These text functions work similarly to Excel functions with the same name.
Time Intelligence Functions
The time-intelligence functions use built-in knowledge about calendars and dates and
evaluate data over a fixed period such as days, weeks, months, quarter, or years. They
require well-formed tables to compare time periods for sales, inventory, and more.
THE NERD'S GUIDE TO DAX | 10
ROW-LEVEL SECURITY (RLS)
WITH POWER BI
R OW L E V E L S E C UR I T Y ( R L S ) US E S G R OUP ME MB E R S HI P OR E X E C UT I ON C ONT E X T T O
c o n t r o l a c c e s s t o r o ws i n a d a t a b a s e t a b l e . I t s i mp l i f i e s c o d i n g a n d d e s i g n o f s e c u r i t y a n d
enforces restrictions on data row access.
T h e a c c e s s r e s t r i c t i o n l o g i c i s i n t h e d a t a b a s e t i e r , wh i c h mi n i mi z e s t h e s u r f a c e a r e a o f
t h e s e c u r i t y s y s t e m. T h e d a t a b a s e s y s t e m a p p l i e s t h e a c c e s s r e s t r i c t i o n s e v e r y t i me t h a t
d a t a a c c e s s i s a t t e mp t e d f r o m a n y t i e r .
R o w- L e v e l S e c u r i t y c a n b e s e t u p i n P o we r B I i t s e l f , o r t h r o u g h r e s p e c t i n g t h e d a t a s o u r c e
r e s t r i c t i o n s f r o m a l i v e c o n n e c t i o n l i k e t o S S AS T a b u l a r .
Dy n a mi c R L S c a n a l s o b e a c c o mp l i s h e d b y s t o r i n g t h e d e f i n i t i o n o f s e c u r i t y b e s i d e
t h e u s e r a c c o u n t i n f o r ma t i o n i n t h e d a t a s o u r c e . F o r e x a mp l e , wh e n J o h n l o g s i n t o t h e
s y s t e m, b a s e d o n d a t a t a b l e s t h a t d e f i n e J o h n ’ s a c c e s s , h e s h o u l d b e a b l e t o s e e o n l y t h e
d a t a r e l e v a n t t o h i m. T h i s i s p o s s i b l e u s i n g DAX f u n c t i o n s l i k e Us e r Na me ( ) o r
Us e r P r i n c i p a l Na me ( ) wh e n c r e a t i n g R o l e s i n R L S .
THE NERD'S GUIDE TO DAX | 11
DA X
TIPS
Use Measures to Carry Out Calculations
Ag g r e g a t i o n s , r a t i o s , p e r c e n t a g e s a n d o t h e r c a l c u l a t i o n s s h o u l d g e n e r a l l y
b e c r e a t e d i n c a l c u l a t e d me a s u r e s n o t c a l c u l a t e d c o l u mn s . Me a s u r e s a r e
d y n a mi c a n d r e s p o n s i v e t o f i l t e r s wh e r e a s c o l u mn s a r e s t a t i c a n d u p d a t e d
o n l y d u r i n g t h e d a t a mo d e l r e f r e s h .
Hide Unnecessary Columns
Hi d e a l l u n n e c e s s a r y c o l u mn s f r o m c l i e n t t o o l s s o u s e r s wo n ’ t b e o v e r -
wh e l me d a n d c a n b e t t e r a v o i d a g g r e g a t i n g c o l u mn s i n c o r r e c t l y . On c e
me a s u r e s h a v e b e e n c r e a t e d t o c a r r y o u t a l l t h e c a l c u l a t i o n s n e e d e d ,
t h e o r i g i n a l c o l u mn s c a n o f t e n b e h i d d e n .
Format Measures
Al wa y s f o r ma t a me a s u r e o n c e i t h a s b e e n d e v e l o p e d t o c r e a t e c o n s i s t e n c y
a c r o s s v i s u a l i z a t i o n s a n d r e p o r t s . On c e t h e f o r ma t t i n g i s s e t i t wi l l c a r r y
i n t o p i v o t t a b l e s o r c h a r t s e a c h t i me t h a t me a s u r e i s s e l e c t e d .
Write DAX Like Code
DAX f o r mu l a s a r e e a s i e r t o b o t h r e a d a n d d e b u g wh e n wr i t t e n l i k e c o d e
( a n d n o t wr i t t e n l i k e E x c e l ) .
Avoid Data Transformation Steps
Wh e n p o s s i b l e , d a t a t r a n s f o r ma t i o n s t e p s s h o u l d n o t b e c a r r i e d o u t i n a
DAX c a l c u l a t i o n . Da t a t r a n s f o r ma t i o n a n d c l e a n s i n g s h o u l d b e c a r r i e d o u t
wi t h a d i f f e r e n t t o o l , s u c h a s P o we r Qu e r y .
THE NERD'S GUIDE TO DAX | 12
[Link]
hello@[Link]
(904) 413-1911
1845 Towncenter Blvd.
Suite 505
Fleming Island, FL 32003
Follow us on social media