Forum Discussion
Dynamic Column visibility in table visual based on filter selection
- 4 months ago
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
- 4 months ago
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
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