-
1
- #1
scottostanek
Programmer
I had this ugly problem involving reporting against budget data that exists in the database in year format and reporting against it using Fiscal year ranges. Here is how I got one piece out (imagine doing this over multiple columns and groupings)
[Formula YearLbsBudget]
WhilePrintingRecords;
numberVar YLbs := 0;
shared Numbervar CustYrBudLbs;
shared Numbervar SalesYrBudLbs;
if not isnull({CUST-SHIPTO-PROD-BUDGET.Quantity@1}) then
(
if Month({?CurrentMonth}) >= 6 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@1};
if Month({?CurrentMonth}) >= 7 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@2};
if Month({?CurrentMonth}) >= 8 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@3};
if Month({?CurrentMonth}) >= 9 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@4};
if Month({?CurrentMonth}) >= 10 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@5};
if Month({?CurrentMonth}) >= 11 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@6};
if Month({?CurrentMonth}) >= 12 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@7};
if(Month({?CurrentMonth}) < 6) then //always need June-Dec if hitting months Jan on in Fiscal year
(
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@1} + {CUST-SHIPTO-PROD-BUDGET.Quantity@2} +
{CUST-SHIPTO-PROD-BUDGET.Quantity@3};+ {CUST-SHIPTO-PROD-BUDGET.Quantity@4} +
{CUST-SHIPTO-PROD-BUDGET.Quantity@5} + {CUST-SHIPTO-PROD-BUDGET.Quantity@6}+
{CUST-SHIPTO-PROD-BUDGET.Quantity@7} + {CUST-SHIPTO-PROD-BUDGET.Quantity@8};
);
if Month({?CurrentMonth}) = 2 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@9};
if Month({?CurrentMonth}) = 3 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@9} + {CUST-SHIPTO-PROD-BUDGET.Quantity@10};
if Month({?CurrentMonth}) = 4 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@9} + {CUST-SHIPTO-PROD-BUDGET.Quantity@10} +
{CUST-SHIPTO-PROD-BUDGET.Quantity@11};
if Month({?CurrentMonth}) = 5 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@9} + {CUST-SHIPTO-PROD-BUDGET.Quantity@10} +
{CUST-SHIPTO-PROD-BUDGET.Quantity@11} + {CUST-SHIPTO-PROD-BUDGET.Quantity@12};
);
CustYrBudLbs := CustYrBudLbs + YLbs;
SalesYrBudLbs := SalesYrBudLbs + YLbs;
YLbs
[YearLbsBudgSales] //ie in the salesman grouping level
shared Numbervar SalesYrBudLbs;
numbervar holder := SalesYrBudLbs;
SalesYrBudLbs := 0;
holder
Note: I had had some trouble with complex reports using shared variables, in the fact that I kept losing amidst the rest the formula that held the shared declaration that reset it to 0. This accomplishes it every time, it is much harder to "lose" and I never have to worry that I reset the variable in the wrong place!
Scotto the Unwise
[Formula YearLbsBudget]
WhilePrintingRecords;
numberVar YLbs := 0;
shared Numbervar CustYrBudLbs;
shared Numbervar SalesYrBudLbs;
if not isnull({CUST-SHIPTO-PROD-BUDGET.Quantity@1}) then
(
if Month({?CurrentMonth}) >= 6 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@1};
if Month({?CurrentMonth}) >= 7 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@2};
if Month({?CurrentMonth}) >= 8 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@3};
if Month({?CurrentMonth}) >= 9 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@4};
if Month({?CurrentMonth}) >= 10 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@5};
if Month({?CurrentMonth}) >= 11 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@6};
if Month({?CurrentMonth}) >= 12 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@7};
if(Month({?CurrentMonth}) < 6) then //always need June-Dec if hitting months Jan on in Fiscal year
(
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@1} + {CUST-SHIPTO-PROD-BUDGET.Quantity@2} +
{CUST-SHIPTO-PROD-BUDGET.Quantity@3};+ {CUST-SHIPTO-PROD-BUDGET.Quantity@4} +
{CUST-SHIPTO-PROD-BUDGET.Quantity@5} + {CUST-SHIPTO-PROD-BUDGET.Quantity@6}+
{CUST-SHIPTO-PROD-BUDGET.Quantity@7} + {CUST-SHIPTO-PROD-BUDGET.Quantity@8};
);
if Month({?CurrentMonth}) = 2 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@9};
if Month({?CurrentMonth}) = 3 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@9} + {CUST-SHIPTO-PROD-BUDGET.Quantity@10};
if Month({?CurrentMonth}) = 4 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@9} + {CUST-SHIPTO-PROD-BUDGET.Quantity@10} +
{CUST-SHIPTO-PROD-BUDGET.Quantity@11};
if Month({?CurrentMonth}) = 5 then
YLbs := YLbs + {CUST-SHIPTO-PROD-BUDGET.Quantity@9} + {CUST-SHIPTO-PROD-BUDGET.Quantity@10} +
{CUST-SHIPTO-PROD-BUDGET.Quantity@11} + {CUST-SHIPTO-PROD-BUDGET.Quantity@12};
);
CustYrBudLbs := CustYrBudLbs + YLbs;
SalesYrBudLbs := SalesYrBudLbs + YLbs;
YLbs
[YearLbsBudgSales] //ie in the salesman grouping level
shared Numbervar SalesYrBudLbs;
numbervar holder := SalesYrBudLbs;
SalesYrBudLbs := 0;
holder
Note: I had had some trouble with complex reports using shared variables, in the fact that I kept losing amidst the rest the formula that held the shared declaration that reset it to 0. This accomplishes it every time, it is much harder to "lose" and I never have to worry that I reset the variable in the wrong place!
Scotto the Unwise