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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors