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
snandy2011
Helper IV
Helper IV

Nested If / And statement not working

Hi All,

I know, this is something relatively easy, but i cannot figure out my issues with this DAX . Below is my scenario..

 

I have Sales measure which gives me total sales of selected year in Slicer.

I also have Previous year sales measure which gives me Last year sales.

 

Based on that, I am calcuating growth rate, which is also in another measure.

 

My growth rate formula look like,

 

DIVIDE('Measure Dimension for Product'[Measure Selection for Product]-[Last Year],[Last Year])

 

format is Percentage..

Now, i am segemnting this growth rate by different category like 1,2,3

 for example,

if the growth rate is 0 to 25 , then 1

if the growth rate is 26 to 50 , then 2

if the growth rate is greater than 100,3

else,0

 

for that, logic i have written below formula,

 

IF(
    AND([Growth Rate By Year]>0,[Growth Rate By Year]<=25),"1",IF(AND([Growth Rate By Year]>=26,[Growth Rate By Year]<=50),"2","0" ) )

 

Does not work.. It gives me only 1 or 0.. when growth rate is also 26

to 50.. It shows also 1.

 I have tried with Switch statement also,

 

SWITCH(TRUE(),
[Growth Rate By Year] >= 0 && [Growth Rate By Year] <=25,"1",
[Growth Rate By Year]>=26 && [Growth Rate By Year] <=50,"2",
"0")
 
But same result..
Can you please identify what wrong in this formula..??
 
I am not able to find out any issues.But still it is not showing the correct result.
 
Any suggesation is really appreciable.
 
Thanks,
snandy
 
 
 
 
 
 
 
 
 
 
 
 
 
1 ACCEPTED SOLUTION
AlB
Super User
Super User

Hi @snandy2011

It could be that your measure is yielding results different from what you expect.

In any case, try using 0,25 instead of 25, 0,50 instead of 50, etc. Those are the real values of your division even though you are formatting them as percentage.

View solution in original post

5 REPLIES 5
snandy2011
Helper IV
Helper IV

@ryan_mayu@yelsherif @AlB,

 

I apologize to everybody for asking this stupid question. I should have sticked with that issues and sloved by myself.Actually, I lost patience.. After some hours, i found out the actual reason when i did it on Excel. The issues was that, i changed the format of that measures. and within if function i was using only integer number, i should have used decimal number.when i did it on excel it came into my mind..

 

Thanks to everyone, for your reply and your valueable time..and sorry once again for asking this stupid type question.

 

Thanks,

snandy

 

 

@snandy2011

No worries. We've all been in similar situations Smiley Happy

ryan_mayu
Super User
Super User

@snandy2011

 

I am afraid the growth rate  is between 25 and 26. Depends on your coding logic, it will also show as 0 when your value is between 25 and 26. Please show the value with one decimal number and double check.

 

You can try modify the coding like below.

IF(
    AND([Growth Rate By Year]>0,[Growth Rate By Year]<=25),"1",IF(AND([Growth Rate By Year]>25,[Growth Rate By Year]<=50),"2","0" ) )
 
I have done the test, it works on my end. Thanks.
c1.JPG
 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




yelsherif
Resolver IV
Resolver IV

Seems you meant to categorize a percentage, .e.g. 0-25% , 25%-50%.

Your formula checks integer values, not percentages.

On the other hand, your formula does not include values above 50 which may be the case that actual values are above 50 (or 50%) and is not recognized, so the formula returns 0

Can you provide a sample data to check it please

AlB
Super User
Super User

Hi @snandy2011

It could be that your measure is yielding results different from what you expect.

In any case, try using 0,25 instead of 25, 0,50 instead of 50, etc. Those are the real values of your division even though you are formatting them as percentage.

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.