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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
cherylyu
Regular Visitor

Setting selected value of what if parameter with code

Hi all,

 

I am using a "what if" parameter. User can enter a wide range of values. But the reasonable range depends on other slicers. To help user enter meaningful numbers, I'd like to reset the selected value each time other slicers are chagned. For example, in the below situation, I know a good starting number is 3745. I just need a way (a command) to place the number 3745 into the what if parameter box. Is this doable?

 

 

cherylyu_0-1626145272048.png

 

1 ACCEPTED SOLUTION
Wimverh
Resolver IV
Resolver IV

It's possible to use a measure, as the default value, but it won't be represented in the marked box. 
So you would need to put a card visual on top of the box, to show your value. 

For resetting the value, after you change a slicer, I don't think it's possible. 

You could use a bookmark, and then add a button to your report to reset the value.

 

Sample measure for changing default (you have this already, this is your suggested value:

MyDefaultValue = if(HASONEVALUE(Customer[CustomerGroup]),SWITCH(min(Customer[CustomerGroup]),"G01",15,"G02",30,20),29)

 Parameter Value (the last part, is where you add your default value, so the measure on top)

Parameter Value = SELECTEDVALUE('Parameter'[Parameter], [MyDefaultValue])

 

Sample file: https://dataploration.be/forumpost/WhatIfSample.pbix 

 

View solution in original post

1 REPLY 1
Wimverh
Resolver IV
Resolver IV

It's possible to use a measure, as the default value, but it won't be represented in the marked box. 
So you would need to put a card visual on top of the box, to show your value. 

For resetting the value, after you change a slicer, I don't think it's possible. 

You could use a bookmark, and then add a button to your report to reset the value.

 

Sample measure for changing default (you have this already, this is your suggested value:

MyDefaultValue = if(HASONEVALUE(Customer[CustomerGroup]),SWITCH(min(Customer[CustomerGroup]),"G01",15,"G02",30,20),29)

 Parameter Value (the last part, is where you add your default value, so the measure on top)

Parameter Value = SELECTEDVALUE('Parameter'[Parameter], [MyDefaultValue])

 

Sample file: https://dataploration.be/forumpost/WhatIfSample.pbix 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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