calculated value

S

Stephen

I have what is called a flat data base one table
four forms to populate which works fine
two general reports working ok

My car expense report can not be completed.
I was told when I started not to save calculated vales.
My auto expense report adds up all car related expenses fine
I have two boxes that use the start and end mile value to give me my
total year mileage and the other is suppose to give me total business
mileage for the year.
How do I take the start and end mile of each record and add them up to
give me total business mileage.
my query is a sum on all car related items plus min and max of start and
stop records

what I do not know is what do I add to query to give me the other value
by end-start summing to total

I can get 220 lines of end-start but have a running total

Thank you
Stephen
 
K

Ken Sheridan

Sum the difference between the two values per row in the table, e.g. the
following would give you the total mileage overall and the total business:

SELECT MAX(End) – MIN(Start) As TotalMiles,
SUM(End – Start) As TotalBusinessMiles
FROM YourTable;

If the table covers more than one year group the query by
YEAR(YourDateColumn) to give the mileages per calendar year. To group by the
fiscal year you'd need to return the fiscal year from your dates, unless
you've recorded the fiscal year in a column in the table, and group on that,
e.g. for a fiscal year starting 1 April you group by the following expression:

Year(DateAdd("m",-3, YourDateColumn))

Ken Sheridan
Stafford, England
 
S

Stephen

Ken said:
Sum the difference between the two values per row in the table, e.g. the
following would give you the total mileage overall and the total business:

SELECT MAX(End) – MIN(Start) As TotalMiles,
SUM(End – Start) As TotalBusinessMiles
FROM YourTable;

If the table covers more than one year group the query by
YEAR(YourDateColumn) to give the mileages per calendar year. To group by the
fiscal year you'd need to return the fiscal year from your dates, unless
you've recorded the fiscal year in a column in the table, and group on that,
e.g. for a fiscal year starting 1 April you group by the following expression:

Year(DateAdd("m",-3, YourDateColumn))

Ken Sheridan
Stafford, England
Thanks Ken

I have my query giving me min & max mileage subtracting one fom the
other does give me total mileage ok

I can not for some reason add to the query the field start & stop
mileage as I have min & max defined

any work around

Thank you
Stephen
 
S

Stephen

Ken said:
Sum the difference between the two values per row in the table, e.g. the
following would give you the total mileage overall and the total business:

SELECT MAX(End) – MIN(Start) As TotalMiles,
SUM(End – Start) As TotalBusinessMiles
FROM YourTable;

If the table covers more than one year group the query by
YEAR(YourDateColumn) to give the mileages per calendar year. To group by the
fiscal year you'd need to return the fiscal year from your dates, unless
you've recorded the fiscal year in a column in the table, and group on that,
e.g. for a fiscal year starting 1 April you group by the following expression:

Year(DateAdd("m",-3, YourDateColumn))

Ken Sheridan
Stafford, England
Thanks Ken

I have my query giving me min & max mileage subtracting one fom the
other does give me total mileage ok

I can not for some reason add to the query the field start & stop
mileage as I have min & max defined

any work around

Thank you
Stephen
 
K

Ken Sheridan

Stephen:

If you are trying to do it in query design view in the 'field row' of one
blank column in the query design grid enter:

TotalMiles: Max([End])-Min([Start])

and in the 'total' row select Expression.

In the 'field' row of another blank column enter:

TotalBusinessMiles: [End]-[Start]

and in the 'total' row select Sum.

Apart from checking the 'show' box leave the other rows in the grid for
these two columns blank.

If you still have problems post back the SQL of your query as it now stands
and we'll hopefully be able to sort it out.

Ken Sheridan
Stafford, England
 
S

Stephen

thanks trying that Ken

Ken said:
Stephen:

If you are trying to do it in query design view in the 'field row' of one
blank column in the query design grid enter:

TotalMiles: Max([End])-Min([Start])

and in the 'total' row select Expression.

In the 'field' row of another blank column enter:

TotalBusinessMiles: [End]-[Start]

and in the 'total' row select Sum.

Apart from checking the 'show' box leave the other rows in the grid for
these two columns blank.

If you still have problems post back the SQL of your query as it now stands
and we'll hopefully be able to sort it out.

Ken Sheridan
Stafford, England

Stephen said:
Thanks Ken

I have my query giving me min & max mileage subtracting one fom the
other does give me total mileage ok

I can not for some reason add to the query the field start & stop
mileage as I have min & max defined

any work around

Thank you
Stephen
 
S

Stephen

Ken

I am using Office2000 where is SOL view I can not find it

got an run error when I try your code

thank you
Smiles
thanks trying that Ken

Ken said:
Stephen:

If you are trying to do it in query design view in the 'field row' of
one blank column in the query design grid enter:

TotalMiles: Max([End])-Min([Start])

and in the 'total' row select Expression.

In the 'field' row of another blank column enter:

TotalBusinessMiles: [End]-[Start]

and in the 'total' row select Sum.

Apart from checking the 'show' box leave the other rows in the grid
for these two columns blank.

If you still have problems post back the SQL of your query as it now
stands and we'll hopefully be able to sort it out.

Ken Sheridan
Stafford, England
Stephen said:
Ken Sheridan wrote:
Sum the difference between the two values per row in the table, e.g.
the following would give you the total mileage overall and the total
business:

SELECT MAX(End) – MIN(Start) As TotalMiles,
SUM(End – Start) As TotalBusinessMiles
FROM YourTable;

If the table covers more than one year group the query by
YEAR(YourDateColumn) to give the mileages per calendar year. To
group by the fiscal year you'd need to return the fiscal year from
your dates, unless you've recorded the fiscal year in a column in
the table, and group on that, e.g. for a fiscal year starting 1
April you group by the following expression:

Year(DateAdd("m",-3, YourDateColumn))

Ken Sheridan
Stafford, England
:

I have what is called a flat data base one table
four forms to populate which works fine
two general reports working ok

My car expense report can not be completed.
I was told when I started not to save calculated vales.
My auto expense report adds up all car related expenses fine
I have two boxes that use the start and end mile value to give me
my total year mileage and the other is suppose to give me total
business mileage for the year.
How do I take the start and end mile of each record and add them up
to give me total business mileage.
my query is a sum on all car related items plus min and max of
start and stop records

what I do not know is what do I add to query to give me the other
value
by end-start summing to total

I can get 220 lines of end-start but have a running total

Thank you
Stephen

Thanks Ken

I have my query giving me min & max mileage subtracting one fom the
other does give me total mileage ok

I can not for some reason add to the query the field start & stop
mileage as I have min & max defined

any work around

Thank you
Stephen
 
K

Ken Sheridan

Open the query in design view and select 'Design View' from the 'View' menu
item or from the 'View' button on the toolbar.

Where are you entering the SQL statement when you get the error?

Ken Sheridan
Stafford, England

Stephen said:
Ken

I am using Office2000 where is SOL view I can not find it

got an run error when I try your code

thank you
Smiles
thanks trying that Ken

Ken said:
Stephen:

If you are trying to do it in query design view in the 'field row' of
one blank column in the query design grid enter:

TotalMiles: Max([End])-Min([Start])

and in the 'total' row select Expression.

In the 'field' row of another blank column enter:

TotalBusinessMiles: [End]-[Start]

and in the 'total' row select Sum.

Apart from checking the 'show' box leave the other rows in the grid
for these two columns blank.

If you still have problems post back the SQL of your query as it now
stands and we'll hopefully be able to sort it out.

Ken Sheridan
Stafford, England
:

Ken Sheridan wrote:
Sum the difference between the two values per row in the table, e.g.
the following would give you the total mileage overall and the total
business:

SELECT MAX(End) – MIN(Start) As TotalMiles,
SUM(End – Start) As TotalBusinessMiles
FROM YourTable;

If the table covers more than one year group the query by
YEAR(YourDateColumn) to give the mileages per calendar year. To
group by the fiscal year you'd need to return the fiscal year from
your dates, unless you've recorded the fiscal year in a column in
the table, and group on that, e.g. for a fiscal year starting 1
April you group by the following expression:

Year(DateAdd("m",-3, YourDateColumn))

Ken Sheridan
Stafford, England
:

I have what is called a flat data base one table
four forms to populate which works fine
two general reports working ok

My car expense report can not be completed.
I was told when I started not to save calculated vales.
My auto expense report adds up all car related expenses fine
I have two boxes that use the start and end mile value to give me
my total year mileage and the other is suppose to give me total
business mileage for the year.
How do I take the start and end mile of each record and add them up
to give me total business mileage.
my query is a sum on all car related items plus min and max of
start and stop records

what I do not know is what do I add to query to give me the other
value
by end-start summing to total

I can get 220 lines of end-start but have a running total

Thank you
Stephen

Thanks Ken

I have my query giving me min & max mileage subtracting one fom the
other does give me total mileage ok

I can not for some reason add to the query the field start & stop
mileage as I have min & max defined

any work around

Thank you
Stephen
 
S

Stephen

Ken said:
Open the query in design view and select 'Design View' from the 'View' menu
item or from the 'View' button on the toolbar.

Where are you entering the SQL statement when you get the error?

Ken Sheridan
Stafford, England

Stephen said:
Ken

I am using Office2000 where is SOL view I can not find it

got an run error when I try your code

thank you
Smiles
thanks trying that Ken

Ken Sheridan wrote:
Stephen:

If you are trying to do it in query design view in the 'field row' of
one blank column in the query design grid enter:

TotalMiles: Max([End])-Min([Start])

and in the 'total' row select Expression.

In the 'field' row of another blank column enter:

TotalBusinessMiles: [End]-[Start]

and in the 'total' row select Sum.

Apart from checking the 'show' box leave the other rows in the grid
for these two columns blank.

If you still have problems post back the SQL of your query as it now
stands and we'll hopefully be able to sort it out.

Ken Sheridan
Stafford, England
:

Ken Sheridan wrote:
Sum the difference between the two values per row in the table, e.g.
the following would give you the total mileage overall and the total
business:

SELECT MAX(End) – MIN(Start) As TotalMiles,
SUM(End – Start) As TotalBusinessMiles
FROM YourTable;

If the table covers more than one year group the query by
YEAR(YourDateColumn) to give the mileages per calendar year. To
group by the fiscal year you'd need to return the fiscal year from
your dates, unless you've recorded the fiscal year in a column in
the table, and group on that, e.g. for a fiscal year starting 1
April you group by the following expression:

Year(DateAdd("m",-3, YourDateColumn))

Ken Sheridan
Stafford, England
:

I have what is called a flat data base one table
four forms to populate which works fine
two general reports working ok

My car expense report can not be completed.
I was told when I started not to save calculated vales.
My auto expense report adds up all car related expenses fine
I have two boxes that use the start and end mile value to give me
my total year mileage and the other is suppose to give me total
business mileage for the year.
How do I take the start and end mile of each record and add them up
to give me total business mileage.
my query is a sum on all car related items plus min and max of
start and stop records

what I do not know is what do I add to query to give me the other
value
by end-start summing to total

I can get 220 lines of end-start but have a running total

Thank you
Stephen

Thanks Ken

I have my query giving me min & max mileage subtracting one fom the
other does give me total mileage ok

I can not for some reason add to the query the field start & stop
mileage as I have min & max defined

any work around

Thank you
Stephen
Thanks here is the code

*******************************
SELECT DISTINCTROW Min([travel 2007].[start mileage]) AS [Min Of start
mileage], Max([travel 2007].[home mileage]) AS [Max Of home mileage],
Sum([travel 2007].[gas]) AS [Sum Of gas], Sum([travel 2007].[US gas]) AS
[Sum Of US gas], Sum([travel 2007].[US gas2]) AS [Sum Of US gas2],
Sum([travel 2007].[servise $]) AS [Sum Of servise $], Sum([travel
2007].[us cost]) AS [Sum Of us cost], Sum([travel 2007].[gas pur]) AS
[Sum Of gas pur], Sum([travel 2007].[insureance]) AS [Sum Of
insureance], Sum([travel 2007].[plate]) AS [Sum Of plate]
FROM [travel 2007];
******************************
gibberish to me

Thank you for your help
Stephen
 
K

Ken Sheridan

Stephen:

First lets make the query a bit more readable by getting rid of the table
names before each column name (as its all from one table you don't need them)
and by putting in some carriage returns so the reference to each column is on
a new line. To get the total mileage you subtract the MIN([start mileage])
from the MAX([home mileage]), and to get the total business mileage you Sum
the difference between the [start mileage] and the [home mileage] values from
each row. As the table is, to judge by its name, presumably just for 2007
you don't need to group it by year. So the query looks like this:

SELECT
MIN([start mileage]) AS [Start of year mileage],
MAX([home mileage]) AS [End of year mileage],
MAX([home mileage]) - MIN([start mileage]) AS [Total mileage],
SUM([home mileage] – [start mileage]) AS [Total business mileage],
SUM([gas]) AS [Sum Of gas],
SUM([US gas]) AS [Sum Of US gas],
SUM([US gas2]) AS [Sum Of US gas2],
SUM([servise $]) AS [Sum Of servise $],
SUM([us cost]) AS [Sum Of us cost],
SUM([gas pur]) AS [Sum Of gas pur],
SUM([insureance]) AS [Sum Of insureance],
SUM([plate]) AS [Sum Of plate]
FROM [travel 2007];

Just paste the above into the query in SQL view and switch to datasheet
view. You should then get the results you are looking for. If so save the
query.

You'll see that I've changed the first two column names to something more
meaningful than [Min Of start mileage] etc. You don't have to accept the
names Access gives to aggregated columns, but can change them either in SQL
view or in design view.

I assume that you'll have created a new table for 2008 now. Having separate
tables per year is not good database design; it amounts to encoding data (the
year in this case) as table names, whereas it’s a fundamental principle of
the relational database model that data is stored as values at column
positions in rows in tables, and in no other way (its called the 'Information
Principle'). I assume you must have a date column in the table, e.g.
TravelDate, if so you can store everything in one table and get the results
for each year by restricting the query, e.g.

SELECT
< and so on>
FROM [travel]
WHERE YEAR([TravelDate]) = 2007;

or for multiple years:

SELECT
< and so on>
FROM [travel]
WHERE YEAR([TravelDate])
BETWEEN 2005 AND 2007;

which would give the data for the three years, 2005, 2006 and 2007.

It could also be done with:

SELECT
< and so on>
FROM [travel]
WHERE [TravelDate]
BETWEEN #01/01/2005# AND #31/12/2007#;

Note that date literals must be in US date format or an otherwise
internationally unambiguous format (just to catch us Yurpeans out!)

Ken Sheridan
Stafford, England

Stephen said:
Thanks here is the code

*******************************
SELECT DISTINCTROW Min([travel 2007].[start mileage]) AS [Min Of start
mileage], Max([travel 2007].[home mileage]) AS [Max Of home mileage],
Sum([travel 2007].[gas]) AS [Sum Of gas], Sum([travel 2007].[US gas]) AS
[Sum Of US gas], Sum([travel 2007].[US gas2]) AS [Sum Of US gas2],
Sum([travel 2007].[servise $]) AS [Sum Of servise $], Sum([travel
2007].[us cost]) AS [Sum Of us cost], Sum([travel 2007].[gas pur]) AS
[Sum Of gas pur], Sum([travel 2007].[insureance]) AS [Sum Of
insureance], Sum([travel 2007].[plate]) AS [Sum Of plate]
FROM [travel 2007];
******************************
gibberish to me

Thank you for your help
Stephen
 
S

Stephen

Thanks Ken

I will look at this in the morning and let you know

Just an insight because of conflicts at work this database is for 2007 I
have started a totally new data base for 2008 not a table

because of fools at work each year going back to 1994 is a different
database spreadsheet or something no cross reference is possible

Now I am independent of others access is my choose my company wants
excel what I do next year I do not know other than the items are fixed
after setting up a new database I can cut and paste or import from excel
to create a new system

the company has come up with a excel paper form to fill in and they will
do all the work and send me the results. Well last year they were off by
$0.18 per Kl on auto expenses which I ate along with other loses
I am not a programmer and am have a fun time learning this but with what
I know I am a head with this work

once again thanks Ken
Thank you
Stephen


Ken said:
Stephen:

First lets make the query a bit more readable by getting rid of the table
names before each column name (as its all from one table you don't need them)
and by putting in some carriage returns so the reference to each column is on
a new line. To get the total mileage you subtract the MIN([start mileage])
from the MAX([home mileage]), and to get the total business mileage you Sum
the difference between the [start mileage] and the [home mileage] values from
each row. As the table is, to judge by its name, presumably just for 2007
you don't need to group it by year. So the query looks like this:

SELECT
MIN([start mileage]) AS [Start of year mileage],
MAX([home mileage]) AS [End of year mileage],
MAX([home mileage]) - MIN([start mileage]) AS [Total mileage],
SUM([home mileage] – [start mileage]) AS [Total business mileage],
SUM([gas]) AS [Sum Of gas],
SUM([US gas]) AS [Sum Of US gas],
SUM([US gas2]) AS [Sum Of US gas2],
SUM([servise $]) AS [Sum Of servise $],
SUM([us cost]) AS [Sum Of us cost],
SUM([gas pur]) AS [Sum Of gas pur],
SUM([insureance]) AS [Sum Of insureance],
SUM([plate]) AS [Sum Of plate]
FROM [travel 2007];

Just paste the above into the query in SQL view and switch to datasheet
view. You should then get the results you are looking for. If so save the
query.

You'll see that I've changed the first two column names to something more
meaningful than [Min Of start mileage] etc. You don't have to accept the
names Access gives to aggregated columns, but can change them either in SQL
view or in design view.

I assume that you'll have created a new table for 2008 now. Having separate
tables per year is not good database design; it amounts to encoding data (the
year in this case) as table names, whereas it’s a fundamental principle of
the relational database model that data is stored as values at column
positions in rows in tables, and in no other way (its called the 'Information
Principle'). I assume you must have a date column in the table, e.g.
TravelDate, if so you can store everything in one table and get the results
for each year by restricting the query, e.g.

SELECT
< and so on>
FROM [travel]
WHERE YEAR([TravelDate]) = 2007;

or for multiple years:

SELECT
< and so on>
FROM [travel]
WHERE YEAR([TravelDate])
BETWEEN 2005 AND 2007;

which would give the data for the three years, 2005, 2006 and 2007.

It could also be done with:

SELECT
< and so on>
FROM [travel]
WHERE [TravelDate]
BETWEEN #01/01/2005# AND #31/12/2007#;

Note that date literals must be in US date format or an otherwise
internationally unambiguous format (just to catch us Yurpeans out!)

Ken Sheridan
Stafford, England

Stephen said:
Thanks here is the code

*******************************
SELECT DISTINCTROW Min([travel 2007].[start mileage]) AS [Min Of start
mileage], Max([travel 2007].[home mileage]) AS [Max Of home mileage],
Sum([travel 2007].[gas]) AS [Sum Of gas], Sum([travel 2007].[US gas]) AS
[Sum Of US gas], Sum([travel 2007].[US gas2]) AS [Sum Of US gas2],
Sum([travel 2007].[servise $]) AS [Sum Of servise $], Sum([travel
2007].[us cost]) AS [Sum Of us cost], Sum([travel 2007].[gas pur]) AS
[Sum Of gas pur], Sum([travel 2007].[insureance]) AS [Sum Of
insureance], Sum([travel 2007].[plate]) AS [Sum Of plate]
FROM [travel 2007];
******************************
gibberish to me

Thank you for your help
Stephen
 
S

Stephen

Thank you Ken

it worked thanks looks good had to make a new report but the wizard did
it nicely just a few tweaks
Stephen
Thanks Ken

I will look at this in the morning and let you know

Just an insight because of conflicts at work this database is for 2007 I
have started a totally new data base for 2008 not a table

because of fools at work each year going back to 1994 is a different
database spreadsheet or something no cross reference is possible

Now I am independent of others access is my choose my company wants
excel what I do next year I do not know other than the items are fixed
after setting up a new database I can cut and paste or import from excel
to create a new system

the company has come up with a excel paper form to fill in and they will
do all the work and send me the results. Well last year they were off by
$0.18 per Kl on auto expenses which I ate along with other loses
I am not a programmer and am have a fun time learning this but with what
I know I am a head with this work

once again thanks Ken
Thank you
Stephen


Ken said:
Stephen:

First lets make the query a bit more readable by getting rid of the
table names before each column name (as its all from one table you
don't need them) and by putting in some carriage returns so the
reference to each column is on a new line. To get the total mileage
you subtract the MIN([start mileage]) from the MAX([home mileage]),
and to get the total business mileage you Sum the difference between
the [start mileage] and the [home mileage] values from each row. As
the table is, to judge by its name, presumably just for 2007 you don't
need to group it by year. So the query looks like this:

SELECT MIN([start mileage]) AS [Start of year mileage], MAX([home
mileage]) AS [End of year mileage],
MAX([home mileage]) - MIN([start mileage]) AS [Total mileage],
SUM([home mileage] – [start mileage]) AS [Total business mileage],
SUM([gas]) AS [Sum Of gas], SUM([US gas]) AS [Sum Of US gas], SUM([US
gas2]) AS [Sum Of US gas2], SUM([servise $]) AS [Sum Of servise $],
SUM([us cost]) AS [Sum Of us cost], SUM([gas pur]) AS [Sum Of gas
pur], SUM([insureance]) AS [Sum Of insureance], SUM([plate]) AS [Sum
Of plate]
FROM [travel 2007];

Just paste the above into the query in SQL view and switch to
datasheet view. You should then get the results you are looking for.
If so save the query.

You'll see that I've changed the first two column names to something
more meaningful than [Min Of start mileage] etc. You don't have to
accept the names Access gives to aggregated columns, but can change
them either in SQL view or in design view.

I assume that you'll have created a new table for 2008 now. Having
separate tables per year is not good database design; it amounts to
encoding data (the year in this case) as table names, whereas it’s a
fundamental principle of the relational database model that data is
stored as values at column positions in rows in tables, and in no
other way (its called the 'Information Principle'). I assume you must
have a date column in the table, e.g. TravelDate, if so you can store
everything in one table and get the results for each year by
restricting the query, e.g.

SELECT
< and so on>
FROM [travel]
WHERE YEAR([TravelDate]) = 2007;

or for multiple years:

SELECT
< and so on>
FROM [travel]
WHERE YEAR([TravelDate]) BETWEEN 2005 AND 2007;

which would give the data for the three years, 2005, 2006 and 2007.

It could also be done with:

SELECT
< and so on>
FROM [travel]
WHERE [TravelDate]
BETWEEN #01/01/2005# AND #31/12/2007#;

Note that date literals must be in US date format or an otherwise
internationally unambiguous format (just to catch us Yurpeans out!)

Ken Sheridan
Stafford, England
Stephen said:
Thanks here is the code

*******************************
SELECT DISTINCTROW Min([travel 2007].[start mileage]) AS [Min Of
start mileage], Max([travel 2007].[home mileage]) AS [Max Of home
mileage], Sum([travel 2007].[gas]) AS [Sum Of gas], Sum([travel
2007].[US gas]) AS [Sum Of US gas], Sum([travel 2007].[US gas2]) AS
[Sum Of US gas2], Sum([travel 2007].[servise $]) AS [Sum Of servise
$], Sum([travel 2007].[us cost]) AS [Sum Of us cost], Sum([travel
2007].[gas pur]) AS [Sum Of gas pur], Sum([travel 2007].[insureance])
AS [Sum Of insureance], Sum([travel 2007].[plate]) AS [Sum Of plate]
FROM [travel 2007];
******************************
gibberish to me

Thank you for your help
Stephen
 

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