Remove Columns That Contain All Nulls From Pivot Table

Comments

3 comments

  • Avatar
    Moti Granovsky

    This would be awesome as a plugin, with a custom menu item to toggle this behavior on and off!

    0
    Comment actions Permalink
  • Avatar
    Dot Q

    What about for values that are 0s? In other BI tools, when values don't exist, no column is created. However, I'm getting columns from calculations I've created that just have running 0s. Instead, I would like to hide them. How would I do that? Thank you!

    0
    Comment actions Permalink
  • Avatar
    Moti Granovsky

    With 0s, the method above won't work because it relies on the jQuery .text() method which returns a single string of the combined text of all matching elements. If the entire column is blank, this text will also be blank, however with 0s it will end up like "0 0 0 0 0 0..." corresponding to the number of rows in the view.

    To change this script to hide all-0 columns as well, you can instead use the jQuery "filter" method on the list of cells, with a function to evaluate if a given cell has content according to your specifications. Then if none are found, implying that no cells in the column have what you consider a valid value, you can hide the column.

    I would add that the above implementation will benefit from limiting the scope of the initial jQuery selector to the widget element, otherwise it will select all column headers on the page, including for other pivots, which can cause undesired behavior.

    1
    Comment actions Permalink

Please sign in to leave a comment.