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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
rdg515
Resolver I
Resolver I

Parameter: Fields selected value

I want to create a measure that references the selected value from a paramater table (create new parameter, select fields). I will show you the way I did it below, but I'm looking for an improvement because if I change the name of the parameter table I have to update all the hardcoded references to it.

Here's is the parameter table:

prmSurveyResponses = { ("NPS", NAMEOF('Service Survey'[NPSResponseCode]), 0), ("Customer Effort", NAMEOF('Service Survey'[CustomerEffortResponseCodeText]), 1), ("Product vs Competition", NAMEOF('Service Survey'[ProductCompetitionResponseCodeText]), 2) 

 

Then I created a slicer of prmSurveyResponses[prmSurveyResponses] which represents measures that the user can select to see.

Finally, I created a measure that will dynamically select the appropriate measure based on the user's selection from the slicer. 

Selected Survey Avg Rating = SWITCH(SELECTEDVALUE(prmSurveyResponses[prmSurveyResponses Fields]), "'Service Survey'[NPSResponseCode]",[NPS Avg Rating], "'Service Survey'[CustomerEffortResponseCodeText]",[Customer Effort Avg Rating], "'Service Survey'[ProductCompetitionResponseCodeText]",[Product Competition Avg Rating] )

 

I cannot figure out how to do this without hardcoding the table name - anyone know how to avoid having to do this?

2 ACCEPTED SOLUTIONS
v-kkf-msft
Community Support
Community Support

Hi @rdg515 ,

 

Please try the measure.

 

Selected Survey Avg Rating = 
SWITCH (
    SELECTEDVALUE ( prmSurveyResponses[prmSurveyResponses Fields] ),
    NAMEOF ( 'Service Survey'[NPSResponseCode] ), [NPS Avg Rating],
    NAMEOF ( 'Service Survey'[CustomerEffortResponseCodeText] ), [Customer Effort Avg Rating],
    NAMEOF ( 'Service Survey'[ProductCompetitionResponseCodeText] ), [Product Competition Avg Rating]
)

vkkfmsft_0-1657526389080.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

rdg515
Resolver I
Resolver I

Thanks, but I was looking for a way to avoid referencing the parameter table in the Avg Rating measure because I had many measures like this that I had to update when I changed the name of the parameter table.  Having said that, I realized I missed an obvious solution which was to just do this in two steps and if I had to change the paramater table name again I'd just have to do it for one measure.

 

Step 1:

Selected Parameter = SELECTEDVALUE ( prmSurveyResponses[prmSurveyResponses Fields] )

 

Step 2:

Selected Survey Avg Rating =
SWITCH (
    [Selected Parameter],
    NAMEOF ( 'Service Survey'[NPSResponseCode] ), [NPS Avg Rating],
    NAMEOF ( 'Service Survey'[CustomerEffortResponseCodeText] ), [Customer Effort Avg Rating],
    NAMEOF ( 'Service Survey'[ProductCompetitionResponseCodeText] ), [Product Competition Avg Rating]
)

 

Thanks for the tip to use NAMEOF instead of using double quotes around the column name.

 

P.S. I keep getting the following error when formatting the dax code as HTML/XML code snippit:

Your post has been changed because invalid HTML was found in the message body. The invalid HTML has been removed. Please review the message and submit the message when you are satisfied.

View solution in original post

4 REPLIES 4
rdg515
Resolver I
Resolver I

Thanks, but I was looking for a way to avoid referencing the parameter table in the Avg Rating measure because I had many measures like this that I had to update when I changed the name of the parameter table.  Having said that, I realized I missed an obvious solution which was to just do this in two steps and if I had to change the paramater table name again I'd just have to do it for one measure.

 

Step 1:

Selected Parameter = SELECTEDVALUE ( prmSurveyResponses[prmSurveyResponses Fields] )

 

Step 2:

Selected Survey Avg Rating =
SWITCH (
    [Selected Parameter],
    NAMEOF ( 'Service Survey'[NPSResponseCode] ), [NPS Avg Rating],
    NAMEOF ( 'Service Survey'[CustomerEffortResponseCodeText] ), [Customer Effort Avg Rating],
    NAMEOF ( 'Service Survey'[ProductCompetitionResponseCodeText] ), [Product Competition Avg Rating]
)

 

Thanks for the tip to use NAMEOF instead of using double quotes around the column name.

 

P.S. I keep getting the following error when formatting the dax code as HTML/XML code snippit:

Your post has been changed because invalid HTML was found in the message body. The invalid HTML has been removed. Please review the message and submit the message when you are satisfied.

The protip to use NAMEOF was a lifesaver. Thanks.

v-kkf-msft
Community Support
Community Support

Hi @rdg515 ,

 

Please try the measure.

 

Selected Survey Avg Rating = 
SWITCH (
    SELECTEDVALUE ( prmSurveyResponses[prmSurveyResponses Fields] ),
    NAMEOF ( 'Service Survey'[NPSResponseCode] ), [NPS Avg Rating],
    NAMEOF ( 'Service Survey'[CustomerEffortResponseCodeText] ), [Customer Effort Avg Rating],
    NAMEOF ( 'Service Survey'[ProductCompetitionResponseCodeText] ), [Product Competition Avg Rating]
)

vkkfmsft_0-1657526389080.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Here is a more universal solution. 

 

Selected Parameter = 
VAR SearchString = SELECTEDVALUE('Field Parameters'[Parameter])
VAR LeftBound = SEARCH("[",SearchString)
VAR RightBound = SEARCH("]",SearchString)
RETURN
MID(SearchString,LeftBound + 1,RightBound-(LeftBound+1))

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.