Yes. I have fields with those names, because I can not figure out how
to name them dynamicly.
No, this is not an issues of table design. It is an issue of query
design.
Another way to describe the problem: Have a report with several
different fields, the goal is to name the fields in the query based on
run-time user input, say from a form. Actually, The names will be
caculated strings, but same concept.
As far as what I am really creating, I will try to explain it more
thoroughly.
Data set is
Date, Brand, Cust#, Item#, Sale QTY, Price, Cost, commission.
Very basic stuff. It is the query that is a little less than basic...
Let us just look at Sales Dollars. The query might be grouped by Brand,
for instance, with twelve data fields, one for each month. The dataset
being represented will go back two full years, based on the current
date, so that it will change in real time as the report is run. Assume
it is being run in January 09.
Brand M1 M2 M3 M4 M5 M6 M7 M8 M9 M10 M11 M12.
The first field M1, will contain sales between Jan 08 and Dec 08.
Actually, between last month and 11 months before last month.
The 2nd field M2, will contain sales between Dec 07 and Nov 08.
Actually, between the month before last, and 11 months before the month
before last.
The third field M3 will contain sales between Nov 07 and Oct 08.
Actualy, three months ago, ...
Each field represents a full year of sales, that year long window
sliding back one month for each successive field, wiht a great deal of
overlap, which is the idea. Any sale in October 08 will be reflected in
M1, M2, and M3, but not in M4 and beyond, for instance.
The way I am doing this is as follows. (warning, getting too deep into
these formulas will require headache medicine. It is all nasty date
math. M1 It can be summed up as:
Sum (iif(date is within the year ending last month, (amount shipped
times unit price),0))
For M1, which represents sales Jan08-Dec08
M1:
Sum(IIf(invoice_h!invoice_date<=DateAdd("m",-1,DateAdd("d",-1,CDate(Month(Now())
& "/1/" & Year(Now())))) And
invoice_h!invoice_date>=DateAdd("m",-13,DateAdd("d",-1,CDate(Month(Now())
& "/1/" & Year(Now())))),(invoice_d!price*invoice_d!ship_qty),0))
This tallies the total sales if the date falls between last month, and
13 months ago. It is ugly because I have to go from the last day of
last month, whether that is the 28th, 29th, 30th or 31st, regardless of
whether today is Jan 1 09 or Jan 12 09.
M2:
Sum(IIf(invoice_h!invoice_date<=DateAdd("m",-2,DateAdd("d",-1,CDate(Month(Now())
& "/1/" & Year(Now())))) And
invoice_h!invoice_date>=DateAdd("m",-14,DateAdd("d",-1,CDate(Month(Now())
& "/1/" & Year(Now())))),(invoice_d!price*invoice_d!ship_qty),0))
If I run it in February, the date ranges of all of those 12 fields will
shift a month. I want to be able to name the fields "JAN08-DEC08",
"DEC07-NOV08", etc. without user intervention. I could restructure this
report as a crosstab if I was just using Sales, but for each of 12 ryear
long periods, I am actually pulling out 5 different values, putting it
beyond the ability of a crosstab.
I can build the formula to do the math, and I can build the formula to
create the strings "JAN08-DEC-08", "DEC07-NOV08", I just need to figure
out how to put that string in as the field name. The result will be
thrown out into an Excel Spreadsheet.
Clear as Mud, right?
Thanx