Forum Discussion
Hide/Show column dynamically depending if the total equals zero
Hi,
I have a table inside Power BI where two columns total to $0.00. I would like to hide those two columns if/when the totals equals to $0.00
Is that possible to do so in Power BI for the table visualization?
Thank you,
Hi brdrok
You cannot hide a measure that's been added to a viz even if that measure returns a blank but you can with a column category. You will need a disconnected table that has a column, containing the measure names, which you can create with DAX or M/Enter data like below:
Then write a measure that switches to different measures depending on the category value
MeasureSwitch = SWITCH ( SELECTEDVALUE ( _values[Measures] ), "Revenue", [Total Revenue], "Transactions", [Total Transactions], "Dummy", VAR __Dummy = -- apply the same value to all category rows CALCULATE ( [Dummy Measure], ALLSELECTED ( Category[Category] ) ) RETURN IF ( __Dummy <> 0, __Dummy ) )ALL/ALLSELECTED must be applied to all the fields added to the row tile.
Notice that the first matrix has a column and a single measure only while the second one doesnt have a column but has three measures.
Please see attached sample pbix.
- Anonymous1 year ago
Thanks for the reply from Irwan, please allow me to provide another insight.
Hi brdrok ,
It is unlikely to be possible to implement autohide columns in the table visualization.
This usually requires manual control of column hiding with the help of field parameters.However, this may be possible to realize in a matrix.
The test data table is as follows.
Create a calculation table that uses a column to contain the names of the columns that need to be dynamically hidden.Create two measures.
Result = SWITCH( SELECTEDVALUE(ColumnName[columns]), "Test1",SUM('Table'[Test1]), "Test2",SUM('Table'[Test2]), "Test3",SUM('Table'[Test3]) )Value = IF(CALCULATE([Result],ALL('Table'[Date]))=0,BLANK(),[Result])Create a matrix.
You can see that the format of the matrix is almost the same as the table visualization and that the columns with a Total of 0 are automatically hidden.Please see the attached pbix for reference.
Best Regards,
Dengliang Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
7 Replies
- danextianSuper User
Hi brdrok
You cannot hide a measure that's been added to a viz even if that measure returns a blank but you can with a column category. You will need a disconnected table that has a column, containing the measure names, which you can create with DAX or M/Enter data like below:
Then write a measure that switches to different measures depending on the category value
MeasureSwitch = SWITCH ( SELECTEDVALUE ( _values[Measures] ), "Revenue", [Total Revenue], "Transactions", [Total Transactions], "Dummy", VAR __Dummy = -- apply the same value to all category rows CALCULATE ( [Dummy Measure], ALLSELECTED ( Category[Category] ) ) RETURN IF ( __Dummy <> 0, __Dummy ) )ALL/ALLSELECTED must be applied to all the fields added to the row tile.
Notice that the first matrix has a column and a single measure only while the second one doesnt have a column but has three measures.
Please see attached sample pbix.
- AnonymousNot applicable
Thanks for the reply from Irwan, please allow me to provide another insight.
Hi brdrok ,
It is unlikely to be possible to implement autohide columns in the table visualization.
This usually requires manual control of column hiding with the help of field parameters.However, this may be possible to realize in a matrix.
The test data table is as follows.
Create a calculation table that uses a column to contain the names of the columns that need to be dynamically hidden.Create two measures.
Result = SWITCH( SELECTEDVALUE(ColumnName[columns]), "Test1",SUM('Table'[Test1]), "Test2",SUM('Table'[Test2]), "Test3",SUM('Table'[Test3]) )Value = IF(CALCULATE([Result],ALL('Table'[Date]))=0,BLANK(),[Result])Create a matrix.
You can see that the format of the matrix is almost the same as the table visualization and that the columns with a Total of 0 are automatically hidden.Please see the attached pbix for reference.
Best Regards,
Dengliang Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. - brdrokHelper I
Hi Anonymous and danextian . Sorry for the late response. Between being a newbie at Dax/Power BI and spending a "wonderful" afternoon at the dentist, it took me a little while to get the idea for the wonderful solutions. Tried both and I kinda got it to work. Still need to lear more but I got the idea. Is there a way to accept more than one solution?
- danextianSuper User
You should be able to accept multiple solutions.