Skip to Content
0
Former Member
Oct 05, 2009 at 03:13 PM

Grouping on If-Then statements.

28 Views

I have a rather complicated formula that is not working correctly and I think its because I don't have it grouped right. I have multiple If-Then statments and I don't think there processing in the right order or some of the statements after the "then" are being processed when they shouldn't be. Here is the formula:

WhilePrintingRecords;

EvaluateAfter ({@Count});

// Declare variables

shared dateVar admit;

shared datevar Prev_admit;

shared dateVar discharge;

shared dateVar Prev_discharge;

shared stringVar print := "N";

shared stringVar crossref;

shared stringVar Prev_crossref;

// If the previous record had to be printed and it was necessary to store

// the previous records data then use the previous data to populate

// the data that will be printed

If {@Prev_admit} <> Date(0,0,0) then

admit := Prev_admit;

discharge := Prev_discharge;

crossref := Prev_crossref;

// It is necessary to determine if this is the first record read so

// we use the variable count to do this

If {@Count} <= 1 then

(

admit := {CostCtrGrp.AdmitDate};

If {CostCtrGrp.DischargeDate} <= {?End} or IsNull({CostCtrGrp.DischargeDate}) then

discharge := {CostCtrGrp.DischargeDate};

If IsNull({CostCtrGrp.DischargeDate}) or {CostCtrGrp.DischargeDate} = Date(0,0,0)

or {CostCtrGrp.DischargeDate} > {?End} then

crossref := "" else

crossref := {CROSSREF.Code}

)

Else

(

// If the previous discharge date was not null and the current discharge date is null

// and if the previouse discharge date is less than the admit date then print

// the previous records data as there has been a break in service

If {@discharge} <> Date(0,0,0) and IsNull ({CostCtrGrp.DischargeDate}) and

{@discharge} < {CostCtrGrp.AdmitDate} then

print := "P";

Prev_admit := {CostCtrGrp.AdmitDate};

Prev_discharge := {CostCtrGrp.DischargeDate};

Prev_crossref := {CROSSREF.Code};

// If the current records discharge date is greater than the previous admit date

// and also greater than the previous records discharge date and the previous records

// discharge date is not null then replace the previous recrods discharge date with

// this records discharge date

If {@discharge} <> Date(0,0,0) and {CostCtrGrp.DischargeDate} > admit and

{CostCtrGrp.DischargeDate} > discharge then

discharge := {CostCtrGrp.DischargeDate};

crossref := {CROSSREF.Code};

// If the current record has a null discharge date and the previous record has a

// discharge date then compare the current records admit date with the previous

// recrods discharge date and if the previouse records discharge date is greater

// than the current recrods admit date then replace the stored discharge date

// with the null date of this record

If {@discharge} <> Date(0,0,0) and IsNull({CostCtrGrp.DischargeDate}) and

{@discharge} > {CostCtrGrp.AdmitDate} and {CostCtrGrp.DischargeDate} <= {?End} then

discharge := {CostCtrGrp.DischargeDate};

crossref := "";

)