0% found this document useful (0 votes)
49 views5 pages

DAX_Practice_Exercises

The document provides a series of DAX exercises with solutions using a sample sales dataset, including calculated columns and measures for sales categorization, total sales, average sales per customer, and customer performance. It also includes visualization exercises such as bar charts, line charts, and KPI visuals to analyze sales data. Additional exercises focus on identifying top products, unique customers, and sales contributions by category.

Uploaded by

shubhiyadav1105
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)
49 views5 pages

DAX_Practice_Exercises

The document provides a series of DAX exercises with solutions using a sample sales dataset, including calculated columns and measures for sales categorization, total sales, average sales per customer, and customer performance. It also includes visualization exercises such as bar charts, line charts, and KPI visuals to analyze sales data. Additional exercises focus on identifying top products, unique customers, and sales contributions by category.

Uploaded by

shubhiyadav1105
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/ 5

DAX Exercises with Solutions and Sample Dataset

Dataset: Sales Data (Sample Columns)

OrderID Date Customer Region Category Product Quantity Unit Total


Price Sales
1001 2024-01-01 John Doe East Electronics Laptop 2 800 1600
Jane
1002 2024-02-10 Smith West Furniture Chair 5 150 750
Alice
1003 2024-03-15 Brown North Electronics Phone 3 600 1800
Bob
1004 2024-04-05 Johnson South Furniture Table 1 500 500
Emma Office
1005 2024-05-20 Davis East Supplies Pen 10 2 20

Calculated Column: Sales Category


Exercise 1: Create a calculated column that categorizes sales as 'High' if Total Sales > 1000,
otherwise 'Low'.

**Solution:**
Sales_Category = IF('Sales'[Total Sales] > 1000, "High", "Low")

Measure: Total Sales


Exercise 2: Create a measure to compute total sales across all orders.

**Solution:**
Total_Sales_Measure = SUM('Sales'[Total Sales])

Measure: Average Sales per Customer


Exercise 3: Calculate the average sales per customer.

**Solution:**
Avg_Sales_Per_Customer = AVERAGE('Sales'[Total Sales])

High Performing Customers


Exercise 4: Write a measure to return 'High Performer' if total sales per customer exceed
$5000, otherwise 'Regular'.

**Solution:**
Customer_Performance =
IF(
CALCULATE(SUM('Sales'[Total Sales]), ALLEXCEPT('Sales', 'Sales'[Customer])) > 5000,
"High Performer",
"Regular"
)

1. SUM('Sales'[Total Sales])

o This calculates the total sales amount for all records in the Sales table.

2. CALCULATE(SUM('Sales'[Total Sales]), ALLEXCEPT('Sales', 'Sales'[Customer]))

o CALCULATE modifies the context in which the calculation happens.

o ALLEXCEPT('Sales', 'Sales'[Customer]) removes all filters except for the


Customer column.

o This means that the SUM('Sales'[Total Sales]) is now evaluated per


customer, ignoring any other filters applied to the dataset (like Region,
Date, Category, etc.).

3. IF(... > 5000, "High Performer", "Regular")

o If the total sales for a given customer exceed $5000, the result is "High
Performer".

o Otherwise, the result is "Regular".

Visualization-Based Exercises
- 1. Bar Chart: Total Sales per Region

• Hint: Use a Bar Chart, place Region on the X-axis and Total Sales on the Y-axis.

• Extra: Sort in descending order, add data labels for clarity.

2. Line Chart: Monthly Sales Trends

• Hint: Use a Line Chart, add Month-Year (from a Date Table) on the X-axis, and
Total Sales on the Y-axis.

• Extra: Use rolling averages for trend smoothing.

3. KPI Visual: Sales Growth Percentage

• Hint: Create a Measure:


Sales_Growth = DIVIDE(SUM('Sales'[Total Sales]) - SUM('Sales'[Last Year Sales]),
SUM('Sales'[Last Year Sales]), 0)

• Extra: Set target value and conditional formatting.

4. Matrix Visual: Sales by Category and Year

• Hint: Use a Matrix Visual, place Category in Rows, Year in Columns, and Total
Sales in Values.

• Extra: Apply conditional formatting for insights.

Few more exercises

1. Identify Top 5 Products by Sales

Question:
Create a table visual showing the Top 5 Products based on total sales.

Solution:

• Use a Table Visual, drag Product Name and Total Sales.

• Apply a Top N filter on Total Sales and set it to Top 5.

2. Create a KPI visual that shows whether total sales meet a dynamic sales target of
$10,000 per month.

Solution:

Sales_Target =

IF(

SUM('Sales'[Total Sales]) >= 10000,

"Target Achieved ",

"Below Target "

• Use in a KPI visual with Conditional Formatting.

3. Write a measure to count the number of unique customers who made purchases.
Solution:

Unique_Customers = DISTINCTCOUNT('Sales'[Customer ID])

• Use in a Card Visual.

4. Write a measure to calculate total sales for 2023 only.

Solution:

Total_Sales_2023 =
CALCULATE(
SUM('Sales'[Total Sales]),
YEAR('Sales'[Order Date]) = 2023
)

Use in a Column Chart by month.

5. Total Sales for a Specific Category

Question:
Create a measure to calculate total sales for Electronics only.

Solution:

Total_Sales_Electronics =

CALCULATE(

SUM('Sales'[Total Sales]),

'Sales'[Category] = "Electronics"

6. Customers Who Spent Over $5000

Question:
Count the number of customers whose total sales exceed $5000.

Solution:

High_Value_Customers =

CALCULATE(

DISTINCTCOUNT('Sales'[Customer ID]),

SUM('Sales'[Total Sales]) > 5000)


7. Sales Percentage by Product

Question:
Calculate each product’s percentage contribution to total sales.

Solution:

Sales_Percentage =

DIVIDE(

SUM('Sales'[Total Sales]),

CALCULATE(SUM('Sales'[Total Sales]), ALL('Sales')),

) * 100

8. Customers Who Made Multiple Purchases

Question:
Count customers who have made more than one purchase.

Solution:

Multiple_Purchase_Customers =

CALCULATE(

DISTINCTCOUNT('Sales'[Customer ID]),

COUNT('Sales'[Order ID]) > 1

You might also like