563 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
How to use the EARLIER function in DAX to sort, group, band and accumulate data Part four of a five-part series of blogs |
---|
Although the EARLIER function in DAX is complicated, it's also very useful! This blog shows how the function works, and how to use it to create running totals, sort rows, create group statistics and divide data into bands.
This blog is part of our online SSAS Tabular tutorial; we also offer lots of other Analysis Services training resources. |
The worked example below shows how to calculate the average price of products by target gender:
What we're aiming for: showing the average price for each product by its target gender.
To get this case study to work, you'll first need to add the target gender table into your model:
You'll need to import this table into your model.
You'll also need to add the TargetGenderId column to the imported products table, and create a relationship between the Product and TargetGender tables:
Change the properties of the Product table to include the TargetGenderId column, and link the two tables together by this column. It's all good practice!
Finally, in preparation, display the TargetGenderName column within the Product table, using a RELATED function:
Create a calculated column to show the target gender within the products table.
Here's the formula to give the average price by target gender:
=AVERAGEX(
FILTER(
Product,
EARLIER([TargetGender])=[TargetGender]
),
[FullPrice]
)
To see how this works, consider the example of the first product, Crocky:
For Crocky, the FILTER function will return the set of rows shown here shaded: those for which the target gender equals this individual product's target gender. The formula will then take the average price from this set of rows.
The usual caveats apply: remember to create a calculated column and not a measure, and bear in mind that the database engine will calculate the results more efficiently than the above table would suggest.
Finally in this look at the EARLIER function, I'll show how to band rows together.
Parts of this blog |
---|
|
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2023. All Rights Reserved.