In Power BI, the SELECTEDVALUE
function is commonly used to retrieve a single value from a column. However, when working with the selected value function using a field parameter in Power BI, you will run into problem:
The usual way: For example, if you have a table named Dim_KPI with a column called KPI, you might typically use SELECTEDVALUE
like this:
Selected KPI = SELECTEDVALUE(Dim_KPI[KPI])
This measure works perfectly for dynamic titles or filtering, returning the selected KPI if only one value is chosen.
This is my third article in my series, how to make your Power BI Report more dynamic. My previous article dealt with a similar topic, how to easiliy switch between multiple KPIs without any bookmarks or buttons. Using Power BI Dynamic Values for Flexible Reporting.
SELECTEDVALUE
Doesn’t Work with Field Parameter in Power BIField parameters in Power BI offer a powerful way to switch between measures or dimensions within a single visual. However, if you try to use the SELECTEDVALUE
function with a field parameter, you’ll encounter an error like this:
“The SELECTEDVALUE function expects a column reference expression for argument ‘1’, but a table reference expression was used.”
This error occurs because of how Power BI structures field parameters. They rely on a composite key that breaks the SELECTEDVALUE
function when applied directly.
Even with this limitation, field parameters are essential for creating dynamic, flexible reports. But there is good news. There is a workaround! But first, you have to set up your parameter:
prm_comparison_switch
) to keep it organized.
Field parameters make reports much more interactive, allowing users to compare data points and scenarios without creating separate visuals. They are particularly useful when you want to offer a clean and flexible user experience.
SELECTEDVALUE
To avoid the SELECTEDVALUE
error, you can use a custom measure that still gets the selected field parameter without issues:
Selected Parameter =
VAR __SelectedValue =
SELECTCOLUMNS (
SUMMARIZE ( prm_comparison, prm_comparison[prm_comparison], prm_comparison[prm_comparison Fields] ),
prm_comparison[prm_comparison]
)
RETURN IF ( COUNTROWS ( __SelectedValue ) = 1, __SelectedValue )
This measure summarizes the field parameter table and filters down to the selected value. It works similarly to SELECTEDVALUE
, but it avoids the composite key problem.
If you want to follow along using my Power BI Desktop file, you can do that. Use the link below and get free access to the PBIX file with all measures, data models and settings.
Field parameters are fantastic for dynamic reporting and offer a flexible way to switch between different measures or fields. While they don’t work well with the traditional SELECTEDVALUE
function, you can easily overcome this by using a custom measure. This solution keeps your reports dynamic and ensures you can still create features like dynamic titles without any errors.
Field parameters are a powerful addition to any Power BI report, making it easier to deliver insights that are both interactive and actionable. Give this technique a try in your next project and unlock even more potential in your Power BI reports!
Next up in my series on How to Make your Power BI Report more dynamic:
Your boss or colleagues want to compare data year over year? Often you hear the question: How did we perform versus two years ago or even 3 years ago? My blog post Dynamically change the reference year answers exactly these questions. Don”t miss out and improve your Power BI report today!
If you like this type of series, I would be very happy if you give me a comment, share this post or follow me on LinkedIn.