cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Helper II

## Previous month not working

Hi,

I have a sales table (with sales of several years back) and the corresponding calendar table. All I need is the count of sales for the previous month.

So,

I created a measure for the count of sales, like

Sales count = COUNTROWS( Sales( SalesID ) )

I created the measure for the sales count previous month, like the following:

Sales count PM = CALCULATE( [Sales count],
DATEADD( Calendar[Date], -1, MONTH ) )

The result gives me the count of all sales of the table, ignoring the month filter, which is obviously incorrect.

Therefore, I experimented with the following alternative formula:

CALCULATE( [Sales count],
YEAR( Calendar[Date] ) = YEAR( TODAY() ),
MONTH( Calendar[Date] ) = MONTH( TODAY() ) -1 )

This time, the result turns out almost correct. But, the month of January does not show any value, because the formula restricts the year to the current year. BTW, I had to filter the year, because otherwise the result sums up the previous month of this year and all previous years too (for example, if the current month is October, the formula would count sales of September this year, and also from previous years).

Also, I experimented with the PREVIOUSMONTH function, which always returns a blank result.

Am I doing something wrong with the Dateadd function?

Thank you and regards.

1 ACCEPTED SOLUTION
Helper II

Wow, I just solved it! (sorry for bothering you, ...good for me)

The reason why the previous month formula returned a zero value is because I needed to give it the today parameter in the filter. Forgot to mention that I displayed the value in a card (not a table). When I apply a filter to the card so as date = today, then the correct value comes up.

Must be very basic for the most of you, but I am so glad to have solved it!

2 REPLIES 2
Helper II

Sorry, I mentioned that the Previousmonth formula returned a blank result; actually the result is zero.

CALCULATE( [Sales count],
PREVIOUSMONTH( Calendar[Date] ) )

Helper II

Wow, I just solved it! (sorry for bothering you, ...good for me)

The reason why the previous month formula returned a zero value is because I needed to give it the today parameter in the filter. Forgot to mention that I displayed the value in a card (not a table). When I apply a filter to the card so as date = today, then the correct value comes up.

Must be very basic for the most of you, but I am so glad to have solved it!