Home » DAX » DAX – PREVIOUSYEAR Function

DAX – PREVIOUSYEAR Function

PREVIOUSYEAR DAX function

Returns a table that contains a column of all dates from the previous year, given the last date in the dates column, in the current context.

It comes under Time Intelligence DAX function category.

Syntax:

PREVIOUSYEAR(<dates>,<year_end_date>)




Description:

S no. Parameter Description
1 Date A column containing dates.
2 year_end_date (optional) A literal string with a date that defines the year-end date. The default is December 31.

Note:

This function returns all dates from the previous year given the latest date in the input parameter.

For example, if the latest date in the dates argument refers to the year 2020, then this function returns all dates for the year of 2019, up to the specified year_end_date.

So, Let’s start with an example, download the sample Dataset from below link

Step-1: Create a calendar table to using existing dataset “Order Date” column.

Go to Modeling Tab > Click to table icon & write below DAX

Calendar = 
CALENDAR(MIN('Global-Superstore'[Order Date]), 
MAX('Global-Superstore'[Order Date]))





Step-2: After that create a relationship between both table.

Relationship

Step-3: Now, create a measure to get Previous year Sale.

PREVIOUSYEAR =
CALCULATE(SUM('Global-Superstore'[Sales]),
PREVIOUSYEAR('Calendar'[Date]))





Step-4: Drag Year Column from Calendar table & Sales from Global-Superstore.

PREVIOUSYEAR DAX - 1

PREVIOUSYEAR DAX – 1

What happen if you will use date instead of Year?

Now, Drag Year & date column from calendar table instead of only Year.

PREVIOUSYEAR DAX - 2

PREVIOUSYEAR DAX – 2

As you see in above screen shot, it will return total sum of previous year sales against current year each dates, here previous year was 2011 and current year is 2012.

Recommended Post : PREVIOUSDAY DAX Function , PREVIOUSMONTH DAX Function

Hope you enjoyed the post. Your valuable feedback, question, or comments about this post are always welcome or you can leave us message on our contact form , we will revert to you asap.



Leave a Reply