DAX Flashcards
What does DAX stand for?
Data Analysis Expressions
What is DAX?
A library of:
- Functions
- Operators
- Constants
that can be used in formulas
Where is DAX used?
- SSAS
- Power Pivot in Excel
- Power BI
Commonly used operators in DAX
- ()
- +
- -
- *
- =
- <>
How do you indicate the AND operator in a DAX expression?
??
How do you indicate the OR operator in a DAX expression?
||
How do you concatenate two values into one string?
+
VAR syntax example
VAR VarName1=DAX Formula VAR VarName2=DAX Formula Return Divide(VarName1, VarName2)
VAR Example
VAR SalesAmount =
SUMX(Sales,
Sales [Unit Price] * Sales[Quantity])
VAR CustomerCount =
DISTINCTCOUNT (Sales[CustomerKey])
RETURN
DIVIDE (SalesAmount, CustomerCount)
When should you use VAR?
Anytime you write a complex expression. This enhances formula readability.
What are the benefits of using a VAR in a DAX formula?
- Easier to read
- Easier to debug
- Re-use formulas
- Avoid running formulas multiple times.
- To avoid extra columns in your column list that are intermediate calculations that will not be used independently
What special characters do you use to comment DAX code?
For a single line
//
For a multi-line comment
/* … */
Just writing a really long sentence so it will left justify
What is a calculated column?
- A new column added to an existing table
- Almost always applied row by row
Calculated Column Syntax
CalculatedColumnName= 'TableName'[ColumnName1] OPERATOR 'TableName'[ColumnName2]
Example
Total Sales =
‘Sales’[Quantity] * ‘Sales’[Unit Price]
How does ADDCOLUMNS work?
- Automatically includes all columns from the table indicated in the Table argument
- Adds additional columns to that table by giving a column name as text and then the field name or an expression.