560 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 two 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. |
To get this example to work, first bring the PosDate column from the Pos table into the Transaction table:
Use the RELATED function to bring the point-of-sale date for each transaction into the transactions table.
When travelling, it helps to keep the destination in sight. Here's what we want to achieve:
We'll create a new column giving the cumulative quantity (although this makes more sense if you sort the transactions by date, as below).
If you sort the transactions into date order, the figures make more sense:
Because the database doesn't record the time of the transaction, figures for each day's sales are lumped together.
Here's a formula which would achieve this:
=SUMX (
FILTER (
'Transaction',
'Transaction'[PosDate] <= EARLIER ( 'Transaction'[PosDate] )
),
'Transaction'[Quantity]
)
That is, instead of summing the quantity for the current row's transaction, sum it instead across the set of those rows whose transactions take place on a date up to and including the transaction date for the current row.
Don't forget (I often do) that this has to be the formula for a calculated column, and not a measure. Because it's referring to the value of the PosDate for the current row, a measure would make no sense and would return an error.
Next up - ranking using EARLIER.
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.