Desktop

Highlighted
Regular Visitor
Posts: 33
Registered: ‎06-08-2018

How to select previous month and use it to calculate the sales of last month

I have the following table:

 CodSale Sold Date 1 125 2018-05-10 2 100 2018-05-15 3 150 2018-05-20 4 50 2018-06-20 5 75 2018-06-25

I need to make a measure that returns me the following table:

 Month SoldLastMonth May 0 Jun 375 (Sum of sales May) Ago 125 (Sum of sales Jun)

I tried to use PREVIOUSMONTH and EDATE(Date; -1) but doesn't work.
I will use this measure on a graph to see "Month Over Month".

Accepted Solutions
Super Contributor
Posts: 1,195
Registered: ‎11-12-2018

Re: How to select previous month and use it to calculate the sales of last month

Have you got a Date table? Time intelligence functions are only guaranteed to work if you have a "complete" Date table.

If you don't, create one, place Month in rows of a matrix visual and this measure in values for the previous month sales:

```SoldPreviousMonth =
CALCULATE ( SUM ( CodSales[Sold] ); PREVIOUSMONTH ( CalendarTable[Date] ) )```

All Replies
Super User
Posts: 765
Registered: ‎09-16-2018

Re: How to select previous month and use it to calculate the sales of last month

in order to be able to use TIME INTELLIGENCE functions, you need to create a date dimension and link it to the fact tables:

Proud to be a Datanaut!

Super Contributor
Posts: 1,195
Registered: ‎11-12-2018

Re: How to select previous month and use it to calculate the sales of last month

Have you got a Date table? Time intelligence functions are only guaranteed to work if you have a "complete" Date table.

If you don't, create one, place Month in rows of a matrix visual and this measure in values for the previous month sales:

```SoldPreviousMonth =
CALCULATE ( SUM ( CodSales[Sold] ); PREVIOUSMONTH ( CalendarTable[Date] ) )```