Forum Discussion
Create Dynamic Previous Result
- 3 years ago
Hi , eliasayyy
According to your description, you are using the timeline slicer custom visual . And your dimension is Year,Month and week . And you want to select one and then get the comparsion of the current object and previous object.
Here are the steps you can refer to :
(1)This is my test data:For your need ,i recommend the 'Calendar' Table contains the all year's date.
Calendar = CALENDAR( DATE(2014,1,1), DATE(2016,12,31) )(2)Then we can create a measure like this:Measure = var _slicer = MAX('Calendar'[Date]) var _cur_year = YEAR(_slicer) var _pre_year = _cur_year -1 var _diff_year =SUM('Sales'[Sales])- CALCULATE( SUM('Sales'[Sales]) , YEAR('Calendar'[Date]) = _pre_year) var _curmonth = EOMONTH(_slicer ,-2)+1 var _diff_month = SUM('Sales'[Sales])- CALCULATE( SUM('Sales'[Sales]) , YEAR('Calendar'[Date])*100+ MONTH('Calendar'[Date]) = YEAR(_curmonth)*100+ MONTH(_curmonth) ) var _preweek = YEAR( _slicer-7)*100 + WEEKNUM(_slicer-7) var _diff_week = SUM('Sales'[Sales])- CALCULATE( SUM('Sales'[Sales]) , YEAR('Calendar'[Date])*100+ WEEKNUM('Calendar'[Date]) = _preweek ) var _count = COUNTROWS('Calendar') return IF(_count>300 , _diff_year , IF(_count>27 , _diff_month , _diff_week))(3)Then we can put this measure on the card visual and we can get the comparsion.
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi , eliasayyy
According to your description, you are using the timeline slicer custom visual . And your dimension is Year,Month and week . And you want to select one and then get the comparsion of the current object and previous object.
Here are the steps you can refer to :
(1)This is my test data:
For your need ,i recommend the 'Calendar' Table contains the all year's date.
Measure =
var _slicer = MAX('Calendar'[Date])
var _cur_year = YEAR(_slicer)
var _pre_year = _cur_year -1
var _diff_year =SUM('Sales'[Sales])- CALCULATE( SUM('Sales'[Sales]) , YEAR('Calendar'[Date]) = _pre_year)
var _curmonth = EOMONTH(_slicer ,-2)+1
var _diff_month = SUM('Sales'[Sales])- CALCULATE( SUM('Sales'[Sales]) , YEAR('Calendar'[Date])*100+ MONTH('Calendar'[Date]) = YEAR(_curmonth)*100+ MONTH(_curmonth) )
var _preweek = YEAR( _slicer-7)*100 + WEEKNUM(_slicer-7)
var _diff_week = SUM('Sales'[Sales])- CALCULATE( SUM('Sales'[Sales]) , YEAR('Calendar'[Date])*100+ WEEKNUM('Calendar'[Date]) = _preweek )
var _count = COUNTROWS('Calendar')
return
IF(_count>300 , _diff_year , IF(_count>27 , _diff_month , _diff_week))
(3)Then we can put this measure on the card visual and we can get the comparsion.
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly