Power BI DAX PREVIOUSYEAR

The Power BI PREVIOUSYEAR function is one of the DAX Date and Time functions useful to return a table that contains all previous year dates based on the given date. The syntax of the PREVIOUSYEAR function is shown below. The year_end_argument argument is an optional string literal that defines the year-end date. By default, it is 31 December.

PREVIOUSYEAR(<dates>, <year_end_argument>)

Power BI DAX PREVIOUSYEAR function Example

To demonstrate the PREVIOUSYEAR() function, click the New Table button on the Modeling Tab and rename it as PREVIOUSYEAR. The below expression uses the FactInternetSales table as the reference. Next, it will create a table of all dates from the previous year based on the OrderDate column.

PREVIOUSYEAR =  PREVIOUSYEAR(FactInternetSales[OrderDate]

The below Power BI DAX PREVIOUSYEAR function expression creates a simple measure that will calculate and show the sum of the Sales Amount of the previous OrderDate year in the FactInternetSales table. Please refer to the DAX YEAR and DAX NEXTYEAR functions.

To compare both present year sales against the previous and next year’s sales, we have added the OrderDate, Sales Amount, and the sum of the previous year’s sales to the table report. For the remaining charts, visit the Power BI Charts article.

PreviousYearSales = CALCULATE(SUM(FactInternetSales[SalesAmount]), PREVIOUSYEAR(FactInternetSales[OrderDate]))
POWER BI DAX PREVIOUSYEAR Function 1

Similarly, the following DAX formula calculates the previous year’s sales sum based on the calendar table. This table was generated by the DAX CALENDAR function. Please refer to the list of Power BI DAX Date functions and the Power BI DAX functions article available on the Power BI tutorial page for the remaining methods.

PreviousYearCalSale = CALCULATE(SUM(FactInternetSales[SalesAmount]), PREVIOUSYEAR(CalendarTable[Date]))
PREVIOUSYEAR Function 2