Frage

I have a pivot table based on PowerPivot with multiple levels in the Rows section. Quite a few of the elements are blank. Is there a way to suppress the blank rows?

My Pivot Table looks like this at the moment.

Product1
    Release 1
        Iteration 1
            (blank)
        Iteration 2
            (blank)
    Release 2
        (blank)
            (blank)
Product2
    (blank)
Product3
    Release 1
        Iteration 1
            Sprint 1
            (blank)
        (blank)
(blank)

This is what I want it to look like

Product1
    Release 1
        Iteration 1
        Iteration 2
    Release 2
Product2
Product3
    Release 1
        Iteration 1
            Sprint 1

That's just an example. I've tried to set filters for each level not to display blanks but if I filter each level to hide blank fields the pivot table doesn't have any items in it. It seems that Excel ends up filtering each level out that has ANY blank values.

Not sure if I made sense or provided enough information for troubleshooting. I'm pretty much brain dead at the moment so I apologize.

Please let me know if it doesn't make sense or if I can provide any additional information to clarify what I'm trying to do and encountering.

Thanks.

EDIT: Changed the code block to be more clear and added an "after" code block to show what I want to get to. I guess the issue is that the "depth" of the rows for the entire pivot table has to be equal. For example if I have 3 indents for the first item, the others must also show 3 levels of indent worth of data. If I hide blanks and that results in 1 indent worth of data for the first item, it will hide non-blanks for other items as well if they appear after 1 indent. Still not sure if that makes any sense :) I need some sleep.

War es hilfreich?

Lösung 2

I ended up using a Flattened PivotTable instead from the PowerPivot "Manage" screen instead. That seemed to do what I needed.

Andere Tipps

I think you should be able to check Show items with no data on rows and/or Show items with no data on columns in Display under PivotTable Options.

I needed to solve exactly the same problem, but wanted the the rows to be hidden automatically when the pivottable filtering was changed or the data was refreshed, so I wrote a function called from a 'Worksheet_PivotTableUpdate' event on the sheet holding the pivottable, although you could drive it off a button if you prefer I suppose. This initially did the job by scanning down each row in the pivottable, hiding it if it was visible and didn't need to be (as the row's first cell was '(blank)'), or showing it if it was hidden and shouldn't be, otherwise just leaving it hidden or visible as it was.

However, I found the function ran very slowly, so here's my next attempt, which initially un-hides all the rows in the pivottable, then goes and finds all the blank cells in the first column, adding them to a range object, then it hides the entire row for every cell in that range. This version works about ten times as fast :-)

Pass in the name of the sheet where the pivottable reside, the name of the pivottable and an optional string to look for in the rows that need to be hidden; this defaults to '(blank)' if not supplied by the calling function.

Apologies in advance if I fall foul of anybody's variable or function naming conventions (I'm only a hacker ;-))

Sub FixBlankPivotRowsV2(ByVal SheetName As String, ByVal PivotName As String, Optional HideDefn as String = "(blank)")
Dim CurrPivot As PivotTable
Dim CurrRow As Range
Dim BlankRange As Range        'NB This is where we'll build the range of things to hide, which will initially be Nothing, as we never initialise it.
Dim oldStatusBar As Boolean

'Show a nice message in the status bar
oldStatusBar = Application.DisplayStatusBar
Application.DisplayStatusBar = True
Application.StatusBar = "Hiding blank entries in " & SheetName & ", back in a sec..."
Application.ScreenUpdating = False

'Get the pivottable to work with        
Set CurrPivot = ActiveWorkbook.Sheets(SheetName).PivotTables(PivotName)

'Unhide all of the pivot rows first
CurrPivot.RowRange.Rows.EntireRow.Hidden = False

'Loop around each row in the pivottable
For Each CurrRow In CurrPivot.RowRange.Rows
    If CurrRow.Offset(0, 0).value = HideDefn Then
        If BlankRange Is Nothing Then
            'This is the first blank row we've found, so just set the range up to be the first cell of that range
            Set BlankRange = CurrRow.Offset(0, 0)
        Else
            'Add the newly found blank row to the range using a Union
            Set BlankRange = Union(BlankRange, CurrRow.Offset(0, 0))
        End If
    End If
Next

'Only hide things if there's anything to hide!
If BlankRange Is Nothing Then
    Debug.Print "Nothing to hide!"
Else
    BlankRange.EntireRow.Hidden = True
End If

'Set the status bar back the way it was
Application.ScreenUpdating = True
Application.StatusBar = False
Application.DisplayStatusBar = oldStatusBar
End Sub

I looked for a way to select all of the 'blanks' cells in the first column using one of the Go To Special type functions, but couldn't find anything that would fit the bill, so please let me know if you know how to do such a thing as it will speed this up even more.

I hope this helps somebody out there!

Try to select the a cell in the pivot table "blank" press delete button and press spacebar.

No idea why or how this works, but I sleclected one of the cells in the PivotTable that contained (blank), then hot spacebar. I then hit the return key, and all the (blank) cells in the same column went blank. Repeated this for the other columns in the table.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top