Forum Discussion
Dynamic Column visibility in table visual based on filter selection
In a power bi report, I have a single select country filter and a table visual.
The table visual consists of columns A,B,C,D
When country filter is set to India or Ausralia
I want to show A,B,C,D columns in the table visual.
When country filter is set to USA or Canada
I want to show A,B,C,D,E,F,G columns in the table visual.
Is this possible by any workaround?
Appreciate for your help
Hi Manish1198
To implement dynamic column visibility based on a country selection, use Field Parameters combined with a Measure-based filter. This approach requires a dedicated Dimension Table for countries to ensure reliable filtering and avoid circular dependencies.
1. Data Model Prerequisite
Ensure your model follows a Star Schema:Dim_Country: A table containing unique country names.
Fact_Table: Your primary data table (Columns A–G).
Relationship: A 1:N relationship from Dim_Country[Country] to Fact_Table[Country].
2. Create the Field Parameter
Navigate to Modeling > New Parameter > Fields.Select columns A, B, C, D, E, F, and G.
Name the parameter (e.g., DynamicColumns).
This creates a table with an index for each column (0 to 6).
3. Create the Visibility Measure
Create the following DAX measure to control which fields remain visible based on the slicer selection:קטע קוד
ColumnVisibility =
VAR SelectedCountry = SELECTEDVALUE('Dim_Country'[Country])
VAR CurrentFieldIndex = SELECTEDVALUE('DynamicColumns'[DynamicColumns Order])
RETURN
IF(
ISFILTERED('Dim_Country'[Country]),
SWITCH(TRUE(),
SelectedCountry IN {"India", "Australia"} && CurrentFieldIndex <= 3, 1,
SelectedCountry IN {"USA", "Canada"} && CurrentFieldIndex <= 6, 1,
0
),
1 -- Default view if no country is selected
)
4. Configure the Visual
Add a Slicer using Dim_Country[Country].Select your Table Visual.
Remove the original columns and add the Field Parameter (DynamicColumns) as the Values.
In the Filters Pane, drag the ColumnVisibility measure into "Filters on this visual".
Set the filter to "is 1" and click Apply filter.
Why this method is optimal:
Performance: Field Parameters are native objects that do not require the overhead of Bookmarks or multiple overlapping visuals.Scalability: If new countries or columns are added, you only need to update the SWITCH logic in the DAX measure.
Integrity: Using a separate Dim_Country table prevents SELECTEDVALUE from returning blank results due to multiple rows in the fact table.
You can also refer to the linked post with similar scenario:
The author of the solution also attached the pbix there.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
Hi Manish1198
You can actually add an extra column to a field parameter table to group the fields into. The fields can have more than one views. You can then use this view column to control the visibility of the fields.
Let report readers use field parameters to change visuals
7 Replies
- danextianSuper User
Hi Manish1198
You can actually add an extra column to a field parameter table to group the fields into. The fields can have more than one views. You can then use this view column to control the visibility of the fields.
Let report readers use field parameters to change visuals
- Ritaf1983Super User
Hi Manish1198
To implement dynamic column visibility based on a country selection, use Field Parameters combined with a Measure-based filter. This approach requires a dedicated Dimension Table for countries to ensure reliable filtering and avoid circular dependencies.
1. Data Model Prerequisite
Ensure your model follows a Star Schema:Dim_Country: A table containing unique country names.
Fact_Table: Your primary data table (Columns A–G).
Relationship: A 1:N relationship from Dim_Country[Country] to Fact_Table[Country].
2. Create the Field Parameter
Navigate to Modeling > New Parameter > Fields.Select columns A, B, C, D, E, F, and G.
Name the parameter (e.g., DynamicColumns).
This creates a table with an index for each column (0 to 6).
3. Create the Visibility Measure
Create the following DAX measure to control which fields remain visible based on the slicer selection:קטע קוד
ColumnVisibility =
VAR SelectedCountry = SELECTEDVALUE('Dim_Country'[Country])
VAR CurrentFieldIndex = SELECTEDVALUE('DynamicColumns'[DynamicColumns Order])
RETURN
IF(
ISFILTERED('Dim_Country'[Country]),
SWITCH(TRUE(),
SelectedCountry IN {"India", "Australia"} && CurrentFieldIndex <= 3, 1,
SelectedCountry IN {"USA", "Canada"} && CurrentFieldIndex <= 6, 1,
0
),
1 -- Default view if no country is selected
)
4. Configure the Visual
Add a Slicer using Dim_Country[Country].Select your Table Visual.
Remove the original columns and add the Field Parameter (DynamicColumns) as the Values.
In the Filters Pane, drag the ColumnVisibility measure into "Filters on this visual".
Set the filter to "is 1" and click Apply filter.
Why this method is optimal:
Performance: Field Parameters are native objects that do not require the overhead of Bookmarks or multiple overlapping visuals.Scalability: If new countries or columns are added, you only need to update the SWITCH logic in the DAX measure.
Integrity: Using a separate Dim_Country table prevents SELECTEDVALUE from returning blank results due to multiple rows in the fact table.
You can also refer to the linked post with similar scenario:
The author of the solution also attached the pbix there.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
- Manish1198Helper I
Thanks, this works as expected.
Does this setup remove the ability to have totals displayed for a numeric column. Because when I enable the totals, I don't see them. The totals row is missing.- Manish1198Helper I
This is resolved. We need to use the measures here instead of the the numeric columns directly
- parry2kSuper User
Manish1198 well, one way to do this is to create explicit measures for each column, filter measures based on country, and use these measures instead of columns. It is not a pretty solution, but it will get over the line.
- parry2kSuper User
Manish1198, do all the columns have some aggregation like sum, avg, in other words, are these numeric columns?