0% found this document useful (0 votes)
9 views

Ideas Bid - Dta Lab 5

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)
9 views

Ideas Bid - Dta Lab 5

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/ 9

DTA102/BID102 – BUSINESS INTELLIGENCE AND DATA ANALYTICS LAB 4

In today’s class, we will build a beautiful report from start to finish using DAX expressions and a
retail dataset.

First, let’s take a quick look at our dataset. Our financial sample dataset includes columns like:

• Transaction ID: Unique identifier for each transaction.


• Date: Date of the transaction.
• Customer ID: Unique identifier for each customer.
• Gender: Gender of the customer (Male/Female).
• Age: Age of the customer.
• Product Category: Category of the product purchased.
• Quantity: Number of units purchased.
• Price per Unit: Price of one unit of the product.
• Total Amount: Total amount of the transaction (Quantity * Price per Unit).

Nect we will be Importing our Data into Power BI

1. Open Power BI Desktop.


2. Click on Home -> Get Data -> Excel.
3. Select your Excel file and load the retail_sales table.

[Data Preparation in Power Query]

1. Go to Home -> Transform Data to open Power Query Editor.


2. Check the data types of each column and ensure they are correct.
3. Create new columns if needed. For example, to create an Age Group column:
Age Group = if [Age] < 20 then "Under 20" else if [Age] >= 20 and [Age] < 30 then "20-
29" else if [Age] >= 30 and [Age] < 40 then "30-39" else if [Age] >= 40 and [Age] < 50
then "40-49" else if [Age] >= 50 then "50+" else "Unknown"

Creating Basic and Advanced DAX Measures

1. Total Sales

Total Sales = SUM('Sales'[Total Amount])

o This measure calculates the sum of the Total Amount column, providing the
overall revenue.
o SUM: This function adds up all the values in a column.
o 'Sales'[Total Amount]: Specifies the column we are summing, which is the Total
Amount column in the Sales table.
o Knowing total sales is crucial for assessing the company’s revenue. Helps to
understand the revenue generated over different periods or by different categories.
2. Total Quantity Sold

Total Quantity Sold = SUM('Sales'[Quantity])

o This measure sums up the Quantity column, giving the total number of items sold.
o SUM: This function adds up all the values in a column.
o 'Sales'[Quantity]: Specifies the column we are summing, which is the Quantity
column in the Sales table.
o Helps in tracking sales volume. Identifies best-selling products and trends in sales
volume.
3. Average Sales per Transaction
Average Sales per Transaction = AVERAGE ('Sales'[Total Amount])

o This measure calculates the average sales amount per transaction.


o AVERAGE: This function calculates the average of all the values in a column.
o 'Sales'[Total Amount]: Specifies the column we are averaging, which is the
Total Amount column in the Sales table.
o Provides insights into typical transaction values. Helps understand the average
value of transactions.

Advanced Measures:

1. Sales by Product Category

Sales by Category = CALCULATE(SUM('Sales'[Total Amount]), ALLEXCEPT('Sales',


'Sales'[Product Category]))

o This measure calculates total sales for each product category by removing all
filters except the Product Category.
o CALCULATE: This function changes the context in which the data is evaluated.
o SUM('Sales'[Total Amount]): Sums up all the values in the Total Amount
column.
o ALLEXCEPT('Sales', 'Sales'[Product Category]): Removes all filters except
for the Product Category column.
o Useful for understanding which categories contribute most to revenue. Identifies
high-revenue product categories.
2. Sales by Gender

Sales by Gender = CALCULATE(SUM('Sales'[Total Amount]), ALLEXCEPT('Sales',


'Sales'[Gender]))

o This measure calculates total sales by gender.


o CALCULATE: This function changes the context in which the data is evaluated.
o SUM('Sales'[Total Amount]): Sums up all the values in the Total Amount
column.
o ALLEXCEPT('Sales', 'Sales'[Gender]): Removes all filters except for the
Gender column.
o Helps understand the purchasing behavior of different genders.Identifies sales
trends based on gender.
3. Sales by Age Group
o First, create an Age Group column in Power Query or DAX:

Age Group = SWITCH(


TRUE(),
'Sales'[Age] < 20, "Under 20",
'Sales'[Age] >= 20 && 'Sales'[Age] < 30, "20-29",
'Sales'[Age] >= 30 && 'Sales'[Age] < 40, "30-39",
'Sales'[Age] >= 40 && 'Sales'[Age] < 50, "40-49",
'Sales'[Age] >= 50, "50+",
"Unknown"
)

o This categorizes customers into different age groups.


o SWITCH: This function evaluates an expression against a list of values and
returns the first result that matches.
o TRUE(): This ensures the function evaluates each condition.
o Helps in analyzing sales by different age groups. Provides a breakdown of sales
contributions by age group.
4. Customer Lifetime Value

Customer Lifetime Value = CALCULATE(SUM('Sales'[Total Amount]),


ALLEXCEPT('Sales', 'Sales'[Customer ID]))

o Explanation: This measure calculates the total sales amount for each customer.
o CALCULATE: This function changes the context in which the data is evaluated.
o SUM('Sales'[Total Amount]): Sums up all the values in the Total Amount
column.
o ALLEXCEPT('Sales', 'Sales'[Customer ID]): Removes all filters except for the
Customer ID column.
o Helps understand the value each customer brings over their lifetime.Identifies
high-value customers.
5. Profit Margin
o Since there is a Cost column in the dataset:

Profit Margin = DIVIDE(SUM('Sales'[Total Amount]) - SUM('Sales'[Cost]),


SUM('Sales'[Total Amount]))

o Explanation: This measure calculates the profit margin for sales.


o DIVIDE: This function performs division and handles division by zero.
o SUM('Sales'[Total Amount]): Sums up all the values in the Total Amount
column.
o SUM('Sales'[Cost]): Sums up all the values in the Cost column.
o Provides insights into the profitability of products and categories. Evaluates the
profitability of sales.

Time Intelligence Measures:

1. Total Sales Last Year

Total Sales Last Year = CALCULATE(SUM('Sales'[Total Amount]),


SAMEPERIODLASTYEAR('Sales'[Date]))

• This measure calculates the total sales amount for the same period in the previous year.
• CALCULATE: This function changes the context in which the data is evaluated.
• SUM('Sales'[Total Amount]): Sums up all the values in the Total Amount column.
• SAMEPERIODLASTYEAR('Sales'[Date]): Adjusts the date context to the same
period in the previous year.
• Essential for year-over-year comparison. Evaluates sales growth and trends over the same
period in the previous year.

2. Total Sales Year to Date (YTD)

Total Sales YTD = CALCULATE(SUM('Sales'[Total Amount]),


DATESYTD('Sales'[Date]))

o This measure calculates the total sales amount from the beginning of the year to
the current date.
o CALCULATE: This function changes the context in which the data is evaluated.
o SUM('Sales'[Total Amount]): Sums up all the values in the Total Amount
column.
o DATESYTD('Sales'[Date]): Shifts the date context to cover the period from the
start of the year to the current date.
o Important for tracking annual performance. Monitors cumulative sales
performance within the year.
3. Total Sales Month to Date (MTD)

Total Sales MTD = CALCULATE(SUM('Sales'[Total Amount]),


DATESMTD('Sales'[Date]))

o This measure calculates the total sales amount from the beginning of the month to
the current date.
o CALCULATE: This function changes the context in which the data is evaluated.
o SUM('Sales'[Total Amount]): Sums up all the values in the Total Amount
column.
o DATESMTD('Sales'[Date]): Shifts the date context to cover the period from the
start of the month to the current date.
o Useful for monthly performance analysis.Assesses sales progress within the
current month.
4. Total Sales Quarter to Date (QTD)
Total Sales QTD = CALCULATE(SUM('Sales'[Total Amount]),
DATESQTD('Sales'[Date]))

o This measure calculates the total sales amount from the beginning of the quarter
to the current date.
o CALCULATE: This function changes the context in which the data is evaluated.
o SUM('Sales'[Total Amount]): Sums up all the values in the Total Amount
column.
o DATESQTD('Sales'[Date]): Shifts the date context to cover the period from the
start of the quarter to the current date.
o Critical for quarterly performance evaluation.Tracks sales performance within the
current quarter.

Creating Visualizations

Now, let’s create some visualizations to bring our data to life. These visualizations will help us
understand our data better and make informed business decisions.

1. Sales Trends Over Time:


o Visualization: Line Chart
▪ Drag Date to Axis and Total Sales to Values.
▪ This shows how sales change over time, helping to identify trends and
seasonal patterns.This visualization helps to spot trends and understand
how sales fluctuate over different periods.
2. Sales by Segment:
o Visualization: Bar Chart
▪ Drag Segment to Axis and Total Sales to Values.
▪ This compares sales across different business segments, highlighting the
top-performing segments.Identifies which segments are performing well
and contributing most to the revenue.
3. Sales by Country:
o Visualization: Map
▪ Drag Country to Location and Total Sales to Size.
▪ This map visualizes sales across different countries, helping to identify
geographical sales trends. Shows which countries are generating the most
sales, aiding in geographical performance analysis.
4. Profit by Segment:
o Visualization: Bar Chart
▪ Drag Segment to Axis and Total Profit to Values.
▪ This compares profit across different business segments, highlighting the
most profitable segments. Helps to identify the most profitable segments
and focus on enhancing them.
5. Profit Margin by Product Category:
o Visualization: Bar Chart
▪ Drag Product Category to Axis and Profit Margin to Values.
▪ This chart shows the profit margin for each product, providing insights
into the profitability of different products. Identifies which products have
the highest profit margins, helping in product performance analysis.
6. Total Sales Year to Date (YTD):
o Visualization: Line Chart
▪ Drag Date to Axis and Total Sales YTD to Values.
▪ This shows the cumulative sales from the beginning of the year to the
current date, providing insights into annual performance.Tracks the
cumulative sales performance throughout the year.
7. Total Sales Month to Date (MTD):
o Visualization: Line Chart
▪ Drag Date to Axis and Total Sales MTD to Values.
▪ This shows the cumulative sales from the beginning of the month to the
current date, helping to monitor monthly performance. Provides a detailed
view of the monthly sales progress.
8. Total Sales Quarter to Date (QTD):
o Visualization: Line Chart
▪ Drag Date to Axis and Total Sales QTD to Values.
▪ This shows the cumulative sales from the beginning of the quarter to the
current date, providing insights into quarterly performance. Monitors sales
performance within the current quarter.
9. Sales Performance by Day of the Week:
o Visualization: Bar Chart
▪ Drag Date to Axis and set it to display the day of the week.
▪ Drag Total Sales to Values.
▪ This shows how sales perform on different days of the week, helping to
identify peak shopping days. Identifies the best and worst performing days
of the week for sales..

You might also like