0% found this document useful (0 votes)
35 views16 pages

Ex 7

This document provides instructions for an assignment to practice DAX measures using a sample dataset. It outlines 32 practice questions across various DAX functions including SUM, COUNT, COUNTROWS, DISTINCTCOUNT, MAX, MIN, AVERAGE, COUNTBLANK, DIVIDE, SUMX, AVERAGEX and CALCULATE. Students are asked to submit Power BI and Word files showing their work.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views16 pages

Ex 7

This document provides instructions for an assignment to practice DAX measures using a sample dataset. It outlines 32 practice questions across various DAX functions including SUM, COUNT, COUNTROWS, DISTINCTCOUNT, MAX, MIN, AVERAGE, COUNTBLANK, DIVIDE, SUMX, AVERAGEX and CALCULATE. Students are asked to submit Power BI and Word files showing their work.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

ASSIGNMENT 7: DAX PRACTICE

Please follow below notices:


1. Do it with your group
2. Submit a package of Power BI file and report (in MS Word format, show process of your work in
step-by-step, and give your comments on those figures). Name of files follows the structure of
“ex7_group1.pbix”, “ex7_group1.docx”.
3. This is a summary assignment, so do it as much as possible.
4. Deadline of submission: before 23:00 October 14, 2022
This assignment is a chance for you to practice DAX measures. Please load the attached dataset (“Ex7
dataset.xlsx”) and conduct the calculations below.
Preparation:
1. Loading data from file, and selecting 5 items including “Calendar”, “Customers”, “Products”,
“Sales”, “Territory”.
2. Create the data model based on the table of relationships, and you get the below figure. Because
these relationships are one-to-many, the joins are specifically single-directional. Please note that
drag from the fact table (or data table) up to the dimensions (or lookup tables).
Data Table Column Lookup Table Column
Sales OrderDate Calendar Date
Sales ProductKey Products ProductKey
Sales CustomerKey Customers CustomerKey
Sales SalesTerritoryKey Territories TerritoryKey

1
A. SUM()
1. [Total Sales] Write a new measure that is the total of the sales in the ExtendedAmount column
from the Sales table.
2. [Total Cost] Create a measure that is the sum of one of the cost columns in the Sales table. You
can use any of the product cost columns in the Sales table; all the cost columns are the same in
this dataset.
3. [Total Margin $] Create a new measure for the total margin, which is total sales minus total cost.
Make sure you reuse the two measures you created above in this new measure.
4. [Total Margin %] Create a new measure that now expresses the total margin from above as a
percentage of total sales. Once again, reuse the measures you created above. (Hint: using
DIVIDE() function)
5. [Total Sales Tax Paid] Create another measure for total sales tax paid. Look for a tax column in
the Sales table and add up the total for that column.
6. [Total Sales Including Tax] The total sales amount above excludes tax, so you need to add two
measures together to get this total.
7. [Total Order Quantity] This is similar to the other measures, but this time you add up the
quantities purchased. Look for the correct column in the Sales table.
B. COUNT()
8. [Total Number of Products] Use the Products lookup table when writing this measure. Just count
how many product numbers there are. Product numbers and product keys are the same thing in
this assignment.

2
9. [Total Number of Customers] Use the Customerslookup table. Again, just count the customer
numbers. Customer numbers and customer keys are the same thing in this assignment.
C. COUNTROWS()
10. [Total Number of Products COUNTROWS Version] Count the number of products in the
Products table, using the COUNTROWS() function.
11. [Total Number of Customers COUNTROWS Version] Count the number of customers in the
Customers table, using the COUNTROWS() function.
D. DISTINCTCOUNT()
12. [Total Customers in Database DISTINCTCOUNT Version] Count a column of unique values in
the Customerstable. Then, add the [Total Number of Customers] measure you created earlier to
the matrix as well. You should end up with a matrix like the one below.

13. [Count of Occupation] Create a new matrix and put


Customers[YearlyIncome] on Rows. Then create the
measure [Count of Occupation]. Use
DISTINCTCOUNT() to count the values in the
Occupation column in the Customers table. You end
up with a matrix like the one shown here. The way to
read this matrix is that there are customers in three
different occupations that have incomes of 10,000,
there are customers across four occupations that have
incomes of 30,000, etc.

3
14. [Count of Country] Create a new matrix and put Territories[Group] on Rows. Write a new
measure called [Count of Country], using DISTINCTCOUNT() over the Country column in the
Territories table. This matrix, as you can see below, shows you how many countries exist in each
sales group.

15. [Total Customers That Have


Purchased] Create a new matrix and
put Products[SubCategory]on Rows.
Then, using DISTINCTCOUNT()on
data from the Sales table, create the
new measure [Total Customers That
Have Purchased]. If you haven’t
already done so, apply some
conditional formatting to the matrix
and then sort the column from
largest to smallest (by clicking on
the heading). You can see below that
Tires and Tubes has the largest
number of customers who have
purchased at least once.

E. MAX(), MIN(), and AVERAGE()


16. [Maximum Tax Paid on a Product] Create a suitable column from the Sales table and use the
MAX() function.
17. [Minimum Price Paid for a Product] Create a suitable column from the Sales table but this time
use the MIN() function.
18. [Average Price Paid for a Product] Create a suitable column from the Sales table but this time use
the AVERAGE() function. You should end up with a matrix like the one shown below.

4
F. COUNTBLANK()
19. [Customers Without Address Line 2] The AddressLine2 column is in the Customers table. As you
write the measure [Customers Without Address Line 2], be sure you do the following:
1. Select the table where you want to store the measure and be sure to add it there.
2. Give the measure a suitable name.
3. Start typing the measure. Pause after you have started to type the formula and read the
IntelliSense to see what the function does (if you don’t already know). As shown below, it does
exactly what you want it to do: It counts how many blanks are in this column.

20. [Products Without Weight Values] The column you need to use is in the Products table. You
should end up with a matrix like the one shown below. Note that the first measure, [Customers
Without Address Line 2], is being filtered by the matrix (i.e., Customers[Occupation] on Rows),
and the values in the matrix change with each row. But the second measure, [Products Without
Weight Values], is not filtered; the values don’t change for each row in the matrix.

G. DIVIDE()

5
21. [Margin %] Write a measure that calculates the percentage margin on sales (TotalMargin$divided
by TotalSales). Reuse measures that you have already written. Note that results of [Total Margin
%] and [Margin %] measures are the same.
22. [Markup %] Find Total Margin $ divided by Total Cost.
23. [Tax %] Divide the total tax by the total sales amount.
H. SUMX()
24. [Total Sales SUMX Version] Multiply quantity by unit price from the appropriate columns in the
Sales table.
25. [Total Sales Including Tax SUMX Version] Add the ExtendedAmount column together with the
appropriate tax column in the Sales table.
26. [Total Sales Including Freight] Add the ExtendedAmount column to the Freight cost.

27. [Dealer Margin] Create a new matrix. Put Product Category on Filters and then select Accessories
from this filter. Then put Product Name on Rows. You should have something like what is shown
below (though what is shown here is truncated). Note that I have used a filter from the Visual
Level Filters section to apply the filter on Product Category. Write a measure that shows the
theoretical margin the dealer gets (i.e., the difference between the product list price and the
product dealer price). Both columns you need for this measure are in the Products table.

6
I. AVERAGEX()
Set up a new matrix and put Products[Category] on Rows. Then write the following measures using
AVERAGEX().
28. [Average Sell Price per Item] Find the column in the Salestable that gives the sell price per unit
and use AVERAGEX()to find the average of this column.
29. [Average Tax Paid] Find the tax column in the Sales table. Find the average of this column.
30. [Average Safety Stock] There is a safety stock column in the Productstable. You should put the
results in a matrix, as shown below.

J. Calculated Columns
31. [Creating a Half-Year Column] Write a calculated column in the Calendar table that returns the
value H1 for the first half of each year (January through June) and H2 for the second half of each
year (July through December). Hint: You might want to use an IF statement to do this.
K. CALCULATE() with a Single Table
Set up a new matrix with Customers[Occupation] on Rows and [Total Number of Customers] on Values.
You should have the matrix shown below as your starting point.

7
32. [Total Male Customers] Write a new measure that modifies the [Total Number of Customers]
measure you wrote previously to come up with a total for male customers only. You need to look
for a suitable column from the Customers table to use in your filter.
33. [Total Customers Born Before 1950] You need to enter the date < January 1, 1950, into the
formula as the filter parameter. You need to use the DATE() function to be able to refer to a date.
You can go ahead and write the measure [Total Customers Born Before 1950].

34. [Total Customers Born in January] You need to use the MONTH() function to turn the
information in the Customers[BirthDate] column into a month.
35. [Customers Earning at Least $100,000 per Year] Write a measure that counts the number of
customers who earn more than $100,000 per year. The following matrix shows what you should
end up with. Look for a suitable column to use for the filter in the Customers table.

L. CALCULATE() with Multiple Tables


36. [Total Sales of Clothing] Use the Products[Category] column in your simple filter. The filter gets
applied to the lookup table, but then the measure [Total Sales] is modified by the filter (and Total
Sales comes from the Sales table), so you use CALCULATE() with multiple tables in this
formula.

8
37. [Sales to Female Customers] As the name of this measure suggests, you use CALCULATE()to
modify the standard calculated field [Total Sales] and create a new measure that is for sales to
female customers.
38. [Sales of Bikes to Married Men] You need to use multiple filters on two tables for this one.
CALCULATE() can accept as many filters as you pass to it. Just separate the filters with
commas.

M. VALUES()
Create a new matrix and put Products[Category] on Rows and the measure [TotalNumberofProducts] on
Values. Then write the following measures by first creating a VALUES() table and then wrapping this
table inside a COUNTROWS() function.
39. [Number of Color Variants]
40. [Number of Sub Categories]
41. [Number of Size Ranges] Use the column Products[SizeRange] for this one.

42. [Product Category (Values)]


43. [Product Subcategory (Values)]

9
44. [Product Color (Values)] Notice that two of these measures are blank. This is because the
VALUES formula has more than one value, and hence the IF HASONEVALUE (or
SELECTEDVALUE) part of the formula returns BLANK(); this is the default if you omit the last
parameter.

45. [Modifying Question 43] Try editing the IF()statement for [ProductSubCategory(Values)]so that
it returns the value More than 1 SubCategory instead of BLANK(). The syntax for IF is
IF(Logical Test, Result if True, Result if False).
46. [Modifying Question 44] try editing the IF() statement for [Product Color (Values)] so that it
returns More than 1 Colour instead of BLANK(). You should end up with something like the
following.

Finally, add a couple of slicers to your report from the Products table for color and subcategory.

N. ALL(), ALLEXCEPT(), and ALLSELECTED()


Create a new matrix and put Customers[Occupation] on Rows and the measure [Total Sales] on Values.
You get the matrix shown below.

10
47. [Total Sales to All Customers]
48. [Total Sales to Selected Customers]
49. [% of Sales to Selected Customers]
50. [% of All Customer Sales] Add a slicer for Customers[Gender] to the report you have just created
and filter by Gender = M, as shown below.

Set up another matrix with Customers[NumberCarsOwned] on Rows, Customers[Occupation]on Slicer,


and [Total Sales] on Values. Your job is to create the other measure in this matrix: [% of Sales to
SelectedCustomers]. When you are done, your matrix should look like the one below, with the last
column showing the percentage of sales to customers based on the number of cars they own.

51. [Total Sales for All Days Selected Dates]


52. [% Sales for All Days Selected Dates]

11
53. [Total Orders All Customers] To check this measure, click on the slicers and note that [Total
Order Quantity] should change, but [Total Orders All Customers] should not change based on the
slicers.
54. [Baseline Orders for All Customers with This Occupation] This measure should also not change
when you make changes to the slicers. However, note that you should get a different value for
each occupation - unlike with [Total Orders All Customers] above. This will be the baseline for
comparison.
55. [Baseline % This Occupation of All Customer Orders] This measure converts the baseline
measure above into a percentage of the baseline for all orders. Test the slicers again and make
sure this new baseline percentage doesn’t change with the slicers.
56. [Total Orders Selected Customers] This measure should adjust depending on the selections you
have in the slicers. Hint: Use ALLSELECTED().
57. [Occupation % of Selected Customers] You can use the interim measures above to create this
measure. Click the slicers a few times and see which values change. This new measure should
change based on the values you select in the slicers.
58. [Percentage Point Variation to Baseline] This measure is the percentage of selected customers
(Question 57) minus the baseline (Question 55).

O. FILTER()
Set up a new matrix with Products[Category] on Rows and [Total Sales] on Values and then write the
following two formulas.
59. [Total Sales of Products That Have Some Sales but Less Than $10,000] Get FILTER() to iterate
over the Products table to determine whether each product has some sales and also whether the
total of those sales is less than $10,000.
Note that you can use the double ampersand operator (&&) if you need more than one condition in your
filter expression: Condition1 && Condition2
Alternatively, you can use two separate FILTER functions.

12
60. [Count of Products That Have Some Sales but Less Than $10,000] You should end up with a
matrix like the one below.

P. Time Intelligence
Before you do these two questions, make sure you set up a matrix like the one below that will give you
feedback if your formula is correct. Set up the matrix like this:
1. Place CalendarYear and MonthName on Filter.
2. Filter for CalendarYear = 2016 and MonthName = August.
3. Put ‘Calendar’[DayNumberOfMonth] on Rows.

13
61. [Total Sales Month to Date]
62. [Total Sales Quarter to Date]
Note: Placing MonthName on rows will not work for Question 61. Instead you need to put a column
such as DayNumberOfMonth in the matrix if you want to be able to “see” that the formula is working
correctly.
63. [Total Sales FYTD 30 September]
64. [Total Sales FYTD 31 December]
Format your matrix by selecting Conditional Formatting, Data Bars to make it easier to spot the
pattern.
Note: Set up a suitable matrix with a suitable column on Rows and [Total Sales] on Values before
writing these measures. Doing this will help you check whether the measures are working and
also should help you comprehend how the measures work. If you don’t understand, go back and
re-read the section about SAMEPERIODLASTYEAR().
65. [Total Sales Previous Month] Given that the PREVIOUSMONTH() function will return a table of
dates, you need to embed the time intelligence formula inside a CALCULATE() function.

14
66. [Total Sales Previous Day] You need to set up a suitable matrix that gives you immediate
feedback about whether your formula is working. Put ‘Calendar’[DayNumberOfMonth] on Rows
and make sure you filter for a single month.
67. [Total Sales Previous Quarter]
68. [Total Sales Moving Annual Total] With this DAX formula, you need to create a rolling 12-
month total of sales. It will always show you 12 months’ worth of sales, up to the end of the
current month.
69. [Total Sales Rolling 90 Days] This is the same as the formula for Question 68, but instead of
delivering a rolling 12-month total, you will instead deliver a rolling 90-day total.
70. [Total Customers Born Before Selected Year] Create a new matrix (on a new page) that allows
the user to select from a list of years in a slicer using a new What-If parameter. Change the above
measure from being hard coded to 1950 and instead make the year selectable from the slicer.
Q. Multiple Data Tables
It’s time to get some practice writing new DAX formulas across the two data tables: BudgetPeriod and
Sales. First, create a new matrix. Then put ProductCategory[Category] on Rows, BudgetPeriod[Period]
on Rows, and [Total Sales] on Values. Make sure you select the correct columns from the two new tables
(ProductCategory and BudgetPeriod).
Once your matrix is set up, click on the Expand All Down icon, as shown below, to expand all levels in
the matrix.

15
Note that the periods shown on Rows in the image above are not formatted properly. The periods should
be in the format YYYYMM, but they are displayed with commas and decimal points. This is an easy fix.
Just select the BudgetPeriod[Period] column in the fields list and change the data type to Whole Number.
Now it is time to create some measures. Right-click the Budget table, select New Measure, and then write
the following new measures.
71. [Total Budget]
72. [Change in Sales vs. Budget]
73. [% Change in Sales vs. Budget]
The image below shows what the matrix looks like with these formulas and the addition of
conditional formatting.

16

You might also like