I am writing a report which contains 3 groups: Year, Month and Supplier.

Each page starts with the Year at the top, then each of the 12 months, with sales summaries for each. The user can then drill down to see the individual sales figures for each company from that month.

e.g. the top level of my report looks like this:

2010  
   January    £20,000
   February   £30,000
   March      £15,000
   etc.

2011
    January   £16,000
    February  £14,000

Now, I wish to compare the values of Jan 2011 with the same period of the previous year (in this case: 16,000 vs 20,000) so I can perform some additional calculations.

Currently I am achieving this by using global variables called JanGlobal, FebGlobal, etc. which are stored and retrieved as necessary. This works because I know there will only be 12 months, so I can name the variables in advance.

However, at the supplier level, I don't know how many suppliers there will be, or even if they will exist at all (suppliers might be new, so they won't have Year-on-year information; or they might have gone bust, and so don't exist in the new year).

My suppliers drill down looks like this:

2010
    January
        Company 1    £5,000
        Company 2    £7,000
        Company 3    £8,000

So I need to compare a variable number of suppliers with their counterparts from 12 months previous, if they exist. Any ideas?

有帮助吗?

解决方案

The solution here involves a fair degree of string manipulation. Essentially, in the group footers for the companies (when the year is 2010), you build up a string of company names and sales figures. When the year is 2011, you process the string instead to extract the data relevant to 2011 (for the given company and month), and use that for your comparison.

So, for a string formula called ProcessJan, you might have (using pipes as a splitting character) :

Global StringVar JanGlobal;
Local NumberVar NumberToCompare := 0;
If Year(Sales) = 2010 Then
    JanGlobal := '||' + {CompanyName} + '|' + ToText({SalesFigure}); //append current value to Jan's formula
Else
(
    If UBound(SalesSearch) > 0
    (
        Local NumberVar Searching := 1;
        For Searching = 1 to UBound(SalesSearch)
            If SalesSearch[Searching] StartsWith ({CompanyName} + '|') Then
            (
                Local StringVar Array Matched := Split(SalesSearch[Searching], '|')
                NumberToCompare := ToNumber(Matched[2]);
            )          
        Next
    )
    //do whatever you want with the 2011 sales figure and the value of NumberToCompare
    //(which should be either zero or Jan 2010's sales figure for the company) here
)

With a bit of work you could adapt this method to have one formula and global variable managing all months and companies.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top