Menu Close

Hiding Columns based on a multi-select Parameter

If you would like to show and hide certain columns in SSRS here is what you should do.

1. Hit the “Design” tab of the report.
2. Go to “Report” then from the drop down select “Report Properties”

3. Click on “Code” and paste the following:

”’ summary
”’ Return whether the passed column name has been selected
”’ in the multi-value parameter, whether it should be visible
”’ or not.
”’ end of summary
Public Shared Function IsColumnSelected(ByRef objMultiValueParam() As Object, ByVal strColumnName As String) As Boolean

‘ return whether the passed column name is in the multi-value
‘ parameter array
Return 0 < InStr(vbNullChar & Join(objMultiValueParam, vbNullChar) & _
vbNullChar, vbNullChar & strColumnName & vbNullChar)

End Function

4. Create a Parameter called “Show Columns” with the following Query:

SELECT ‘Column1’ AS [Label]
, 1 AS [Value]

UNION

SELECT ‘Column2’ AS [Label]
, 2 AS [Value]

UNION

SELECT ‘Column3’ AS [Label]
, 3 AS [Value]

UNION

SELECT ‘Column4’ AS [Label]
, 4 AS [Value]

Column1, Column2 etc. should be the names of your columns.

5. Under each column select the “Column Visibility…” and paste this expression.

=Not Code.IsColumnSelected(Parameters!ShowColumns.Value, “1”)

The expression example above is for Column1. For Column2 you will change it to this:

=Not Code.IsColumnSelected(Parameters!ShowColumns.Value, “2”)

So in short you have to 1st map the Columns with numbers that represent them and then in the expression for the column visibility to use the corresponding numbers (values).