0% found this document useful (0 votes)
2 views15 pages

Power BI Learning Series: A To Z: Part 7: DAX (Data Analysis Expressions)

DAX (Data Analysis Expressions) is a formula language used in Power BI for creating custom calculations on data models, including calculated columns, measures, and calculated tables. Key concepts include calculated columns for adding new data, measures for aggregations, and various functions like FILTER and CALCULATE for manipulating data context. The document also provides examples of common DAX functions and tips for writing efficient DAX code.

Uploaded by

rajkapure986
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)
2 views15 pages

Power BI Learning Series: A To Z: Part 7: DAX (Data Analysis Expressions)

DAX (Data Analysis Expressions) is a formula language used in Power BI for creating custom calculations on data models, including calculated columns, measures, and calculated tables. Key concepts include calculated columns for adding new data, measures for aggregations, and various functions like FILTER and CALCULATE for manipulating data context. The document also provides examples of common DAX functions and tips for writing efficient DAX code.

Uploaded by

rajkapure986
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/ 15

Power BI Learning Series: A to Z

Part 7: DAX (Data Analysis


Expressions)
What is DAX?

1. DAX stands for Data Analysis Expressions — a formula language

used in Power BI, Power Pivot, and SSAS.

2. DAX is used to create custom calculations on data models like

calculated columns, measures, and calculated tables.

3. DAX operates on tables and columns, not individual cells like Excel.
Key Concepts of DAX
1. Calculated Columns

Adds new data to a table (row by row).

Stored in the model, increases size.

Example:

FullName = Customers[FirstName] & " " & Customers[LastName]

This adds a new column to the Customers table by concatenating

first and last names.


2. Measures
Performs aggregations like SUM, AVERAGE, etc.
Calculated only during report usage (more efficient).
Example: Total Sales = SUM(Sales[SalesAmount])
Calculates the sum of all values in the SalesAmount column.
3. Calculated Tables
New tables created using DAX.
Useful for filtering, summarizing data.
Example: HighSales = FILTER(Sales, Sales[SalesAmount] > 1000)
Creates a new table containing only rows with SalesAmount > 1000.
Common DAX Functions
1. Aggregation Functions

Function Description Example

SUM Adds numbers SUM(Sales[Amount])

AVERAGE Mean value AVERAGE(Sales[Amount])

COUNT Count rows COUNT(Sales[ProductID])

DISTINCTCOUNT(Sales
DISTINCTCOUNT Count unique values
[CustomerID])
2. Logical Functions

Function Description Example

IF(Sales[Amount] > 1000,


IF Conditional logic
"High", "Low")

SWITCH(TRUE(),
Sales[Amount]>1000,
"High",
SWITCH Multiple IFs
Sales[Amount]>500,
"Medium", "Low")
3. Date Functions

Function Description Example

TODAY() Returns today’s date TODAY()

YEAR() Extracts year YEAR(Orders[OrderDate])

DATEDIFF(Orders[OrderDate],
DATEDIFF Date difference
Orders[ShipDate], DAY)
4. FILTER Function
FILTER(table, condition)

Example:

HighValueSales = CALCULATE(SUM(Sales[SalesAmount]), FILTER(Sales,

Sales[SalesAmount] > 1000))

Explanation:

FILTER(Sales, Sales[SalesAmount] > 1000): returns only rows with

SalesAmount > 1000.

CALCULATE(..., FILTER(...)): changes context to filtered rows, then sums


5. CALCULATE Function
Most powerful DAX function, used to change context.

Syntax:

CALCULATE(<expression>, <filter1>, <filter2>, ...)

Example:

Total2019Sales = CALCULATE(SUM(Sales[SalesAmount]), Sales[Year] =

2019)

Explanation:

Changes the context to only 2019, then sums SalesAmount.


6. RELATED / RELATEDTABLE

RELATED: brings in values from related tables (many-to-one).

RELATEDTABLE: returns table of related rows (one-to-many).

Example:

CustomerCity = RELATED(Customers[City])

Explanation:

From the Sales table, pulls in the related city from Customers table.
7. ALL Function
Removes filters from columns/tables.

Example:

PercentOfTotal = DIVIDE(SUM(Sales[Amount]), CALCULATE(SUM(Sales

[Amount]), ALL(Sales)))

Explanation:

Finds percentage of total by removing filters from the Sales table.


DAX Example with Full Explanation

Find % of Total Sales for Each Product

Step 1: Total Sales by Product

ProductSales = SUM(Sales[SalesAmount])

Step 2: Total Sales All Products

AllProductSales = CALCULATE(SUM(Sales[SalesAmount]), ALL(Products))

Step 3: % of Total Sales

PercentOfTotal = DIVIDE([ProductSales], [AllProductSales])


How it works:

ProductSales: gets sales for the current product row.

AllProductSales: removes filters so it's the total across all products.

DIVIDE: safely divides (avoids divide-by-zero).

Tips for Writing DAX:

Use CALCULATE to manipulate filter context.

Use DIVIDE instead of / to avoid errors.

FILTER returns a table, often used inside CALCULATE.

Avoid calculated columns unless necessary—measures are more

efficient.
Useful Time Intelligence Functions

Function: TOTALYTD

Description: Year-to-date

Example: TOTALYTD(SUM(Sales[Amount]), Dates[Date])

Function: SAMEPERIODLASTYEAR

Description: Compare to last year

Example: SAMEPERIODLASTYEAR(Dates[Date])

Function: DATEADD

Description: Shift time

Example: DATEADD(Dates[Date], -1, YEAR)


✅ Part 7: Done!
🚀 Next step – Data
Visualization 💥✨

You might also like