LASTDATE

How to Use the Power BI DAX function LASTDATE

What is the LASTDATE Function?

The LASTDATE function is a DAX function in Power BI that returns the latest date in a column or table. This function is useful in situations where you want to filter your data based on the latest date. It is commonly used in time intelligence calculations in Power BI.

Syntax of the LASTDATE Function

The syntax of the LASTDATE function is as follows:


LASTDATE(❰column❱)


Where `❰column❱` is the column or table that you want to get the latest date from.

How to Use the LASTDATE Function

To use the LASTDATE function in Power BI, you first need to create a measure. Here's an example of how to create a measure that uses the LASTDATE function:

1. Open your Power BI report and go to the "Modeling" tab.

2. Click on "New measure" in the "Calculations" group.

3. In the formula bar, type in the following formula:


LatestDate = LASTDATE(‘Table'[Date])


In this example, we're creating a measure called "LatestDate" that gets the latest date from a column called "Date" in a table called "Table".

4. Press "Enter" to create the measure.

You can now use the LatestDate measure in your Power BI visuals. For example, you can create a card visual that shows the latest date in your data set.

Using the LASTDATE Function with Other Functions

The LASTDATE function can be combined with other functions in Power BI to create more complex calculations. Here are some examples:

Calculate the Number of Days Between Today and the Latest Date

You can use the TODAY function and the LASTDATE function to calculate the number of days between today and the latest date in your data set. Here's an example formula:


DaysSinceLatestDate = DATEDIFF(LASTDATE(‘Table'[Date]), TODAY(), DAY)


In this formula, we're using the DATEDIFF function to calculate the difference between the latest date and today's date in days.

Filter a Visual to Show Data for the Latest Date

You can use the FILTER function and the LASTDATE function to filter a visual to show data for the latest date in your data set. Here's an example formula:


LatestSales = CALCULATE(SUM(‘Table'[Sales]), FILTER(‘Table’, ‘Table'[Date] = LASTDATE(‘Table'[Date])))


In this formula, we're using the CALCULATE function to sum the sales for the latest date in the "Table" table. We're using the FILTER function to filter the "Table" table to only show data for the latest date.

The LASTDATE function is a powerful tool in Power BI that can help you determine the latest date in your data set. You can use it in combination with other DAX functions to create more complex calculations and filter your visuals to show data for the latest date. By using the LASTDATE function, you can gain valuable insights into your data and make better 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)