DAX_Practice_Exercises
DAX_Practice_Exercises
**Solution:**
Sales_Category = IF('Sales'[Total Sales] > 1000, "High", "Low")
**Solution:**
Total_Sales_Measure = SUM('Sales'[Total Sales])
**Solution:**
Avg_Sales_Per_Customer = AVERAGE('Sales'[Total Sales])
**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.
o If the total sales for a given customer exceed $5000, the result is "High
Performer".
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.
• Hint: Use a Line Chart, add Month-Year (from a Date Table) on the X-axis, and
Total Sales on the Y-axis.
• Hint: Use a Matrix Visual, place Category in Rows, Year in Columns, and Total
Sales in Values.
Question:
Create a table visual showing the Top 5 Products based on total sales.
Solution:
2. Create a KPI visual that shows whether total sales meet a dynamic sales target of
$10,000 per month.
Solution:
Sales_Target =
IF(
3. Write a measure to count the number of unique customers who made purchases.
Solution:
Solution:
Total_Sales_2023 =
CALCULATE(
SUM('Sales'[Total Sales]),
YEAR('Sales'[Order Date]) = 2023
)
Question:
Create a measure to calculate total sales for Electronics only.
Solution:
Total_Sales_Electronics =
CALCULATE(
SUM('Sales'[Total Sales]),
'Sales'[Category] = "Electronics"
Question:
Count the number of customers whose total sales exceed $5000.
Solution:
High_Value_Customers =
CALCULATE(
DISTINCTCOUNT('Sales'[Customer ID]),
Question:
Calculate each product’s percentage contribution to total sales.
Solution:
Sales_Percentage =
DIVIDE(
SUM('Sales'[Total Sales]),
) * 100
Question:
Count customers who have made more than one purchase.
Solution:
Multiple_Purchase_Customers =
CALCULATE(
DISTINCTCOUNT('Sales'[Customer ID]),