Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Hi,
If you could please help me out with this error:
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.
Solved! Go to Solution.
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!
Sorry, I mentioned that the Previousmonth formula returned a blank result; actually the result is zero.
CALCULATE( [Sales count],
PREVIOUSMONTH( Calendar[Date] ) )
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!
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
23 | |
21 | |
20 | |
13 | |
12 |
User | Count |
---|---|
43 | |
31 | |
24 | |
23 | |
22 |