Dax formula question

BORUCH

Well-known Member
Joined
Mar 1, 2016
Messages
548
Office Version
  1. 365
Platform
  1. Windows
Hi all

i have been breaking my head to figure this out if someone can help me i would greatly appreciate it

the formula is as follows

=IF(data[Discount Percentge]=0,"no discount",IF(AND(data[Discount Percentge]>0,data[Discount Percentge]<=0.05),"discount 1 .00% to 5.00%",IF(AND(data[Discount Percentge]>=0.05000001,data[Discount Percentge]<=0.1),"discount 2 5.00% to 10.00%",IF(AND(data[Discount Percentge]>=0.10001,data[Discount Percentge]<=0.35),"Discount 3 10.00 % TO 35.00 %",IF(AND(data[Discount Percentge]>=0.35001,data[Discount Percentge]<=0.75),"Discount 4 35.00 % TO 75.00 %",IF(AND(data[Discount Percentge]>=0.75001,data[Discount Percentge]<=100),"DISCOUNT 5 75.00 % TO 100.00 %","NEGATIVE"))))))

my problem is if i have a discount percent of exactly 5.00% it shows negative the question is why

if someone can please help me

thanks
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi,

I agree with the previous post, it might be the issue with decimal places. Try replacing "NEGATIVE" with FORMAT(DP, "0.00000") to display a value with 5 decimal places in order to see the true amount. Increase the number of decimal places if this still didn't give you an answer.

On a side note, I recommend getting familiar with SWITCH function - it will really make your life easier!

Rich (BB code):
var DP = data[Discount Percentge]
return
SWITCH(
    TRUE(),
    DP=0, "no discount",
    AND(DP>0,DP<=0.05), "discount 1 .00% to 5.00%",
    AND(DP>0.05,DP<=0.1), "discount 2 5.00% to 10.00%",
    AND(DP>0.1,DP<=0.35), "Discount 3 10.00 % TO 35.00 %",
    AND(DP>0.35,DP<=0.75), "Discount 4 35.00 % TO 75.00 %",
    AND(DP>0.75,DP<=1), "DISCOUNT 5 75.00 % TO 100.00 %",
    "NEGATIVE"
)
 
Upvote 0
Hi,

I agree with the previous post, it might be the issue with decimal places. Try replacing "NEGATIVE" with FORMAT(DP, "0.00000") to display a value with 5 decimal places in order to see the true amount. Increase the number of decimal places if this still didn't give you an answer.

On a side note, I recommend getting familiar with SWITCH function - it will really make your life easier!

Rich (BB code):
var DP = data[Discount Percentge]
return
SWITCH(
    TRUE(),
    DP=0, "no discount",
    AND(DP>0,DP<=0.05), "discount 1 .00% to 5.00%",
    AND(DP>0.05,DP<=0.1), "discount 2 5.00% to 10.00%",
    AND(DP>0.1,DP<=0.35), "Discount 3 10.00 % TO 35.00 %",
    AND(DP>0.35,DP<=0.75), "Discount 4 35.00 % TO 75.00 %",
    AND(DP>0.75,DP<=1), "DISCOUNT 5 75.00 % TO 100.00 %",
    "NEGATIVE"
)


hi

thanks for the formula

can you amend the formula that if the discount percentage is 5.000000000000000%

it would still show up in the first discount group and the same for 10 and 35 etc..
 
Upvote 0
Hi,

If the discount percentage is equal to 5.000000000000000% then it should, in theory, appear in the first group -

Rich (BB code):
AND(DP>0,DP<=0.05), "discount 1 .00% to 5.00%"

Just to be sure that we are working with the correct values, it might be worth adding ROUND function. See the first line -

Rich (BB code):
var DP = ROUND(data[Discount Percentge], 2)
return
SWITCH(
    TRUE(),
    DP=0, "no discount",
    AND(DP>0,DP<=0.05), "discount 1 .00% to 5.00%",
    AND(DP>0.05,DP<=0.1), "discount 2 5.00% to 10.00%",
    AND(DP>0.1,DP<=0.35), "Discount 3 10.00 % TO 35.00 %",
    AND(DP>0.35,DP<=0.75), "Discount 4 35.00 % TO 75.00 %",
    AND(DP>0.75,DP<=1), "DISCOUNT 5 75.00 % TO 100.00 %",
    "NEGATIVE"
)

If it still doesn't do the trick, can you paste some screenshots and/or exemplary data?
 
Upvote 0
Hi,

If the discount percentage is equal to 5.000000000000000% then it should, in theory, appear in the first group -

Rich (BB code):
AND(DP>0,DP<=0.05), "discount 1 .00% to 5.00%"

Just to be sure that we are working with the correct values, it might be worth adding ROUND function. See the first line -

Rich (BB code):
var DP = ROUND(data[Discount Percentge], 2)
return
SWITCH(
    TRUE(),
    DP=0, "no discount",
    AND(DP>0,DP<=0.05), "discount 1 .00% to 5.00%",
    AND(DP>0.05,DP<=0.1), "discount 2 5.00% to 10.00%",
    AND(DP>0.1,DP<=0.35), "Discount 3 10.00 % TO 35.00 %",
    AND(DP>0.35,DP<=0.75), "Discount 4 35.00 % TO 75.00 %",
    AND(DP>0.75,DP<=1), "DISCOUNT 5 75.00 % TO 100.00 %",
    "NEGATIVE"
)

If it still doesn't do the trick, can you paste some screenshots and/or exemplary data?

Hi

Thanks again for helping me

I'm getting an error as follows.

"Calculation error in column 'data'[]: An argument of function 'ROUND' has the wrong data type or the result is too large or too small."

I just want to be more clear what my goal is here in order for it to say "discount 1 .00% to 5.00%" . it needs to be less then and including the 5 percent even 5.000000000000%

the same is with 10 percent and 35 percent it needs ti include the 5 percent in the discount 1 right now with the first formula you provided me if you expand the percentage it only includes up to 4.999999999 etc.

thanks again for your help its greatly appreciated
 
Upvote 0
OK i figured it out

I just added the if error and increased the decimal place on round to 22

thanks
 
Upvote 0

Forum statistics

Threads
1,223,793
Messages
6,174,635
Members
452,575
Latest member
Fstick546

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top