Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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?
Solved! Go to Solution.
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
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
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
16 | |
13 | |
12 | |
11 | |
11 |
User | Count |
---|---|
19 | |
14 | |
14 | |
11 | |
9 |