Forum Discussion
Sales Prior Year
I'm trying to get Sales Prior Year (see below). Sales Prior Year is the monthly sales for May of 2019. I need to get this in addition to Current Month Sales on the same report and in the same visual so I've been trying a variety of measures but most are similar to
This isn't working BTW. Also I need for the date range to be dynamic based on the current date.
4 Replies
- Greg_DecklerCommunity Champion
So for time intelligence functions to work, you generally need a separate Calendar table. And you would use SAMEPERIODLASTYEAR like:
PY = CALCULATE([CurrentYear],SAMEPERIODLASTYEAR('Calendar'[Date]))
But if it frustrates you to no end. See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.
https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TITHW/m-p/434008 - v-alq-msftCommunity Support
Hi, mikeoshields
Based on your description, I created data to reproduce your scenario.
Table:
You may create calculated columns and measures as below.
Calculated column: Year = YEAR('Table'[Date]) Month = MONTH('Table'[Date]) Year-Month = FORMAT('Table'[Date],"yyyy-mm") Measure: CurrentMonth Sales = var _year = SELECTEDVALUE('Table'[Year]) var _month = SELECTEDVALUE('Table'[Month]) return CALCULATE( SUM('Table'[Sales]), FILTER( ALLSELECTED('Table'), YEAR('Table'[Date]) = _year&& MONTH('Table'[Date]) = _month ) ) LastMonth Sales = var _year = SELECTEDVALUE('Table'[Year]) var _month = SELECTEDVALUE('Table'[Month]) return IF( _month = 1, CALCULATE( SUM('Table'[Sales]), FILTER( ALLSELECTED('Table'), YEAR('Table'[Date]) = _year - 1&& MONTH('Table'[Date]) = 12 ) ), CALCULATE( SUM('Table'[Sales]), FILTER( ALLSELECTED('Table'), YEAR('Table'[Date]) = _year&& MONTH('Table'[Date]) = _month - 1 ) ) ) LastYearMonth Sales = var _year = SELECTEDVALUE('Table'[Year]) var _month = SELECTEDVALUE('Table'[Month]) return CALCULATE( SUM('Table'[Sales]), FILTER( ALLSELECTED('Table'), YEAR('Table'[Date]) = _year-1&& MONTH('Table'[Date]) = _month ) )Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- v-alq-msftCommunity Support
Hi, mikeoshields
If you take the answer of someone, please mark it as the solution to help the other members who have same problems find it more quickly. If not, let me know and I'll try to help you further. Thanks.
Best Regards
Allan
- v-alq-msftCommunity Support
Hi, mikeoshields
If you want to calculate Sales Prior Year based on today, you may try the following steps.
Table:
You may create two measures as below.
CurrentYearMonth Sales = CALCULATE( SUM('Table'[Sales]), FILTER( ALL('Table'), YEAR('Table'[Date]) = YEAR(TODAY())&& MONTH('Table'[Date]) = MONTH(TODAY()) ) ) LastYearMonth Sales = CALCULATE( SUM('Table'[Sales]), FILTER( ALL('Table'), YEAR('Table'[Date]) = YEAR(TODAY())-1&& MONTH('Table'[Date]) = MONTH(TODAY()) ) )Result:
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.