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
Anonymous
Not applicable

Slicer autoselecting

Hi,

 

I have the following situation:

 

A slicer which let you select "object", these objects have a "time":

Capture2.PNG

Now what I am trying to achieve is that when you click "object A" in the slicer the slicer will automatically remove all other options except for the "object" that is closest to "object A" in terms of "time", in this example this would be "object B". Another example is when you click on "object C" it will again only let you choose the closest one in "time" which is "object D".

(note that when I say closest I mean the closest one that is a higher value than the one selected)

 

Thanks in advance !

2 REPLIES 2
Eric_Zhang
Microsoft Employee
Microsoft Employee


@Anonymous wrote:

Hi,

 

I have the following situation:

 

A slicer which let you select "object", these objects have a "time":

Capture2.PNG

Now what I am trying to achieve is that when you click "object A" in the slicer the slicer will automatically remove all other options except for the "object" that is closest to "object A" in terms of "time", in this example this would be "object B". Another example is when you click on "object C" it will again only let you choose the closest one in "time" which is "object D".

(note that when I say closest I mean the closest one that is a higher value than the one selected)

 

Thanks in advance !


@Anonymous

You can create a calculated table and a measure as below. See more details in the attached pbix.

SlicerTable = VALUES('Table'[Object]) 

isShown = VAR Tbl1 = SUMMARIZE ( FILTER ( ALL ( 'Table' ), 'Table'[Time] >= CALCULATE ( MAX ( 'Table'[Time] ), FILTER ( ALL ( 'Table' ), 'Table'[Object] = LASTNONBLANK ( SlicerTable[Object], "" ) ) ) ), 'Table'[Object], "time", MAX ( 'Table'[Time] ) ) VAR Tbl2 = ADDCOLUMNS ( Tbl1, "rank", RANKX ( Tbl1, [time],, ASC, DENSE ) ) VAR Top2 = FILTER ( Tbl2, [rank] <= 2 ) RETURN IF ( ISFILTERED ( SlicerTable[Object] ) && HASONEVALUE ( SlicerTable[Object] ) && CONTAINS ( Top2, 'Table'[Object], LASTNONBLANK ( 'Table'[Object], "" ) ), 1, BLANK () )

Capture.PNG

 

 

 

Anonymous
Not applicable

Hi @Eric_Zhang,

 

I can't get your formula to work since the value "Time" I spoke of was a measure not a normal column. Sorry it is stupid of me that I forgot to mention this detail. The measure looks something like this:

Time = MAX(table[avgTimePoint]) - MIN(table[avgTimePoint])

 

Now when I try to create "column" like in your example PBIX I get the message: "Column "Time" in table 'table' cannot be found or may not be used in this expression.

 

Another question I have about your formula is, in the calculated column you use:  'Table'[Object]="C" why C because it is the middle one or ? I'd like to understand this since my actual file doesn't use A B C D E but other names for these objects(which are alot more then 5).

 

 Regards,

 

L. Meijdam

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.