557 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 three 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. |
A previous blog showed how you can rank data in DAX using the RANKX function; this page gives an alternative method, using EARLIER.
We'll rank the products by their list price. As we've seen in earlier blogs, The Emperor is the most expensive and Wol the cheapest.
Here's a formula for the calculated column (not a measure, don't forget!) to achieve this:
=COUNTROWS(
FILTER(
Product,
EARLIER([FullPrice])<[FullPrice]
)
)+1
To see how this works, consider the example of the first product in alphabetical order, Crocky:
The FILTER function returns the table of products, but filtered to show only those ones where the current row's FullPrice (11.50) is less than the product's full price. This gives the blue-shaded products: Pingu, Simon and The Emperor. The formula then counts how many rows there are in this set of rows, and adds one to it (this is needed because we want the top ranking product to be 1, not 0 or blank).
The calculation above is for one product; the formula will then be repeated again for the other 12 products. Although this look like it does 13 x 13 calculations, the database engine will optimise them to avoid repetition where possible.
The next worked example is on calculating group averages.
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.