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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Nested IF's in DAX with text and parameters

Hi all,

 

I'm stuck and hope the community can help me. 

 

Simple problem.  A table contains:

 

Fruit                      Value

Orange                  10

Apple                     4

Banana                  20

Strawberries          7

 

I have a % parameter (so 0% to 100%) which is selected by the user. 

I need a new column with the logic of:

 

If Fruit = Orange then (Value * % parameter + 10) or;

If Fruit = Apple then (Value * % parameter + 5) or;

If Fruit = Banana then (Value * % parameter + 2)

otherwise return Value

 

I relatively new to PowerBI so am struggling with nested IF searching for texts and returning a formula.  I've looked at many examples but currently haven't got it.

 

All help welcome.  Thanks a lot in advance.

 

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @Anonymous 

try this technique 

Measure = 
var _parameter = DIVIDE(SELECTEDVALUE('Table'[Parameter]), 100)
var _fruit = SELECTEDVALUE('Table'[Fruit])
var _valueParameter = SELECTEDVALUE('Table'[Value])*_parameter 
RETURN
SWITCH(TRUE(),
_fruit = "Orange", (_valueParameter  + 10),
_fruit = "Apple", (_valueParameter  + 5),
_fruit = "Banana", (_valueParameter  + 2)
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

4 REPLIES 4
az38
Community Champion
Community Champion

Hi @Anonymous 

try this technique 

Measure = 
var _parameter = DIVIDE(SELECTEDVALUE('Table'[Parameter]), 100)
var _fruit = SELECTEDVALUE('Table'[Fruit])
var _valueParameter = SELECTEDVALUE('Table'[Value])*_parameter 
RETURN
SWITCH(TRUE(),
_fruit = "Orange", (_valueParameter  + 10),
_fruit = "Apple", (_valueParameter  + 5),
_fruit = "Banana", (_valueParameter  + 2)
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Thank you for the superfast reply!  Yes, the format with some tweaking worked and I learnt a lot on the way.

 

Really appreciated!

Anonymous
Not applicable

Actually, sorry still stuck.  When I use the following with a a whatif parameter, the correct values are returned.

 

Apple = ((620)*Parameter[Parameter Value])+((750)*(1-Parameter[Parameter Value]))

However, if I wanted to simply subtract that result from another number , the results are incorrect.  So for example:
 
Apple  = 750 - ((620)*Parameter[Parameter Value])+((750)*(1-Parameter[Parameter Value]))
 
Clearly I'm missing something so basic but has stumped me.   Any suggestions again would be appreciated 
 
Many thanks.
 
az38
Community Champion
Community Champion

@Anonymous 

sorry, I do not understand the issue

also, please set @ in message and choose my login in drop down list to notify me about reply


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.