Power BI Table with Dynamic Columns: Step-by-Step
In this article
You can create a Power BI table with dynamic columns by building a disconnected table of column names, writing a DAX measure that switches on the selected column, and placing that measure in a matrix or table visual. The result is a table whose columns change when a user picks a different field from a slicer, without editing the report.
What You'll Need
- Power BI Desktop (any current version). The steps below are for Desktop; the Power BI service can display the result but you build it in Desktop.
- A data model with at least one fact table and the fields you want to switch between.
- Basic familiarity with DAX measures and the Modeling tab.
Menu labels can differ slightly by version, device or region, so if a button name does not match exactly, look for the closest equivalent.
Step-by-Step
- Decide which columns should be dynamic. List the fields users will choose from, for example Region, Product Category, and Sales Channel. They should share a common data type or be safely convertible, because the measure will return different types depending on the selection.
- Create a disconnected table of column names. Go to Home > Enter Data and type a single-column table with one row per option, for example a column called ColumnName with values "Region", "Product Category", "Sales Channel". Name the table ColumnSelector. Do not relate it to any other table; it must stay disconnected so the slicer does not filter the fact table.
- Add a slicer for the selector. Select the ColumnSelector table and add a slicer visual using the ColumnName field. Set it to single select so only one column is active at a time.
- Write the switching measure. Create a new measure with DAX that reads the selected value and returns the matching aggregation. A typical pattern is: Replace the table and column names with your own. SELECTEDVALUE returns the single selected value and BLANK when nothing or more than one is selected.
- For numeric columns, aggregate instead of returning raw values. If the dynamic column is a number such as Sales Amount, wrap it in SUM or AVERAGE, for example
SUM( Sales[Sales Amount] ), and return a numeric result for every branch. Mixing text and numbers in one measure is possible but the visual will format the column as text, so keep the measure consistent. - Build the visual. Add a Matrix visual (or a Table visual). Put the row field you want to group by, such as Product, on Rows. Put the Dynamic Value measure in Values. The measure now shows the column the slicer points to.
- Test each option. Click through every value in the slicer and confirm the measure returns the right field and the totals look correct. Check a blank selection too; it should show blank rather than an error.
- Format and label. Rename the measure to something user-friendly, set its format string in the Modeling tab, and add a title or text box that tells users to pick a column from the slicer.
Common Mistakes
- Creating a relationship between the selector table and the fact table. That makes the slicer filter the data and can hide rows. Keep the selector disconnected.
- Using a calculated column instead of a measure. Calculated columns are evaluated at refresh and cannot react to a slicer. Dynamic columns need a measure.
- Forgetting SELECTEDVALUE returns BLANK when multiple items are selected. Either set the slicer to single select or handle multi-select with a different pattern.
- Mixing data types in one measure. Text and numeric branches cause inconsistent formatting and sorting. Keep each dynamic measure to one type.
- Expecting the measure to create real columns. It changes the values shown in one column; it does not add or remove physical columns from the model.
Tips
- Name the selector column clearly, such as "Choose a column", so the slicer reads well.
- Add a default by using COALESCE or an IF that returns a sensible field when SELECTEDVALUE is blank.
- If you need several dynamic columns at once, create one measure per slot and one selector table per slot, or use a field parameter instead.
- Field parameters (Modeling > New parameter > Fields) are the built-in way to let users switch fields in a visual; they are simpler than DAX switching when they fit the need.
- Keep the selector table small and hide it from report view if you only want the slicer visible.
Troubleshooting
If the measure shows blank for every selection, check that the slicer is bound to the selector table and that the text in the selector exactly matches the strings in the SWITCH statement, including spaces and case. If the visual errors, confirm every branch returns the same data type. If totals look wrong, check whether the slicer is filtering the fact table through an unintended relationship. If the slicer allows multiple selections and the measure goes blank, set the slicer to single select or rewrite the measure to handle multiple values. If the column header does not change, remember that a measure keeps its own name; use a dynamic title measure or a text box to show the selected field name.
Frequently Asked Questions
Can a Power BI table have columns that change automatically?
Not as physical columns. You can switch the values shown in a measure with a slicer, or use a field parameter to let users swap fields in a visual.
What is the difference between a measure and a field parameter for dynamic columns?
A measure uses DAX to return different values based on a selection. A field parameter is a built-in modeling feature that lets a visual change which field it uses. Field parameters are usually simpler; DAX measures give more control over formatting and logic.
Why does my dynamic measure return blank?
Usually the selector has no single selected value, the text does not match the SWITCH strings, or the slicer is filtering the fact table through a relationship it should not have.
Can I use dynamic columns in a matrix visual?
Yes. Put the grouping field on Rows and the dynamic measure in Values. The measure acts as one column whose contents change with the slicer.
Do dynamic columns work in the Power BI service?
Yes, once the report is published. Users interact with the slicer in the service or in the mobile apps, but the model and measures are built in Power BI Desktop.
Can I switch between text and numeric columns in one measure?
You can, but the column will format as text and sorting may be inconsistent. It is better to keep separate measures for text and numeric fields.