cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
byggarebob
Regular Visitor

Variable filter range based on slicer single selection

Hi,

 

I'm building a report which will be used on an Ipad and I want to minimize the number of slicer selections needed for the user to make it more user friendly. I have a year slicer with single selection and I want to keep it that way.

 

I have a line chart where I want to show the selected year AND the year before. Problem is obviously with the single selection slicer. There is a "periodic table" that I use for all calendar dimensions and this is the source of the Year slicer in the report (this slicer is disconnected from the chart in question). In this periodic table I have created the following measures to try to solve the problem:

 

Selected year = SELECTEDVALUE(Periodic_table[Year])       <-  collecting the year selected in the slicer

Prior year = [Selected year]-1

 

Filter = IF(

    VALUES(Periodic_table[Year])>=[Prior year] && VALUES(Periodic_table[Year]) <= [Selected year],
    1,0)
 
I put the Filter measure as a filter in the chart and set it to only include "1". However, the chart does not seem to respond to this filter, all years are currently shown in the chart. (When I set the filter to "0" all lines disappear from the chart)
 
The chart looks like this and has the following settings:
Month and year comes from the periodic table and the data (POS visit) comes from a parameter table.
 
byggarebob_0-1675344684931.pngbyggarebob_1-1675344734076.png

 

byggarebob_2-1675344898189.png

 

I hope its somewhat easy to follow! 😄

 

Would highly appreciate any help here.

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@byggarebob , Based on what I got

 

In such a case slicer, need to be on an independent year/date table and then you can have measure like

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Year])
var _min = _max -1
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Year] >=_min && 'Date'[Year] <=_max))

 

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI



!! Microsoft Fabric !!
Microsoft Power BI Learning Resources, 2023 !!
Learn Power BI - Full Course with Dec-2022, with Window, Index, Offset, 100+ Topics !!
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@byggarebob , Based on what I got

 

In such a case slicer, need to be on an independent year/date table and then you can have measure like

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Year])
var _min = _max -1
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Year] >=_min && 'Date'[Year] <=_max))

 

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI



!! Microsoft Fabric !!
Microsoft Power BI Learning Resources, 2023 !!
Learn Power BI - Full Course with Dec-2022, with Window, Index, Offset, 100+ Topics !!
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!

Your suggested solution worked! I only had to add a slicer linked to year in the independent date table and then sync that slicer to the "year"-slicer of the main date table. Thanks alot!

Helpful resources

Announcements
May 2023 update

Power BI May 2023 Update

Find out more about the May 2023 update.

Submit your Data Story

Data Stories Gallery

Share your Data Story with the Community in the Data Stories Gallery.

Top Solution Authors