Catching Multiple Slicer Selections in a Formula

A long time ago I did a post on using slicer selections in Excel formulas. That technique only worked when you select single values on slicers, though – any more than one and the dreaded “(Multiple items)” foils your well-laid plans.

How to handle that multi-select case became a very common question – in email and posted as comments.

Awhile back I responded privately to one of those requests but haven’t had time to post the solution. So here goes.

The Solution, Summarized

First, here’s a picture of the solution I came up with. For fun, see if you can figure out what I’m doing just by looking at it:

Everything in green is visible to the final report consumer (or at least, you can choose to make it so). Everything in grey is stuff you likely hide – either by hiding columns or by placing on a hidden sheet. The SKUID field is on the slicer (that is hooked to both pivots) and is also on the row axis of the hidden pivot, but is not included on the visible pivot.

Here’s the same spreadsheet, but zoomed in and with formulas visible:

I went ahead and uploaded this workbook so you can take a look in a hands-on manner.

Note that this was a PowerPivot workbook originally but I think I nuked all the data out of it, so you won’t be able to manipulate the pivots. No worries though – the formulas here are 100% of the technique and should work with any pivot.

I’m pretty sure I could simplify this a little bit if I tried, but probably not by much. I eagerly await everyone’s constructive input

Update, November 2012

I’ve since posted yet another way to do this that is probably the simplest I’ve personally used to date, and it handles multi select quite well too:

One of the founding engineers behind Power Pivot during his 14-year career at Microsoft, and creator of the world’s first cloud Power Pivot service, Rob is one of the foremost authorities on self-service business intelligence and next-generation spreadsheet technology.

Hey Rob – I got this UDF a while ago from somewhere on the internets that concatenates a range of cells:

Function concat(useThis As Range, Optional delim As String) As String
' this function will concatenate a range of cells and return one string
' useful when you have a rather large range of cells that you need to add up
Dim retVal, dlm As String
retVal = ""
If delim = Null Then
dlm = ""
Else
dlm = delim
End If
For Each cell In useThis
If CStr(cell.Value) "" And CStr(cell.Value) " " Then
retVal = retVal & CStr(cell.Value) & dlm
End If
Next
If dlm "" And retVal "" Then
retVal = Left(retVal, Len(retVal) - Len(dlm))
End If
concat = retVal
End Function

Using this, you can setup a little function that concatenates the row label headers:

Because I have up to 8 slicers in my PowerPivots I like to save space and use a single formula based solution that limits the number of shown multiple selections to 4. Anything more and they get a “More than 4” message (obviously you can expand the formula to capture as many selections that make sense for the subject in question)
Here is a sample formula for the slicer Region_Name:
=IF(ISERROR(CUBERANKEDMEMBER(“PowerPivot Data”,Slicer_Region_Name,5)),IF(CUBERANKEDMEMBER(“PowerPivot Data”,Slicer_Region_Name,1)=”all”,”All Regions”,”Region(s): “&CUBERANKEDMEMBER(“PowerPivot Data”,Slicer_Region_Name,1))&IFERROR(“, “&CUBERANKEDMEMBER(“PowerPivot Data”,Slicer_Region_Name,2),””)&IFERROR(“, “&CUBERANKEDMEMBER(“PowerPivot Data”,Slicer_Region_Name,3),””)&IFERROR(“, “&CUBERANKEDMEMBER(“PowerPivot Data”,Slicer_Region_Name,4),””),”More than 4 Regions”)

Hi,
In the uploaded file, for Formula Series 2, for the first row, the formula should be =IF(S5=””,4,0), instead of =IF(S5=””,1,0). If you don’t make this change, and if only one slicer is selected, then the Output value returns a 0.
Nandita

Rob: Why don’t you just check if the first thing in your hidden pivot is the same as the last thing in your hidden pivot? Something like this:=IF(INDEX(A:A,COUNTA(A:A))A2,"Please select a single country","")

This solution may work for me in Excel 2010, but am now challenged with multiple interactive slicers. My goal is to have the MANUALLY selected filter results (from all slicers) appear on the top of my master pivot table report (in the report title).

My question is: Is there any way (preferably not VBA) to tell if a filter is being used. Like: if filter has an item selected then 1 else 0.

Here is my somewhat verbose attempt to create a one-cell solution with a title and the selected slicers using an array formula. I am still using Excel 2010 so I am not sure if this necessary with Excel 2013 and newer. It works for me. Let me know if you find any bugs.

The slicer values (from the report filters) are in the range B1:B3. You can use more or fewer. As noted before, it is an array formula, so make sure to enter with CTRL+SHIFT+ENTER.

UPDATE: I wrote the formula above to handle multiple slicers per Denise’s question but not multiple selections within a slicer (the original problem!). This is exactly what I need so the formula works for me but YMMV.

Denise, I think is the test you want:
=–IF($B$1″(All)”,TRUE)
or array format C+S+E
=–IF($B$1:$B$3″(All)”,TRUE) for range $B$1:$B$3 where the filter values are captured

P.S. – I don’t know how to lock my quote marks to ANSI 34 when posting. Left displays as 147 and right as 148 on this web page. When copying from this web page, make sure to replace all quote marks with ANSI 34 quote marks (Notepad works fine) before using these formulas in Excel.