Lab Manual 07
Lab Manual 07
LAB MANUAL 7
Date:
Name:
Reg#: Group:
Marks: Signature:
Introduction:
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
1. CALCULATE:
Example:
Suppose you have a sales table with columns for sales amount, date, and
region. You can use the CALCULATE function to filter the sales amount by
a specific date and region. For instance, the following DAX formula
calculates the total sales amount for the Western region in January 2022:
=CALCULATE(SUM(Sales[Amount]), Sales[Region]="West",
YEAR(Sales[Date])=2022, MONTH(Sales[Date])=1)
2. SUM:
Example:
Suppose you have a table with a column for sales amount. You can use
the SUM function to calculate the total sales amount. For instance, the
following DAX formula calculates the total sales amount:
=SUM(Sales[Amount])
3. AVERAGE:
Example:
Suppose you have a table with a column for product prices. You can use
the AVERAGE function to calculate the average price. For instance, the
following DAX formula calculates the average price:
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
=AVERAGE(Products[Price])
4. COUNT:
The COUNT function counts the number of rows in a table or column that
contain a value. It is helpful for determining the number of occurrences.
Example:
Suppose you have a table with a column for product names. You can use
the COUNT function to count the number of products. For instance, the
following DAX formula counts the number of products:
=COUNT(Products[Name])
5. MIN/MAX:
The MIN and MAX functions return the minimum and maximum values,
respectively, from a specified column or expression.
Example:
Suppose you have a table with a column for product prices. You can use
the MIN and MAX functions to find the lowest and highest prices,
respectively. For instance, the following DAX formulas find the minimum
and maximum prices:
=MIN(Products[Price])
=MAX(Products[Price])
6. DISTINCT:
Example:
Suppose you have a table with a column for product categories. You can
use the DISTINCT function to retrieve a list of unique categories. For
instance, the following DAX formula retrieves the distinct categories:
= DISTINCT(Products[Category])
7. CONCATENATE:
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
Example:
Suppose you have a table with columns for first and last names. You can
use the CONCATENATE function to create a full name field. For instance,
the following DAX formula creates a full name field:
8. LEFT/RIGHT:
Example:
Suppose you have a table with a column for phone numbers. You can use
the LEFT and RIGHT functions to extract the area code and last four digits,
respectively. For instance, the following DAX formulas extract the area
code and last four digits:
=LEFT(Orders[Phone Number], 3)
=RIGHT(Orders[Phone Number], 4)
9. LEN:
Example:
Suppose you have a table with a column for product descriptions. You can
use the LEN function to calculate the length of each description. For
instance, the following DAX formula calculates the length of the
description:
=LEN(Products[Description])
10. UPPER/LOWER/PROPER:
Example:
Suppose you have a table with a column for customer names. You can use
the UPPER, LOWER, and PROPER functions to format the names. For
instance, the following DAX formulas convert the names to uppercase,
lowercase, and proper case:
=UPPER(Customers[Name])
=LOWER(Customers[Name])
=PROPER(Customers[Name])
11. IF:
Example:
Suppose you have a table with a column for sales amounts. You can use
the IF function to categorize sales as "High" or "Low" based on a
threshold. For instance, the following DAX formula categorizes sales:
12. SWITCH:
Example:
Suppose you have a table with a column for product ratings. You can use
the SWITCH function to assign a rating category based on the rating
value. For instance, the following DAX formula assigns a rating category:
13. ISBLANK:
Example:
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
Suppose you have a table with a column for order dates. You can use the
ISBLANK function to identify orders with missing dates. For instance, the
following DAX formula flags orders with missing dates:
14. AND/OR:
The AND and OR functions perform logical operations. They return TRUE
or FALSE based on the logical conditions specified.
Example:
Suppose you have a table with columns for product prices and quantities.
You can use the AND function to check if both price and quantity meet
certain criteria. For instance, the following DAX formula checks if the price
is greater than $50 and the quantity is less than 10:
15. DATE:
The DATE function creates a date from specified year, month, and day
values. It is useful for working with date-related calculations.
Example:
Suppose you have a table with columns for year, month, and day. You can
use the DATE function to create a date field. For instance, the following
DAX formula creates a date field:
16. YEAR/MONTH/DAY:
The YEAR, MONTH, and DAY functions extract the year, month, and day
components from a date, respectively.
Example:
Suppose you have a table with a column for order dates. You can use the
YEAR, MONTH, and DAY functions to extract the corresponding
components. For instance, the following DAX formulas extract the year,
month, and day:
=YEAR(Orders[Date])
=MONTH(Orders[Date])
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
=DAY(Orders[Date])
17. FORMAT:
Example:
Suppose you have a table with a column for sales amounts. You can use
the FORMAT function to format the amounts as currency. For instance, the
following DAX formula formats the sales amounts:
=FORMAT(Sales[Amount], "Currency")
18. RANKX:
Example:
Suppose you have a table with a column for product sales. You can use
the RANKX function to rank the products based on sales. For instance, the
following DAX formula calculates the sales rank:
=RANKX(Products, Products[Sales])
19. RELATED:
Example:
Suppose you have a table with a column for customer IDs and another
table with customer names. You can use the RELATED function to retrieve
the corresponding customer names based on the IDs. For instance, the
following DAX formula retrieves the customer name:
=RELATED(Customers[Name])
20. CALCULATETABLE:
Example:
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
Suppose you have a table with columns for sales amounts and regions.
You can use the CALCULATETABLE function to filter the sales amounts by
region. For instance, the following DAX formula creates a new table with
sales amounts in the Western region:
=CALCULATETABLE(Sales, Sales[Region]="West")
21. FIRSTNONBLANK/LASTNONBLANK:
Example:
Suppose you have a table with a column for product sales. You can use
the FIRSTNONBLANK and LASTNONBLANK functions to retrieve the first
and last non-blank sales amounts, respectively. For instance, the following
DAX formulas retrieve the first and last non-blank sales amounts:
=FIRSTNONBLANK(Products[Sales], 0)
=LASTNONBLANK(Products[Sales], 0)
22. DIVIDE:
The DIVIDE function divides two numbers and handles zero or blank
values gracefully by returning a specified alternate value.
Example:
Suppose you have a table with columns for sales and units sold. You can
use the DIVIDE function to calculate the sales per unit, handling the case
where units sold is zero. For instance, the following DAX formula
calculates the sales per unit, returning zero when units sold is zero: