Syntax
Table of contents:
- Explain the function
- Calculate the difference between two dates (in same column)
- Calculate the sum of subcategories (or categories)
1. Explain the function
Learn how to use the function EARLIER in DAX/ Powerpivot.
EARLIER is mostly used in the context of calculated columns.
The performance of EARLIER might be slow because it theoretically, it might have to perform a number of operations that is close to the total number of rows (in the column) times the same number (depending on the syntax of the expression). For example if you have 10 rows in the column, approximately a 100 operations could be required; if you have 100 rows then close to 10,000 operations might be performed.
Download example file:
To get the files:
1. Go to Curbal Download Center > Dax Fridays
2. Get File #13
Remarks
EARLIER succeeds if there is a row context prior to the beginning of the table scan. Otherwise it returns an error.
The performance of EARLIER might be slow because it theoretically, it might have to perform a number of operations that is close to the total number of rows (in the column) times the same number (depending on the syntax of the expression). For example if you have 10 rows in the column, approximately a 100 operations could be required; if you have 100 rows then close to 10,000 operations might be performed.
Example 2: Calculate the difference between two dates (in same column)
Do you know how to calculate the difference between dates when both are in the same column?
One example of when this is needed is when you are working with subscription based services. If you want to calculate how many dates go between users changing subscriptions, this DAX measure will help you.
To get the files:
1. Go to Curbal Download Center > Dax Fridays
2. Get File #85
Example 3: Calculate the sum of subcategories
Let me show you how to calculate the sum of subcategories.
To get the files:
1. Go to Curbal Download Center > Dax Fridays
2. Get File #57

Example 4: Create an index based on multiple columns using DAX
Do you need to create an index based on multiple columns using DAX? Here is a detailed guide on how to do it.
Leave a Reply