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
Anonymous
Not applicable

How to change values based on the slicer selection using DAX

ProductDateQuantityDemand
A1/05/201958
A18/03/201924
B2/04/202052
C7/05/202163
C2/05/2021100
A3/10/202063

 

I have a data set that looks like the above and I want to create a what-if scenario and change the values of quantity demand based on the Product selection of slicer. For instance, if someone selects A, the Quantity demand for Product A must be set to zero and calculate the total Quantity demand. This is to see what would the total demand quantity be if the demand for a specific product or products is zero. I want to create a measure that changes the value of quantity demand and return the Total Quantity Demand dynamically.

 

Here is my trial below, but no luck yet.

 

 

 

 

 

 

 

 

Deletion = 
var selection = 
    SELECTEDVALUE(Table[Product])
    Return
    SWITCH(TRUE(),
    selection = HASONEVALUE(Data[Product])
    ,VALUES(Data[QuantityDemand])=0)

 

 

 

 

 

 

 

 

Can anyone please help me with this?

 

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You can use what-if parameter.

8.png

 

Then create the following separate table.

Table 2 = DISTINCT('Table'[Product])

9.png

 

At last, create the following measure.

Total Quantity Demand = CALCULATE(SUM('Table'[QuantityDemand]),FILTER(ALL('Table'),[Product]<>SELECTEDVALUE('Table 2'[Product])))+SELECTEDVALUE('Quantity demand'[Dynamic Quantity demand])

10.gif

 

Best Regards,

Stephen Tao

 

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

3 REPLIES 3
v-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You can use what-if parameter.

8.png

 

Then create the following separate table.

Table 2 = DISTINCT('Table'[Product])

9.png

 

At last, create the following measure.

Total Quantity Demand = CALCULATE(SUM('Table'[QuantityDemand]),FILTER(ALL('Table'),[Product]<>SELECTEDVALUE('Table 2'[Product])))+SELECTEDVALUE('Quantity demand'[Dynamic Quantity demand])

10.gif

 

Best Regards,

Stephen Tao

 

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

@v-stephen-msft  there seems to be an error?

 

Quantities w/o dynamic slicer do not fit.

Sum of A = 145 (not 215)

Sum of B = 52 (not 308)

Sum of C = 163 (not 197)

 

Is there an issue with the measure?

amitchandak
Super User
Super User

@Anonymous , can you share expected output

 

like quantity other than selected 

 

calculate(sum(Data[QuantityDemand]), filter( Data, not(data[Product] in allselected(data[Product] ))))

 

You can control this better if you have an independent table for the product

example Need of an Independent Table in Power BI: https://youtu.be/lOEW-YUrAbE

 

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.