function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ksqd1112ksqd1112 

Problem with FLOOR & MOD on Formula Field

I'm having a devil of a time getting this formula to work for me.  If anyone can see something obviously wrong I'd appreciate the help.

 

IF (AND( Total_Days_to_Quote__c > 16, Total_Days_to_Quote__c <= 28), 1,

IF(AND (FLOOR( Total_Days_to_Quote__c / 28 ) > 1 , MOD( Total_Days_to_Quote__c ,28) > 16 ) , (FLOOR( Total_Days_to_Quote__c / 28 ) + 1),

IF(AND( MOD( Total_Days_to_Quote__c , 28) < 16 , FLOOR( Total_Days_to_Quote__c / 28 ) > 1) , FLOOR( Total_Days_to_Quote__c / 28 ) , 0)))

 

I’m trying to configure a formula field with a series of nested IF statements which each use an AND function.  The business problem briefly is as follows:  A customer get quoted an entire month after the 16th day of a quote period.  I’m trying to determine how many months to quote using the Mod and Floor functions.  So if the customer has the product after the 17 thru 28 day they are quoted for 1 month.  All monthly calculations are based on 28 days.  If they keep the product until the 17 day after the first month they will be quoted for another month for a total of 2 months.  If the customer keeps the product less than 17 days the monthly quoted rate is 0.  I’m using Total_Days_to_Quote as my number of days to base the quote.  My code will compile.  If the condition for the first IF is met the line executes properly.  If any other conditions exist the second and third IF statements don't execute as I think they should and the formula returns 0. 

 

My formula consists of 3 IF statements and an ending “0”. 

 

The first IF tests for quote days between 17 & 28 in period 0.

 

The second IF tests for subsequent contract periods greater than the first period using the FLOOR function (tests for next lowest integer) and the days greater than 16 using the MOD functions (tests for remainder).  .

 

The second If tests for subsequent contract periods greater than the first period using the FLOOR function and days less than 16 using the MOD functions (tests for remainder) and FLOOR function (tests for next lowest integer).  I can't get this statement to return a value.

 

Finally if none of the IF conditions are met a 0 is returned.  This is the value is being returned except for IF statement 1.

 

Thanks for your help in advance,

 

Ken

 

Best Answer chosen by Admin (Salesforce Developers) 
MarcPannenberg.ax1843MarcPannenberg.ax1843

I think you are missing the case where FLOOR (Total_Days_to_Quote__c) == 1. Try this:

 

IF (AND( Total_Days_to_Quote__c > 16, Total_Days_to_Quote__c <= 28), 1,

IF(AND (FLOOR( Total_Days_to_Quote__c / 28 ) >= 1 , MOD( Total_Days_to_Quote__c ,28) > 16 ) , (FLOOR( Total_Days_to_Quote__c / 28 ) + 1),

IF(AND( MOD( Total_Days_to_Quote__c , 28) <= 16 , FLOOR( Total_Days_to_Quote__c / 28 ) > =1) , FLOOR( Total_Days_to_Quote__c / 28 ) , 0)))

 


I also added the <= to the to the Mod condition, so you have all three cases (<16, =16, >16) covered.

All Answers

MarcPannenberg.ax1843MarcPannenberg.ax1843

I think you are missing the case where FLOOR (Total_Days_to_Quote__c) == 1. Try this:

 

IF (AND( Total_Days_to_Quote__c > 16, Total_Days_to_Quote__c <= 28), 1,

IF(AND (FLOOR( Total_Days_to_Quote__c / 28 ) >= 1 , MOD( Total_Days_to_Quote__c ,28) > 16 ) , (FLOOR( Total_Days_to_Quote__c / 28 ) + 1),

IF(AND( MOD( Total_Days_to_Quote__c , 28) <= 16 , FLOOR( Total_Days_to_Quote__c / 28 ) > =1) , FLOOR( Total_Days_to_Quote__c / 28 ) , 0)))

 


I also added the <= to the to the Mod condition, so you have all three cases (<16, =16, >16) covered.

This was selected as the best answer
ksqd1112ksqd1112

Marc,

 

You are spot on.  Your solution did the trick.  Many,many thanks.  I'm fairly new to this and I just couldn't see what you saw.  Thanks for spending your time to help out a fellow Salesforce user.

 

Best Regards,

 

Ken

MarcPannenberg.ax1843MarcPannenberg.ax1843

My pleasure! Glad it helped!