Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
46 | |
25 | |
19 | |
16 | |
8 |
User | Count |
---|---|
65 | |
50 | |
45 | |
20 | |
17 |