Calculated Fields in query

G

Guest

Hello,

I have a query that pulls a month worth of figures and puts them on a
excel worksheet... I would like to add 2 calculated fields to the end of the
query but not sure how to do this...

Here is the SQL as it stands now...

SELECT tDayData.*
FROM tDayData
WHERE (((Month([Date]))=1));

The 2 calculated fields are Last Years Sales and Last Years CC

Each record should list this years sales and calculate what last years sales
were...

I can calculate last years date just don't know how to put it into the
calculated field...

Any help would be great...

Ernst.
 
G

Guest

SELECT tDayData.*, calculation1 as last_year_sales, calculation2 as
Last_Years_CC
FROM tDayData
WHERE (((Month([Date]))=1));

replace CalculationN with your calculations
 
G

Guest

SELECT tDayData.*, calculation1 as last_year_sales, calculation2 as
Last_Years_CC
FROM tDayData
WHERE (((Month([Date]))=1));

replace CalculationN with your calculations

Here is where I am...

SELECT tDayData.Date, DLookUp("[Daily Sales]","tDayData","[Date] = " &
[Date] -365) AS Expr1, tDayData.[Daily Sales]
FROM tDayData
WHERE (((Month([Date]))=1));

The dlookup does not give me a value... nor an error for that matter but
still...

Ernst.
 
G

Guest

First try with your dbug that the dlookup return a value, if it does then it
should work with your query, you might not have a value for that day, so if
you dont have a value for every day yu should cosider a different approch
second try that add the # before and after the date
SELECT tDayData.Date, DLookUp("[Daily Sales]","tDayData","[Date] = #" &
[Date] -365 & "#") AS Expr1, tDayData.[Daily Sales]
FROM tDayData
WHERE (((Month([Date]))=1));


Ernst Guckel said:
SELECT tDayData.*, calculation1 as last_year_sales, calculation2 as
Last_Years_CC
FROM tDayData
WHERE (((Month([Date]))=1));

replace CalculationN with your calculations

Here is where I am...

SELECT tDayData.Date, DLookUp("[Daily Sales]","tDayData","[Date] = " &
[Date] -365) AS Expr1, tDayData.[Daily Sales]
FROM tDayData
WHERE (((Month([Date]))=1));

The dlookup does not give me a value... nor an error for that matter but
still...

Ernst.
 
G

Guest

First try with your dbug that the dlookup return a value, if it does then it
should work with your query, you might not have a value for that day, so if
you dont have a value for every day yu should cosider a different approch
second try that add the # before and after the date
SELECT tDayData.Date, DLookUp("[Daily Sales]","tDayData","[Date] = #" &
[Date] -365 & "#") AS Expr1, tDayData.[Daily Sales]
FROM tDayData
WHERE (((Month([Date]))=1));

That was it. Forgot the ## around the dates... Thanks for the help.

Ernst.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top