Dynamically Change Fields in Visual With Field Parameter

Spread the love

Do you have a use case where you need to dynamically change what you see in a visual? Examples:

  • You would like to have a filter to choose what metric you see in a visual, e.g., Revenue or Costs, or # Units, or Profit Margin, etc.
  • You would like to have a filter where you can choose the breakdown of your metric, e.g., see Revenue by Product or Revenue by Sales Person, or Revenue by Company, etc.

To avoid creating multiple visuals and bookmarks, Field Parameters can help you to create such selections easily and quickly.

field parameters
Field Parameter Usage Example

Implementation Steps

  1. Enable the Field Parameters feature in Power BI Desktop (done once): 

  2. In your Power BI Desktop file, when all your data is uploaded, create a parameter: 

  3. Define the parameter name and add fields that you want to display dynamically in a visual: 
    Note: If you want to use measures, you can use only explicit measures (created by DAX formulas)!
  4. You will get a filter (slicer in Power BI terms) with this parameter, and you need to change its settings to “Single select” (that can be found under Visualization pane > Format visual tab > Visual > Slicer settings > Selection).
  5. The last step is to use this parameter in your visual. That’s it!

    Example output:

You can notice that even the visual title will change automatically depending on your selection in the slicer Select Breakdown, and you don’t need to do anything additional.

If you want to edit your parameter, for example, add another field, you can do that by editing the parameter’s DAX. When you create a Field Parameter, the table with the parameter name is created, and its code can look like this:

So, if you want to add a new field, e.g., Dates[Year], you can do that by simply adding a new row:

Note: if you want to see these examples in action, you can download the Field Parameters.pbix file.

Limitations

As always, there are some limitations:


Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *