Forum Discussion
Using PREVIOUSMONTH function to calculate previous month sales, able to filter the dates column
So looking through the syntax of PREVIOUSMONTH(dates) function, you would need to specify a dates column and it would return the previous month based on the first value of the dates column. Problem is, I have a "Year" slicer which selects current year, 2023, 2022, etc... and if I filter any of the years, the previousmonth function will return the number of sales in December of the prior year.
That is because the dates column is returning values from Jan 1-December 31 of the selected year, and the function will always base it on January 1 as that is the first value of the column and thus calculate December numbers.
Is there a way I can apply a filter on the previousmonth function, or somewhere in my measure?
I am using the USERELATIONSHIP function that links the sale date column with my date calendar.
We are in February right now, and the measure is still returning December 2023 numbers. If only I can apply a filter on the column that is being used in the previousmonth function, such as only start the first value from today's date? Is there a way to do this as I've used datesbetween and filter functions, and it does not return the correct values
- Anonymous2 years ago
Hi beepboop
Please try this:
First of all, I create a set of sample data:
Then create a measure:
Measure = IF( MONTH(TODAY()) - 1 = 0, CALCULATE( SUM('Table'[value]), FILTER( ALLSELECTED('Table'), MONTH('Table'[date]) = 12 && YEAR('Table'[date]) = YEAR(TODAY() - 1) ) ), CALCULATE( SUM('Table'[value]), FILTER( ALLSELECTED('Table'), MONTH('Table'[date]) = MONTH(TODAY()) - 1 && YEAR('Table'[date]) = YEAR(TODAY()) ) ) )The result is as follow:
Best Regards,
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 Replies
- AnonymousNot applicable
Hi beepboop
Please try this:
First of all, I create a set of sample data:
Then create a measure:
Measure = IF( MONTH(TODAY()) - 1 = 0, CALCULATE( SUM('Table'[value]), FILTER( ALLSELECTED('Table'), MONTH('Table'[date]) = 12 && YEAR('Table'[date]) = YEAR(TODAY() - 1) ) ), CALCULATE( SUM('Table'[value]), FILTER( ALLSELECTED('Table'), MONTH('Table'[date]) = MONTH(TODAY()) - 1 && YEAR('Table'[date]) = YEAR(TODAY()) ) ) )The result is as follow:
Best Regards,
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- beepboopFrequent Visitor
Is there a way to return only one calculate expression and do an IF expression within the dates itself? Such as CALCULATE(SUM(TABLE)), IF(MONTH()=....,FILTER(DATE)..,FILTER))
- Daniel29195
Community Champion
Sorry, i didnt quite understand what is the requirement,
if you are in feb 2023, what do you want your measure to return ?