EARLIEST

How to Use the Power BI DAX function EARLIEST

EARLIEST is a powerful DAX function that allows you to return the first value for a given column within a specified context. In this article, we’ll explore how to use the EARLIEST function in Power BI to gain valuable insights into your data.

Understanding the EARLIEST Function

The EARLIEST function is used to retrieve the first value in a column that is related to a specific context. For example, let’s say you have a table of sales data that includes the date and revenue for each transaction. You could use the EARLIEST function to retrieve the first date for each customer, which could be useful for analyzing customer behavior over time.

The syntax for the EARLIEST function is as follows:


EARLIEST(❰column❱, [❰filter❱])


The first parameter is the column for which you want to retrieve the first value. The second parameter, which is optional, is a filter that restricts the context for the calculation.

Examples of Using EARLIEST

Let's look at a few examples of how to use the EARLIEST function in Power BI.

Example 1: Retrieving the First Date for Each Customer

Suppose you have a table of sales data that includes the following columns:

- Customer ID

- Date

- Revenue

You want to retrieve the first date for each customer, which could be useful for analyzing customer behavior over time.

To do this, you would create a new measure and use the EARLIEST function as follows:


First Purchase Date = EARLIEST(Sales[Date],Sales[Customer ID])


This formula retrieves the earliest date in the Sales[Date] column that is related to the current context of the Sales[Customer ID] column.

Example 2: Retrieving the First Date for Each Product

Suppose you have a table of sales data that includes the following columns:

- Product ID

- Date

- Revenue

You want to retrieve the first date for each product, which could be useful for analyzing product performance over time.

To do this, you would create a new measure and use the EARLIEST function as follows:


First Purchase Date = EARLIEST(Sales[Date],Sales[Product ID])


This formula retrieves the earliest date in the Sales[Date] column that is related to the current context of the Sales[Product ID] column.

Example 3: Retrieving the First Date for All Transactions

Suppose you have a table of sales data that includes the following columns:

- Transaction ID

- Date

- Revenue

You want to retrieve the first date for all transactions, regardless of customer or product.

To do this, you would create a new measure and use the EARLIEST function as follows:


First Purchase Date = EARLIEST(Sales[Date])


This formula retrieves the earliest date in the Sales[Date] column, without any additional filters.

The EARLIEST function is a powerful tool for retrieving the first value for a given column within a specified context. By using EARLIEST in your DAX formulas, you can gain valuable insights into your data and make more informed business decisions.

Power BI DAX Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)