Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
eliasayyy
Memorable Member
Memorable Member

Create Dynamic Previous Result

hello everyone i am using timeline slicer custom visual with all granuality on from by day to by year.

i want to make a measure that will compare current vs previous based on selected date

so if i i am on the "By year" slicer , if i select 2023, i want to compare 2023 result to 2022 result ,
if i am on "By week" slicer , if i select week 3 of 2023 i want to compare to week 2 of 2023
if i am on "By month" slicer , if i select january 2023 i want to compare to december 2023

is this possible?

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

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:

vyueyunzhmsft_0-1682920150929.png

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.

vyueyunzhmsft_1-1682920850763.png

 

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

View solution in original post

1 REPLY 1
v-yueyunzh-msft
Community Support
Community Support

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:

vyueyunzhmsft_0-1682920150929.png

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.

vyueyunzhmsft_1-1682920850763.png

 

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.