Home » DAX » DAX – PREVIOUSMONTH Function

DAX – PREVIOUSMONTH Function

PREVIOUSMONTH DAX function

Returns a table that contains a column of all dates from the previous month, based on the first date in the dates column, in the current context.

It comes under Time & Intelligence Dax function Category.

Syntax:

PREVIOUSMONTH(<dates>)




Description:

Dates – A column with dates.

Note:

This function returns all dates from the previous month, using the first date in the column used as input.

For example, if the first date in the dates argument refers to Sept 13, 2020, this function returns all dates for the month of Aug, 2020.

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(Orders[Order Date]),
MAX(Orders[Order Date]))

Step-2: Now, create a measure to get Previous Month Sale.

PREVIOUSMONTH = 
CALCULATE(SUM(Orders[Sales]),
PREVIOUSMONTH('Calendar'[Date]))

Step-3: Drag Date Column from Calendar table & Sales from Order Table.

Previous Month

Previous Month




What happen if you will use date instead of Month?

Now, Drag complete date column from calendar table instead of only moth.
PreviousMonth DAX -2

PreviousMonth DAX -2

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

Recommended Post : PREVIOUSDAY 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.

1 thought on “DAX – PREVIOUSMONTH Function”

  1. Hi DAX team,

    This is pretty handy. I tried and it worked.

    I have a question, why cannot use order date column in order table? Why the calendar table is necessary?

    Regards,
    Tony

Leave a Reply