Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

Field Parameter composite key error?

I'm facing an issue in Power BI after creating a field parameter to swap between 4 hierarchy columns with person names in them. The user should be able to select hierarchy level in slicer, and then, the associated column is returned. But I get error noted below.

 

 

 

Error fetching data for this visual

MdxScript(Model) (79, 20) Calculation error in measure Swap Test]: Column

[hierarchy_parameter_testl is part of composite key, but not all columns of the composite key are

included in the expression or its dependent expression.

 

Here's what my 'field parameter' table shows in the DAX after creation using Modeling > New Parameter > Fields

 

hierarchy_parameter_test = {
    ("DIRECTOR_NAME", NAMEOF('FIELD_PARAMETER'[DIRECTOR_NAME]), 0),
    ("MANAGER_NAME", NAMEOF('FIELD_PARAMETER'[MANAGER_NAME]), 1),
    ("SUPERVISOR_NAME", NAMEOF('FIELD_PARAMETER'[SUPERVISOR_NAME]), 2),
    ("VP_NAME", NAMEOF('FIELD_PARAMETER'[VP_NAME]), 3)
}

Here's the swap to change to each of my original table columns:

Hierarchy Swap Test = 
VAR selectedRole = SELECTEDVALUE(hierarchy_parameter_test[hierarchy_parameter_test])
RETURN
SWITCH(
    selectedRole,
    "VP", MAX('TABLE1'[VP_NAME]),
    "DIR", MAX('TABLE1'[DIRECTOR_NAME]),
    "MGR", MAX('TABLE1'[MANAGER_NAME]),
    "SUP", MAX('TABLE1'[SUPERVISOR_NAME])
)
 

 

 

So in short, I have a field parameter to change across 4 simple columns, but the Switch calculation won't allow me to do so, telling me there's a composite key missing. What am I missing here? I feel like this should be so simple. Pick a value, return the column!

5 REPLIES 5
Anonymous
Not applicable

Hi @Anonymous ,

 

Try to modify your formula like below:

Hierarchy Swap Test = 
VAR selectedRole = MAX(hierarchy_parameter_test[Parameter])
RETURN
SWITCH(
    selectedRole,
    "VP_NAME", MAX('TABLE'[VP_NAME]),
    "DIRECTOR_NAME", MAX('TABLE'[DIRECTOR_NAME]),
    "MANAGER_NAME", MAX('TABLE'[MANAGER_NAME]),
    "SUPERVISOR_NAME", MAX('TABLE'[SUPERVISOR_NAME])
)

vkongfanfmsft_0-1735613744486.png

vkongfanfmsft_1-1735613755196.png

vkongfanfmsft_2-1735613762516.png

 

Best Regards,
Adamk Kong

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

@Anonymous this only returns 1 value, my intention is for it to pick an entire column of values. So user picks slicer value 1: Column 1. Slicer value 2: column 2 and so on. Using MAX only returns 1 value, not the entire list of associated values

DataInsights
Super User
Super User

@Anonymous,

 

To use SELECTEDVALUE with field parameters, adjust your DAX per the article below:

 

https://www.sqlbi.com/blog/marco/2022/06/11/using-selectedvalue-with-fields-parameters-in-power-bi/ 

 

Another option is to use MAX:

 

VAR selectedRole = MAX ( hierarchy_parameter_test[hierarchy_parameter_test] )

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Hi @DataInsights - Thanks for sharing that resource article. Had a look, and maybe I am missing something, but Max will only return 1 value, rather than the entire list of values in the column. So when I pick a level, it returns just 1 name, instead of the entire list of values. 

@Anonymous,

 

Have you tried using the field parameter in the visual? The engine is able to dynamically use the selected field without the need for custom DAX. You can customize the names as shown below:

 

hierarchy_parameter_test =
{
    ( "DIR", NAMEOF ( 'FIELD_PARAMETER'[DIRECTOR_NAME] ), 0 ),
    ( "MGR", NAMEOF ( 'FIELD_PARAMETER'[MANAGER_NAME] ), 1 ),
    ( "SUP", NAMEOF ( 'FIELD_PARAMETER'[SUPERVISOR_NAME] ), 2 ),
    ( "VP", NAMEOF ( 'FIELD_PARAMETER'[VP_NAME] ), 3 )
}

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.