POWER BI EXERCISES▼
DAX | The FILTER function exercise | Use the FILTER function to limit purchases in a measure
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
You can learn how to do this exercise if you attend one of more of the courses listed below!
You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
Open the Power BI file in the above folder:
At the moment the matrix shows a dummy measure.
The SUMX function uses this syntax:
The table can be a table, or the set of rows returned from a FILTER function. We'll create examples of both types of syntax!
Use this information to create a measure called Sales, which should sum the price multiplied by the quantity. Show this measure in your matrix to give:
You should see a report showing total sales by purchase year and environment.
Copy the formula for this measure, and use this as a basis to create a new measure called Sales in 2018. This measure should use the FILTER function to only sum sales where the year for the purchase date is 2018.
You can use the YEAR function to return the year corresponding to any date.
Show this measure in the matrix to get the following;
The matrix collapses, as there are only figures for 2018.
Now copy the formula for this measure again and amend it to create another measure called Big sales 2018, which only sums sales where:
- The purchase year is 2018; and
- The quantity of goods bought for a purchase was 5 or more.
This should give the following table:
The figures are falling, as we filter out more purchases.
You can use the AND function, the && operator or nested FILTER functions to achieve this - the choice (as Graham used to say) is yours!
Save this file as Special measures, then close it down.
big sales = CALCULATE([total sales],FILTER('Purchase',AND(YEAR('Purchase'[PurchaseDate])=2018,Purchase[Quantity]>5)=TRUE()))
total sales = sumx('Purchase','Purchase'[Quantity]*Purchase[Price])
Why is this not working?