Skip to Content
0
Jan 19, 2022 at 05:03 PM

Subtract Business Days - Replace NumberVar with Formula

74 Views

Good day everyone. I'm trying to use a formula to subtract business days. I found a very useful formula from Ken Hamaday below. However I would like to replace the NumberVar Add := -3 with a formula. Essentially I'm trying to back date to a certain process stage in my route for scheduling purposes. The formula would look similar to the following:

IF {Process.Group} = "FINISHING" THEN SUM({Process.Lead_Days}) ELSE 0

I have also thought of using subtotals and running totals but crystal doesn't like those included in formulas.

//Subtracting Business Days:

WhileReadingRecords;

DateVar Array Holidays;

DateVar Target:= date ({ORDE_Goods.Agreed_Date}); //Put your field name in here

NumberVar Add:= -3; // Put in the number of days to subtract (a negative number)

NumberVar Added := 0;

WHILE Added > Add

Do (target := target -1;

if dayofweek (target) in 2 to 6 and not (target in holidays)

then Added:=Added-1

else Added:=Added);

Target

Thank you in advance,

Matt