Hi Dr. Chill
Apologies in advance for the long answer. This can be done with three queries - this may be one or two queries too many but I split it up to allow what is happening to be better understood.
The first query sorts your values (I have assumed the values will be sorted in ascending order) that you want on the report, so be sure to include all of the fields you want in your report - you may already have a query that does this. Don't worry about the sort order at this point in time, you can re-sort the fields on the report irrespective of how they are sorted in the queries.
The second query is based on the first query and it assigns a "ranking" to the values from 0 to n-1 (where n is the number of records in the first query). Add the fields you want on the report into the new query, click View -> Properties, Select the "Sorted Values Query" (or whatever you have called it) in the top half of the query screen and change the "Alias" to something like "Sorted_Values_Alias" (without the quotes). Add a new field into the query using the following :
Ranking: (Select Count(*) from Q_Values_Sorted where [value] < [Sorted_Values_Alias].[value]; )
Please note that I used the query Q_Values_Sorted, gave it the alias "Sorted_Values_Alias" and I used the field name [value].
This query will assign a ranking to the values, which we will use in the next query. Save the query (I used the name "Q_Values_Ranked".
FYI the SQL for my first query is as follows :
SELECT Sorted_Values_Alias.value, (Select Count(*) from Q_Values_Sorted where [value] < [Sorted_Values_Alias].[value]; ) AS Ranking
FROM Q_Values_Sorted AS Sorted_Values_Alias;
NB : you could probably avoid these first two queries if you had an autonumber field in your table (an autonumber field would have a similar effect as the ranking field) and you knew you wanted to include all records on the report, but I try not to use autonumbers so have based this solution on a structure that does not have autonumbers.
The third query is based on the 2nd query, add all of the fields you want on the report, include the ranking field and then add a new field with the following :
Product: IIf([Ranking]=0, [value], [value] * (DLookUp("[Product]", "Q_Values_Products", "Ranking = " & [Ranking] -1 )))
This will give you a running product for each line in the query, a bit like a factorial, where it multiplies the [value] by the product of the previous values. I used the field names [value] &[Ranking] and I used the query name "Q_Values_Products" (without the quotes). Save this query - note the query name and the 2nd argument in the DLookup function must be the same (I used Q_Values_Products). Also, the new field name (i.e. Product) must be the same as the first field in the Dlookup function. The quotes and square brackets are necessary in the Dlookup function.
The SQL for the query I tested this on follows :
SELECT Q_Values_Ranked.value, Q_Values_Ranked.Ranking, IIf([Ranking]=0,[value],[value]*(DLookUp("[Product]","Q_Values_Products","Ranking = " & [Ranking]-1))) AS Product
FROM Q_Values_Ranked
ORDER BY Q_Values_Ranked.Ranking;
If you base your report on this query (you might have developed one already, so you could change the record source of your existing report to the new query, provided the field names have not changed), add a new unbound text box into the footer of the report with the following as the control source :
=Max([Product])
This will put the product of the column of values into the report footer. In actual fact it is seeking the largest [product] value which equals the product of all values multiplied together. Please be aware that where you add this into the footer, the running products, in the detail section of the report, appear to have funny values - I'm not sure why but I figure that it doesn't matter for the moment.
A lot of work for such a small item on the report!
HTH, Andrew.