[go: up one dir, main page]

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

Art of DAX

The document discusses good practices for writing DAX code, including formatting, commenting, shortcuts, variables, and measure tables. It recommends formatting DAX code with line breaks, indentation, and whitespace to improve readability. It also emphasizes the importance of adding comments to document intent, calculations, variables, problems, and restrictions. Various keyboard shortcuts for navigating and editing DAX code are provided. The use of variables to store and manipulate values is described. Finally, it outlines how to create a measure table to organize calculated measures.

Uploaded by

Kiran Keeru
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)
37 views41 pages

Art of DAX

The document discusses good practices for writing DAX code, including formatting, commenting, shortcuts, variables, and measure tables. It recommends formatting DAX code with line breaks, indentation, and whitespace to improve readability. It also emphasizes the importance of adding comments to document intent, calculations, variables, problems, and restrictions. Various keyboard shortcuts for navigating and editing DAX code are provided. The use of variables to store and manipulate values is described. Finally, it outlines how to create a measure table to organize calculated measures.

Uploaded by

Kiran Keeru
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
POWER BI
DO YOU USE DAX?
WANT TO KNOW SOME GOOD PRACTICES?

Scroll this side


GOOD PRACTICES IN DAX

1. FORMATTING
2. COMMENTING
3. SHORTCUTS
4 VARIABLES
. MEASURE TABLE
5.
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.
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.
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.
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.
IF YOU DON'T WANT TO
FORMAT IT ON YOUR OWN.

THEN YOU CAN VISIT :


https://www.daxformatter.com/
COMMENTING IN DAX

1. FORMATTING
2. COMMENTING
3. SHORTCUTS
4 VARIABLES
. MEASURE TABLE
5.
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
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. COMMENTIN
3. G
SHORTCUTS
4 VARIABLES
. MEASURE TABLE
5.
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)
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)
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.
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.
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.
SHORTCUTS IN DAX

DELETE DAX LINE :


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

SELECT ALL OCCURANCE CURRENT


SELECTION :
Select & Press "Ctrl" + "Shift" + "L"
SHORTCUTS IN DAX

SCROLL UP/DOWN WITHOUT


MOVING CURSOR :

Press "Ctrl" + "Up Arrow" to move


upwards.
Press "Ctrl" + "Down Arrow" to move
Downwards.
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.
COMMENTING IN DAX

1. FORMATTING
2. COMMENTING
3. SHORTCUTS

4. VARIABLES
5. MEASURE TABLE
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
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

You might also like