0% found this document useful (0 votes)
15 views41 pages

Dax Simple

The document discusses best practices for using DAX, including formatting code with line breaks, indentation, and whitespace for readability. It also covers commenting code to document intent and issues, using shortcuts to navigate and edit code efficiently, declaring variables to store intermediate results and simplify complex formulas, and creating measure tables to organize different measure types and group related calculations.

Uploaded by

Hendra Yuliyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views41 pages

Dax Simple

The document discusses best practices for using DAX, including formatting code with line breaks, indentation, and whitespace for readability. It also covers commenting code to document intent and issues, using shortcuts to navigate and edit code efficiently, declaring variables to store intermediate results and simplify complex formulas, and creating measure tables to organize different measure types and group related calculations.

Uploaded by

Hendra Yuliyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

THE ART OF

DAX
PROVEN BEST PRACTICES

PART-01
POWER BI
www.linkedin.com/in/pushkar-bhamare
DO YOU USE DAX?
WANT TO KNOW SOME GOOD PRACTICES?

Scroll this side

www.linkedin.com/in/pushkar-bhamare
GOOD PRACTICES IN DAX

1. FORMATTING
2. COMMENTING
3. SHORTCUTS
4. VARIABLES
5. MEASURE TABLE

www.linkedin.com/in/pushkar-bhamare
GOOD PRACTICES IN DAX
Use line breaks: Break your code into multiple
lines to make it easier to read. Use line breaks
to separate different functions and arguments.

www.linkedin.com/in/pushkar-bhamare
GOOD PRACTICES IN DAX
Use indentation: Indent your code to show the
hierarchy of functions and arguments. Use the
tab key or spaces to indent your code.

www.linkedin.com/in/pushkar-bhamare
GOOD PRACTICES IN DAX
Use whitespace: Use whitespace to separate different
parts of your code. For example, add a space between
the function name and the first argument.

www.linkedin.com/in/pushkar-bhamare
GOOD PRACTICES IN DAX
Use parentheses: Use parentheses to group functions
and arguments. This can make your code easier to read
and reduce the risk of errors.

www.linkedin.com/in/pushkar-bhamare
IF YOU DON'T WANT TO
FORMAT IT ON YOUR OWN.

THEN YOU CAN VISIT :


https://www.daxformatter.com/

www.linkedin.com/in/pushkar-bhamare
COMMENTING IN DAX

1. FORMATTING
2. COMMENTING
3. SHORTCUTS
4. VARIABLES
5. MEASURE TABLE

www.linkedin.com/in/pushkar-bhamare
COMMENTING IN DAX

But why i need to add comments in


my DAX?
Describing the intent behind a formula
Describing a calculation's reasoning
Setting a variable or measure's context
Highlighting any possible problems or code
restrictions
COMMENTING IN DAX

There are two Types of comments.

1. Single Line comment


2. Multi-Line Comment

www.linkedin.com/in/pushkar-bhamare
COMMENTING IN DAX

Single Line Comments:


To Add a Single line comment Type "--" or "//"
and start your comment.
COMMENTING IN DAX

Multi Line Comments:

To start a multi line comment Type "/*" &


to End the comment type "*/"
COMMENTING IN DAX
Tip:
You can also use Comments to Disable
part of DAX without Removing It.
COMMENTING IN DAX

1. FORMATTING
2. COMMENTING
3. SHORTCUTS
4. VARIABLES
5. MEASURE TABLE

www.linkedin.com/in/pushkar-bhamare
SHORTCUTS IN DAX

1. ZOOM IN & ZOOM OUT DAX


EDITOR :

Way 1 :
Hold Ctrl key & Roll Wheel of Mouse.

Way 2 :
Hold Ctrl key & "+" Key to Zoom In.
Hold Ctrl key & "-" Key to Zoom Out.
SHORTCUTS IN DAX

INSERT LINE BELOW :

Way 1 :
Press "Shift" key plus "Enter" Key.

Way 2 :
Press "Alt" key plus "Enter" Key.
(It will take you to start of the new line)

www.linkedin.com/in/pushkar-bhamare
SHORTCUTS IN DAX

INSERT LINE BELOW :

Way 1 :
Press "Shift" key plus "Enter" Key.

Way 2 :
Press "Alt" key plus "Enter" Key.
(It will take you to start of the new line)

www.linkedin.com/in/pushkar-bhamare
SHORTCUTS IN DAX

COMMENT OR UNCOMMENT LINE :

Way 1 :
Press "Ctrl" key plus "/" Key to
comment.
Press "Ctrl" key plus "/" Key to
uncomment.

www.linkedin.com/in/pushkar-bhamare
SHORTCUTS IN DAX

INDENTATION :
Way 1 :
Press "TAB" key.

Way 2 :
Press "Ctrl" key plus "]" Key to
forward Indentation.
Press "Ctrl" key plus "[" Key to
Backward Indentation.
www.linkedin.com/in/pushkar-bhamare
SHORTCUTS IN DAX

MOVE DAX LINE UP & DOWN :

Press "Alt" Key plus "Down Arrow"


To move code downwards.
Press "Alt" Key plus "Up Arrow" To
move code Upwards.

www.linkedin.com/in/pushkar-bhamare
SHORTCUTS IN DAX

DUPLICATE DAX LINE :

Press "Alt" Plus "Shift" & "Down


Arrow" to duplicate code in below
line.
Press "Alt" Plus "Shift" & "Up Arrow"
to duplicate code in above line.

www.linkedin.com/in/pushkar-bhamare
SHORTCUTS IN DAX

DELETE DAX LINE :


Select the line & Press "Ctrl" + "Shift" +
"K"

SELECT ALL OCCURANCE CURRENT


SELECTION :
Select & Press "Ctrl" + "Shift" + "L"

www.linkedin.com/in/pushkar-bhamare
SHORTCUTS IN DAX

SCROLL UP/DOWN WITHOUT


MOVING CURSOR :

Press "Ctrl" + "Up Arrow" to move


upwards.
Press "Ctrl" + "Down Arrow" to move
Downwards.

www.linkedin.com/in/pushkar-bhamare
SHORTCUTS IN DAX

SWITCH BETWEEN START & END


BRACKETS:

Press "Ctrl" + "Shift" + "\" to move


from open bracket to close bracket.
Press "Ctrl" + "Shift" + "\" to move
from close bracket to open bracket.

www.linkedin.com/in/pushkar-bhamare
COMMENTING IN DAX

1. FORMATTING
2. COMMENTING
3. SHORTCUTS
4. VARIABLES
5. MEASURE TABLE

www.linkedin.com/in/pushkar-bhamare
VARIABLES IN DAX

What is a Variable?

Variables are used to store and


manipulate values within DAX.

They provide flexibility and improve


the readability and maintainability
of complex DAX expressions.
VARIABLES IN DAX
Syntax & variable Declaration:
To declare a variable in DAX, you use the VAR
keyword followed by the variable name, an equal
sign, and the expression or value assigned to the
variable.
To complete the Loop you need to Write RETURN
statement to define calculation.
VARIABLES IN DAX
Syntax & variable Declaration:

it is not Mandatory to always


write the last variable name
after RETURN Statement.
VARIABLES IN DAX
Syntax & variable Declaration:

It is not Mandatory to write any


Variable name after RETURN, You
can also start another calculation.
VARIABLES IN DAX
Nested Variable:

We can also Declare variable


inside another variable.(Nested
Variable)
VARIABLES IN DAX
Important Note:
Once the variable declared it will not recalculate
again when you use that variable.

DAX : DAX :

RESULT: RESULT:
VARIABLES IN DAX
Important Note:
We can only use Varible once It is declared,
You can not use same varible in same line untill
it is declared.
We can not use Variable once loop is closed.
Once you close Varible Loop with RETURN
statement you can not use that variable.
Declared Variable can be use in same DAX function
only.
VAR1 is Declared in Measure1 so we can use that
variable only in Measure1 not in measure2
VARIABLES IN DAX
Benifits of Variable in DAX:
Code Efficiency: By storing intermediate results in
variables, you can reuse those values multiple times
within a formula.
Easy for Complex Calculations: Variables enable you to
break down complex calculations into smaller,
manageable parts.
Easier Debugging: Variables play a crucial role in
troubleshooting and debugging DAX formulas.
Readability and Maintainability: Variables improve the
readability of DAX formulas by allowing you to assign
meaningful names to intermediate results or complex
expressions.
COMMENTING IN DAX

1. FORMATTING
2. COMMENTING
3. SHORTCUTS
4. VARIABLES
5. MEASURE TABLE

www.linkedin.com/in/pushkar-bhamare
MEASURE TABLE IN DAX

A measure table is a table created


specifically to store calculated
measures.

It is a table that contains columns


representing different measures,
such as sums, averages, counts, or
any other calculations based on the
underlying data.
MEASURE TABLE IN DAX
How to create Measure Table?
Create New Table and Name this
table "Measure Table".
MEASURE TABLE IN DAX
How to create Measure Table?
Select Measure & go to Measure tools Tab.
In Home table select "Measure Table"

Delete first default column "Column1" by Right


click & "Delete from model.
MEASURE TABLE IN DAX
How to create Measure Table?
Now you can allocate all your measure to
Specific measure Tables.

Measure Table based on Datasets :

Measure Table based on Measure Type:


MEASURE TABLE IN DAX
Pro Tip :
We can also Create Folders in Measure Table based on Measure Type:

1. Go to the Modeling Tab.


2. Select The Measure & Click on Properties.
3. Go to Display Folder & Name it based on
requirement.
DO YOU FIND THIS USEFUL ?
IF YES,
You can FOLLOW

www.linkedin.com/in/pushkar-bhamare

You might also like