A way to handle Field Parameters in DENEB
Nikolaos Christoforidis
Senior Power BI Developer | Data Visualization Expert | Six Sigma Yellow Belt | Greece
Anyone who has used DENEB quickly understands that the possibilities are endless: it is like unlocking a superpower for your Power BI reporting. A similar feeling exists for Field Parameters! However, combining the two can lead to challenges, such as Deneb visuals breaking when switching field parameters due to changing column names. In this article, I will demonstrate a solution to this problem by creating a static column with a consistent name, ensuring that Deneb visuals work seamlessly regardless of the selected field parameter.
So, let's use a very simple scenario: my dataset has three dimensions: Department, Language & Position, and a single measure [Metric] that counts something very important (can be anything you want, headcounts, KPIs, volumes, whatever).
Using Field Parameters
Field Parameters allow you to choose whatever grouping you want for your visuals. By leveraging Field Parameters, we can have the visual change to accommodate our choice. Assume we have the field parameter named "fpDimensions". When I click on the Department choice of the field parameter, the visual table displays the metric by Department. As soon as I click on Language, the visual changes and displays Language.
Creating the Deneb Visual
Let's use Deneb to visualize this table. For our example, I'll use a bar chart. The steps below also apply to any kind of Deneb visual.
I enter the deneb editor and start selecting from the default options for a bar chart. First I have to choose what is the category and the measure for the barchart; obviously it is "Department" and "Metric" respectively. Since my data only contain two columns at this point (Department & Metric, as in the teal screenshot above), I have no other options.
Great, now I have a visual representation of the data table as a bar chart:
Handling Field Parameter Changes
When you click on any other selection in the field parameter, except for "Department", the Deneb visual breaks and shows "undefined". This is because Deneb is set up for "Department" and cannot find any data for that, since we have chosen "Language". You can actually see the y-axis title still being "Department" in the visual.
领英推荐
Now, if you go to edit the visual again, you are greeted by an error dialogue: it says that the "department" field is not found and you have to remap it. The only choice now is "Language", and if you remap it the visual is shown correctly, with bars for every language. Of course, this is not the way to go and it would not work at all when published and various users start to interact with your report. We need something to overcome this issue.
You might have noticed that the reason deneb cannot render the visual after changing the field parameter selection, is the fact that it cannot find any data for the new column name. Field parameters go directly into the data and affect the column name with whatever name is used in the field parameter definition; you cannot change the way this works (at least I do not know of a way).
So, a solution might be to have a column with a static name that does not change when selecting a field parameter option, and the data values of that column should be the same as the field parameter's, as shown in the picture:
How can we achieve this? We need to author a DAX measure that checks what is the currently selected field parameter and in every row displays the value of the corresponding dimension. So, for example, when the field parameter is "Department" the measure, in every row, should return the value of the currently selected Department. The following code implements this:
Static =
VAR _selection =
MIN ( fpDimensions[fpDimensions] )
VAR _result =
SWITCH (
_selection,
"Language", MIN ( dimLanguage[Language] ),
"Position", MIN ( dimPosition[Position] ),
"Department", MIN ( dimDepartments[Vice President] )
)
RETURN
IF ( NOT ISBLANK ( [Metric] ), _result )
Having a column with a static name that contains the dimensioning values allows us to direct deneb to use that column as category. Then, even when we change the field parameter, there is no error and everything works smoothly:
Have you faced this particular problem with deneb and field parameters? Did you solve this in a different way? I'd love to hear about it.
I hope you find this useful and use it for your reporting needs!
#powerbi #deneb #fp #fieldparameters #dax #datamodeling #techtips
Principal Consultant @ Blueforte GmbH | Microsoft Solutions Partner for Data and AI | Microsoft Fabric, Microsoft Power BI, DevOps, DataOps, IBCS
8 个月I really like this solution, but the same problem occurs when your measures use translations in the model. Your Deneb visual will break, when the users language is not matching the language the visual was authored in. Sure it could be dealed with in a similar way: create an extra measure which just references the original translated version and use this in your visual. But looking at Daniel Marsh-Patrick: would it be possible to address fields/measures in Deneb by its underlying technical name? This would solve the problem for both scenarios, translations and field parameters, without using extra measures everytime. And another thought: does this work with visual calculations instead real measures? This would spare us from many many extra measures ;-)
Business intelligence & data visualisation | usually making stuff in/for #PowerBI | #Deneb & #HTMLContent owner/developer | MS data platform MVP
8 个月This article is extremely valuable for developers - thanks for the great write-up, Nikolaos! ?? Because Power BI renames the field in the visual dataset when a field parameter changes, it's tricky to handle them natively in Deneb. Historically, custom visuals haven't had a way to track this. In the latest release of the custom visuals API this month, MS has finally given us a way to identify whether a named field belongs to a parameter and what its name is, which will allow us to reconcile this within the visual ???? Because upgrading to the latest API means that a user will need the latest version of Power BI Desktop, I want Deneb to support at least three versions back. Therefore, I will start work on this functionality soon, but not immediately.? We have an issue tracking the potential approach we'll take here, and you or anyone else is very welcome to add your thoughts to it so that we get this right: https://github.com/deneb-viz/deneb/issues/238 Because developers may wish to take control themselves, like in your approach (and to maintain specifications that might employ this approach when such an update comes along), we would give a developer the option of allowing or disallowing this in-visual via a setting.