0% found this document useful (0 votes)
20 views12 pages

DAX Functions SUMMARY

The document provides an overview of DAX functions categorized into groups such as Aggregate, Logical, Text, Date and Time, Filter, and Time Intelligence functions. Each category includes detailed explanations and examples illustrating how to use various functions like SUM, AVERAGE, IF, CONCATENATE, TODAY, FILTER, and TOTALYTD. This serves as a comprehensive guide for users to understand and apply DAX functions in data analysis.

Uploaded by

afoeze1
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)
20 views12 pages

DAX Functions SUMMARY

The document provides an overview of DAX functions categorized into groups such as Aggregate, Logical, Text, Date and Time, Filter, and Time Intelligence functions. Each category includes detailed explanations and examples illustrating how to use various functions like SUM, AVERAGE, IF, CONCATENATE, TODAY, FILTER, and TOTALYTD. This serves as a comprehensive guide for users to understand and apply DAX functions in data analysis.

Uploaded by

afoeze1
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/ 12

DAX Functions

DAX functions can be categorized into several groups. Below, we’ll elaborate on each category with
detailed explanations and multiple examples.

Aggregate Functions
Aggregate functions perform calculations on a set of values and return a single value.

1. SUM()
Adds up all the values in a specified column.

Example 1: Total Sales

Total Sales = SUM(Sales[SalesAmount])

Calculates the total sales amount from the `SalesAmount` column in the `Sales` table.

Example 2: Total Quantity Sold

Total Quantity = SUM(Sales[Quantity])

Calculates the total quantity sold from the `Quantity` column in the `Sales` table.

2. AVERAGE()
Calculates the average of values in a specified column.

Example 1: Average Sales Amount

Average Sales = AVERAGE(Sales[SalesAmount])

Returns the average sales amount from the `SalesAmount` column.

Example 2: Average Discount

Average Discount = AVERAGE(Sales[Discount])

Calculates the average discount applied in the sales transactions.

3. COUNT()
Counts the number of rows in a column that contain numbers.

Example 1: Count of Sales Transactions


Number of Sales = COUNT(Sales[SalesID])

Counts the total number of sales transactions based on the `SalesID` column.

Example 2: Count of Products Sold

Count of Products = COUNT(Sales[ProductID])

Counts how many products have been sold.

4. COUNTA()
Counts the number of non-empty values in a column.

Example 1: Count of Non-blank Customer Names

Count of Customers = COUNTA(Customers[CustomerName])

Counts all non-blank customer names in the `CustomerName` column.

Example 2: Count of Non-empty Order IDs

Count of Orders = COUNTA(Sales[OrderID])

Counts all non-empty order IDs.

5. MIN()
Returns the smallest value in a column.

Example 1: Minimum Sales Amount

Lowest Sale = MIN(Sales[SalesAmount])

Finds the smallest sales amount from the `SalesAmount` column.

Example 2: Minimum Order Quantity

Minimum Quantity = MIN(Sales[Quantity])

Returns the minimum quantity ordered.

6. MAX()
Returns the largest value in a column.
Example 1: Maximum Sales Amount

Highest Sale = MAX(Sales[SalesAmount])

Finds the largest sales amount from the `SalesAmount` column.

Example 2: Maximum Order Quantity

Maximum Quantity = MAX(Sales[Quantity])

Returns the maximum quantity ordered.

---

Logical Functions
Logical functions perform logical operations and return TRUE or FALSE.

1. IF()
Evaluates a condition and returns one value if TRUE, another if FALSE.

Example 1: Sales Performance

Sales Performance = IF(Sales[SalesAmount] > 1000, "High", "Low")

Classifies sales as "High" if above 1000, otherwise "Low".

Example 2: Discount Eligibility

Discount Eligibility = IF(Sales[TotalPurchase] > 500, "Eligible", "Not Eligible")

Checks if the total purchase qualifies for a discount.

2. AND()
Returns TRUE if all conditions are TRUE.

Example 1: High Sales in North Region

Is High Sales = IF(AND(Sales[SalesAmount] > 1000, Sales[Region] = "North"), "Yes", "No")

Checks if sales are high and in the North region.

Example 2: Product Availability


Is Available = IF(AND(Products[Stock] > 0, Products[Discontinued] = FALSE), "In Stock", "Out of Stock")

Determines if a product is available based on stock and discontinuation status.

3. OR()
Returns TRUE if at least one condition is TRUE.

Example 1: Sales in Specific Regions

Is South or West = IF(OR(Sales[Region] = "South", Sales[Region] = "West"), "Yes", "No")

Checks if sales are in either the South or West region.

Example 2: High Discount or Special Offer

Is Special Offer = IF(OR(Sales[Discount] > 20, Sales[SpecialOffer] = TRUE), "Yes", "No")

Determines if a sale qualifies as a special offer.

4. NOT()
Reverses the value of a logical expression.

Example 1: Not High Sales

Not High Sales = IF(NOT(Sales[SalesAmount] > 1000), "Yes", "No")

Checks if sales are not high.

Example 2: Not Eligible for Discount

Not Eligible for Discount = IF(NOT(Sales[TotalPurchase] > 500), "Yes", "No")

Determines if a purchase does not qualify for a discount.

---
Text Functions
Text functions manipulate text strings.

1. CONCATENATE()
Joins two text strings into one.

Example 1: Full Name


Full Name = CONCATENATE(Customers[FirstName], " " & Customers[LastName])

Combines first and last names into a full name.

Example 2: Address

Full Address = CONCATENATE(Customers[StreetAddress], ", " & Customers[City])

Combines street address and city into a full address.

2. LEN()
Returns the length of a text string.

Example 1: Length of Customer Name

Name Length = LEN(Customers[CustomerName])

Calculates the length of customer names.

Example 2: Length of Product Description

Description Length = LEN(Products[Description])

Returns the length of product descriptions.

3. LEFT()
Returns the specified number of characters from the start of a text string.

Example 1: First Three Letters of Product Code

Product Code Prefix = LEFT(Products[ProductCode], 3)

Extracts the first three letters of the product code.

Example 2: Initials from Name

Initials = LEFT(Customers[FirstName], 1) & LEFT(Customers[LastName], 1)

Creates initials from the first and last names.

4. RIGHT()
Returns the specified number of characters from the end of a text string.
Example 1: Last Three Characters of Product SKU

SKU Suffix = RIGHT(Products[SKU], 3)

Extracts the last three characters of the SKU.

Example 2: Last Name from Full Name

Last Name = RIGHT(Customers[FullName], LEN(Customers[FullName]) - FIND(" ", Customers[FullName]))

Extracts the last name from the full name.

5. UPPER()
Converts a text string to uppercase.

Example 1: Uppercase Customer Name

Upper Case Name = UPPER(Customers[CustomerName])

Converts customer names to uppercase.

Example 2: Uppercase Product Description

Upper Case Description = UPPER(Products[Description])

Converts product descriptions to uppercase.

6. LOWER()
Converts a text string to lowercase.

Example 1: Lowercase Customer Name

Lower Case Name = LOWER(Customers[CustomerName])

Converts customer names to lowercase.

Example 2: Lowercase Product Description

Lower Case Description = LOWER(Products[Description])

Converts product descriptions to lowercase.

---
Date and Time Functions
These functions work with date and time values.

1. TODAY()
Returns the current date.

Example 1: Current Date

Current Date = TODAY()

Displays the current date.

Example 2: Days Since Start of Year

Days Since Start of Year = TODAY() - DATE(YEAR(TODAY()), 1, 1)

Calculates the number of days since the start of the current year.

2. NOW()
Returns the current date and time.

Example 1: Current DateTime

Current DateTime = NOW()

Displays the current date and time.

Example 2: Time Elapsed Since Last Update

Time Since Last Update = NOW() - LastUpdated[UpdateTime]

Calculates the time elapsed since the last update.

3. YEAR()
Extracts the year from a date.

Example 1: Year of Sale

Sale Year = YEAR(Sales[SaleDate])

Extracts the year from the sale date.


Example 2: Year of Birth

Birth Year = YEAR(Customers[DateOfBirth])

Extracts the birth year from the customer's date of birth.

4. MONTH()
Extracts the month from a date.

Example 1: Month of Sale

Sale Month = MONTH(Sales[SaleDate])

Extracts the month from the sale date.

Example 2: Month of Birth

Birth Month = MONTH(Customers[DateOfBirth])

Extracts the birth month from the customer's date of birth.

5. DAY()
Extracts the day from a date.

Example 1: Day of Sale

Sale Day = DAY(Sales[SaleDate])

Extracts the day from the sale date.

Example 2: Day of Birth

Birth Day = DAY(Customers[DateOfBirth])

Extracts the day from the customer's date of birth.

6. DATEDIFF()
Calculates the difference between two dates.

Example 1: Days Between Two Dates

Days Between = DATEDIFF(Sales[StartDate], Sales[EndDate], DAY)

Calculates the number of days between start and end dates.


Example 2: Months Between Two Dates

Months Between = DATEDIFF(Sales[StartDate], Sales[EndDate], MONTH)

Calculates the number of months between start and end dates.

---

Filter Functions
These functions modify filter context for calculations.

1. FILTER()
Returns a table that has been filtered based on a condition.

Example 1: Filter High Sales

High Sales = FILTER(Sales, Sales[SalesAmount] > 1000)

Creates a table of sales where the sales amount exceeds 1000.

Example 2: Filter Products in Stock

In Stock Products = FILTER(Products, Products[Stock] > 0)

Creates a table of products that are in stock.

2. ALL()
Removes filters from a table or column.

Example 1: Total Sales Without Filters

Total Sales All = CALCULATE(SUM(Sales[SalesAmount]), ALL(Sales))

Calculates total sales ignoring any filters applied to the `Sales` table.

Example 2: All Products Count

Total Products All = CALCULATE(COUNT(Products[ProductID]), ALL(Products))

Counts all products ignoring any filters.

3. CALCULATE()
Changes the context in which data is evaluated.

Example 1: Total Sales for 2020

Total Sales 2020 = CALCULATE(SUM(Sales[SalesAmount]), Sales[Year] = 2020)

Calculates total sales for the year 2020.

Example 2: Total Sales for Specific Region

Total Sales North = CALCULATE(SUM(Sales[SalesAmount]), Sales[Region] = "North")

Calculates total sales for the North region.

4. VALUES()
Returns a one-column table that contains the distinct values from the specified column.

Example 1: Unique Products Sold

Unique Products = VALUES(Sales[ProductID])

Returns a table of unique product IDs sold.

Example 2: Distinct Customer Names

Distinct Customers = VALUES(Customers[CustomerName])

Returns a table of distinct customer names.

---

Time Intelligence Functions


Time intelligence functions simplify working with dates and time, allowing for easy calculations over
time periods.

1. TOTALYTD()
Calculates year-to-date values.

Example 1: Year-to-Date Sales

Total Sales YTD = TOTALYTD(SUM(Sales[SalesAmount]), Dates[Date])

Calculates total sales from the beginning of the year to the current date.
Example 2: Year-to-Date Profit

Total Profit YTD = TOTALYTD(SUM(Sales[Profit]), Dates[Date])

Calculates year-to-date profit.

2. SAMEPERIODLASTYEAR()
Compares values from the same period in the previous year.

Example 1: Sales Last Year

Sales Last Year = CALCULATE(SUM(Sales[SalesAmount]), SAMEPERIODLASTYEAR(Dates[Date]))

Calculates total sales for the same period last year.

Example 2: Profit Last Year

Profit Last Year = CALCULATE(SUM(Sales[Profit]), SAMEPERIODLASTYEAR(Dates[Date]))

Calculates profit for the same period last year.

3. DATEADD()
Shifts dates by a specified number of intervals.

Example 1: Sales Last Month

Sales Last Month = CALCULATE(SUM(Sales[SalesAmount]), DATEADD(Dates[Date], -1, MONTH))

Calculates total sales for the last month.

Example 2: Sales Last Quarter

Sales Last Quarter = CALCULATE(SUM(Sales[SalesAmount]), DATEADD(Dates[Date], -1, QUARTER))

Calculates total sales for the last quarter.

4. PREVIOUSYEAR()
Returns the previous year.

Example 1: Sales Previous Year

Sales Previous Year = CALCULATE(SUM(Sales[SalesAmount]), PREVIOUSYEAR(Dates[Date]))


Calculates total sales for the previous year.

Example 2: Profit Previous Year

Profit Previous Year = CALCULATE(SUM(Sales[Profit]), PREVIOUSYEAR(Dates[Date]))

Calculates profit for the previous year.

You might also like