In this blog post, we'll take a look at the new "Field Parameters" and "Calculation Groups" features in Power BI and how to use them in both Power BI Desktop and Tabular Editor.
Power BI Options
To use the new Field Parameters and Calculation Groups features in Power BI Desktop, you must check the following boxes under “Preview features” in the Options menu: “Field Parameters” and “Model Explorer and Calculation Group Authoring.”.
Calculation Groups have been available for some time when using the Tabular Editor to develop your Semantic Model. To use field parameters, make sure the compatibility level is set to 1500 or higher.
Field Parameters
The advantage of Field Parameters is that you can let the user decide which dimension fields and/or measures should be displayed in a Power BI visual. Often, there is limited space on a canvas, and you don’t want to repeat the same visual over and over again with only a different measure or dimension. In that case, field parameters offer a solution. You can create a field parameter using “New Parameter Field,” as shown below.
The created field parameters can then be used in the desired Power BI visual, and to give the user the flexibility to choose which fields should be displayed in the visual, slicer visuals can be added to the report. As shown below, for example.
Field Parameters in Tabular Editor
When you create a Field parameter in Power BI Desktop, Power BI creates three fields with underlying DAX code, two of which are hidden. You can modify this DAX code later if you want to change or add a field. Currently, there is no “GUI” interface for modifying a parameter field. If you want to create a parameter field in Tabular Editor—since that’s where you maintain the model—you can copy the logic of those three fields, including their exact properties and the corresponding DAX code, into Tabular Editor. However, there’s an easier way, because on GitHub there’s also a script There is a feature that automatically creates a Parameter Field for you. By saving this as a macro, you can easily select the fields for which you want to create a Parameter Field.
Calculation Groups
Calculation Groups have been available for some time if you maintain the model using Tabular Editor, but they are now also available in Power BI Desktop and can be accessed in the “Model View” section. There is some overlap with Parameter Fields, because with Calculation Groups I can also create something similar to what’s shown above—specifying which measures I do or don’t want to see in my visual. However, this is only possible with measures and not with dimensions (data fields). Another drawback of Calculation Groups is that the model property “Discourage Implicit Measures” is set to “True.” This means that for numeric data fields in a Power BI report, you can no longer apply an aggregation (sum, max, etc.), and you must always create a measure in your model if you need a specific aggregation.
The advantage of Calculation Groups is that you can define time intelligence calculations—such as Year-to-Date (YTD) and Previous Year-to-Date (PYTD)—which can then be used for any measure, rather than having to create them separately for each measure. In Power BI Desktop, you can create a Calculation Group in the “Model View” section. The first calculation item, “New calculation item,” is created by default and, via the underlying DAX code, references the measure you’re using in the visual. In the example below, I’ve created “YTD” and “PYTD” as additional calculation items and renamed “New calculation item” to “Measure.”.
Based on the “Calculation group” I created, named “TimeCalculation,” I can now create a Slicer. In the example below, I’ve also created a matrix table that combines field parameters and a calculation group into a single visual. This allows me to determine which measure(s), dimensions, and calculations I want to see in the visual.
Conclusion
Adding field parameters and calculation groups can enhance a Power BI semantic model, ultimately allowing users viewing reports in view mode to dynamically select fields. Also, be aware that implicit measures can no longer be used with calculation groups.