Parameter Query on an expression

J

Joe

I have a calculated (expression) field in my query as an example
Profit:[cost]/[sale price].
I would like to use a parameter query to find less than 75% profit.
Placing "Between[min] and [max]" or "<.75" does not fly.
 
J

John Spencer MVP

I suspect that you need to enter the parameter criteria as

Field: Profit:[cost]/[sale price]
Criteria: < [Enter Percent as decimal fraction]

OR

Field: Profit:[cost]/[sale price]
Criteria: < [Enter Percent whole number]/100

By the way if you have a query that is not working the way you want, it is
usually a good idea to post the actual SQL string. (Open query in design
view, switch to SQL view, copy the SQL and paste it into your message)

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
V

vanderghast

In the computed expression column criteria, use

< 0.75


NO quote around it. That should work unless cost or [sale price] is itself
another computed expression.

In the SQL view you should have a WHERE clause (or the HAVING clause) which
repeat the computed expression and which DOES NOT use the alias. Ie:

SELECT [cost]/[sale price] AS Profit ...
WHERE [cost]/[sale price] < 0.75


and NOT:

SELECT [cost]/[sale price] AS Profit ...
WHERE Profit < 0.75


since the computed expression, and alias, ARE NOT DONE YET when the WHERE
clause is to be evaluated, in general. Sure, if cost is also a computed
expression, you should use the expression, NOT the alias given to the
expression:


SELECT unitPrice * Quantity AS cost, cost/[sale price] AS profit, ...
WHERE unitPrice * Quantity/[sale price] < 0.75


and NOT:

SELECT unitPrice * Quantity AS cost, cost/[sale price] AS profit, ...
WHERE cost/[sale price] < 0.75





Vanderghast, Access MVP
 
J

Joe

I am not using SQL I am using the query form. The problem I believe is I can
not place "where" in the "Total" row since it is an expression.
If I place anything in the "criteria" row then it will prompt me for the
"Cost" and the "sale price" which are in the formula and have values already
assigned to them.
It seems once there is a criteria access no longer knows the values of the
cost and sale price. I would expect it to determine what the "Profit" value
is and conpare it to the criteria. This would seem to be a standard operation
to filter by a calulated value.



vanderghast said:
In the computed expression column criteria, use

< 0.75


NO quote around it. That should work unless cost or [sale price] is itself
another computed expression.

In the SQL view you should have a WHERE clause (or the HAVING clause) which
repeat the computed expression and which DOES NOT use the alias. Ie:

SELECT [cost]/[sale price] AS Profit ...
WHERE [cost]/[sale price] < 0.75


and NOT:

SELECT [cost]/[sale price] AS Profit ...
WHERE Profit < 0.75


since the computed expression, and alias, ARE NOT DONE YET when the WHERE
clause is to be evaluated, in general. Sure, if cost is also a computed
expression, you should use the expression, NOT the alias given to the
expression:


SELECT unitPrice * Quantity AS cost, cost/[sale price] AS profit, ...
WHERE unitPrice * Quantity/[sale price] < 0.75


and NOT:

SELECT unitPrice * Quantity AS cost, cost/[sale price] AS profit, ...
WHERE cost/[sale price] < 0.75





Vanderghast, Access MVP



Joe said:
I have a calculated (expression) field in my query as an example
Profit:[cost]/[sale price].
I would like to use a parameter query to find less than 75% profit.
Placing "Between[min] and [max]" or "<.75" does not fly.
 
J

John Spencer MVP

Since you are using TOTALS, you will need to add the expression a second time
and set the Total to WHERE

Field: FilterON:[cost]/[sale price]
Total: WHERE
Criteria: < [Enter Percent as decimal fraction]

As noted earlier, it helps if you post the SQL of the query that is not
working for you.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
I am not using SQL I am using the query form. The problem I believe is I can
not place "where" in the "Total" row since it is an expression.
If I place anything in the "criteria" row then it will prompt me for the
"Cost" and the "sale price" which are in the formula and have values already
assigned to them.
It seems once there is a criteria access no longer knows the values of the
cost and sale price. I would expect it to determine what the "Profit" value
is and conpare it to the criteria. This would seem to be a standard operation
to filter by a calulated value.



vanderghast said:
In the computed expression column criteria, use

< 0.75


NO quote around it. That should work unless cost or [sale price] is itself
another computed expression.

In the SQL view you should have a WHERE clause (or the HAVING clause) which
repeat the computed expression and which DOES NOT use the alias. Ie:

SELECT [cost]/[sale price] AS Profit ...
WHERE [cost]/[sale price] < 0.75


and NOT:

SELECT [cost]/[sale price] AS Profit ...
WHERE Profit < 0.75


since the computed expression, and alias, ARE NOT DONE YET when the WHERE
clause is to be evaluated, in general. Sure, if cost is also a computed
expression, you should use the expression, NOT the alias given to the
expression:


SELECT unitPrice * Quantity AS cost, cost/[sale price] AS profit, ...
WHERE unitPrice * Quantity/[sale price] < 0.75


and NOT:

SELECT unitPrice * Quantity AS cost, cost/[sale price] AS profit, ...
WHERE cost/[sale price] < 0.75





Vanderghast, Access MVP



Joe said:
I have a calculated (expression) field in my query as an example
Profit:[cost]/[sale price].
I would like to use a parameter query to find less than 75% profit.
Placing "Between[min] and [max]" or "<.75" does not fly.
 
J

Joe

I tried that before it still prompts me for the values for LOTSACC and
COUNTOFQTYRCV



SELECT rec.vid, rec.item, rec.rcvr, Count(rec.qtyrcv) AS CountOfqtyrcv,
Count(rec.dc1) AS CountOfdc1, [CountOfqtyrcv]-[CountOfdc1] AS LotsAcc,
Sum(rec.qtyrcv) AS SumOfqtyrcv, Sum(rec.qtyacc) AS SumOfqtyacc,
([LotsAcc]/[CountOfqtyrcv]) AS Rating, Max(rec.datee) AS MaxOfdatee
FROM rec
WHERE (((rec.datee) Between [Start] And [End]) AND
((([LotsAcc]/[CountOfqtyrcv]))<[enter value]))
GROUP BY rec.vid, rec.item, rec.rcvr;


John Spencer MVP said:
Since you are using TOTALS, you will need to add the expression a second time
and set the Total to WHERE

Field: FilterON:[cost]/[sale price]
Total: WHERE
Criteria: < [Enter Percent as decimal fraction]

As noted earlier, it helps if you post the SQL of the query that is not
working for you.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
I am not using SQL I am using the query form. The problem I believe is I can
not place "where" in the "Total" row since it is an expression.
If I place anything in the "criteria" row then it will prompt me for the
"Cost" and the "sale price" which are in the formula and have values already
assigned to them.
It seems once there is a criteria access no longer knows the values of the
cost and sale price. I would expect it to determine what the "Profit" value
is and conpare it to the criteria. This would seem to be a standard operation
to filter by a calulated value.



vanderghast said:
In the computed expression column criteria, use

< 0.75


NO quote around it. That should work unless cost or [sale price] is itself
another computed expression.

In the SQL view you should have a WHERE clause (or the HAVING clause) which
repeat the computed expression and which DOES NOT use the alias. Ie:

SELECT [cost]/[sale price] AS Profit ...
WHERE [cost]/[sale price] < 0.75


and NOT:

SELECT [cost]/[sale price] AS Profit ...
WHERE Profit < 0.75


since the computed expression, and alias, ARE NOT DONE YET when the WHERE
clause is to be evaluated, in general. Sure, if cost is also a computed
expression, you should use the expression, NOT the alias given to the
expression:


SELECT unitPrice * Quantity AS cost, cost/[sale price] AS profit, ...
WHERE unitPrice * Quantity/[sale price] < 0.75


and NOT:

SELECT unitPrice * Quantity AS cost, cost/[sale price] AS profit, ...
WHERE cost/[sale price] < 0.75





Vanderghast, Access MVP



I have a calculated (expression) field in my query as an example
Profit:[cost]/[sale price].
I would like to use a parameter query to find less than 75% profit.
Placing "Between[min] and [max]" or "<.75" does not fly.
 
V

vanderghast

It is because you CANNOT USE ALIAS in the WHERE clause, but have to repeat
the expression the alias stands for. And you used not one, but two levels of
alias : LotsAcc depends on CountOfqtrce which is itself an alias for a
computed expression.

Furthermore, since the computed expression involves aggregate, some of the
criteria have to be moved in the HAVING clause.


Try:


SELECT rec.vid, rec.item, rec.rcvr, Count(rec.qtyrcv) AS CountOfqtyrcv,
Count(rec.dc1) AS CountOfdc1, [CountOfqtyrcv]-[CountOfdc1] AS LotsAcc,
Sum(rec.qtyrcv) AS SumOfqtyrcv, Sum(rec.qtyacc) AS SumOfqtyacc,
([LotsAcc]/[CountOfqtyrcv]) AS Rating, Max(rec.datee) AS MaxOfdatee
FROM rec
WHERE (rec.datee Between [Start] And [End])
GROUP BY rec.vid, rec.item, rec.rcvr
HAVING (Count(rec.qtyrcv)- Count(rec.dc1))/Count(rec.qtyrcv) < [ enter
value ]


.... if I am right with the parenthesis, that is...



Vanderghast, Access MVP


Joe said:
I tried that before it still prompts me for the values for LOTSACC and
COUNTOFQTYRCV



SELECT rec.vid, rec.item, rec.rcvr, Count(rec.qtyrcv) AS CountOfqtyrcv,
Count(rec.dc1) AS CountOfdc1, [CountOfqtyrcv]-[CountOfdc1] AS LotsAcc,
Sum(rec.qtyrcv) AS SumOfqtyrcv, Sum(rec.qtyacc) AS SumOfqtyacc,
([LotsAcc]/[CountOfqtyrcv]) AS Rating, Max(rec.datee) AS MaxOfdatee
FROM rec
WHERE (((rec.datee) Between [Start] And [End]) AND
((([LotsAcc]/[CountOfqtyrcv]))<[enter value]))
GROUP BY rec.vid, rec.item, rec.rcvr;


John Spencer MVP said:
Since you are using TOTALS, you will need to add the expression a second
time
and set the Total to WHERE

Field: FilterON:[cost]/[sale price]
Total: WHERE
Criteria: < [Enter Percent as decimal fraction]

As noted earlier, it helps if you post the SQL of the query that is not
working for you.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
I am not using SQL I am using the query form. The problem I believe is
I can
not place "where" in the "Total" row since it is an expression.
If I place anything in the "criteria" row then it will prompt me for
the
"Cost" and the "sale price" which are in the formula and have values
already
assigned to them.
It seems once there is a criteria access no longer knows the values of
the
cost and sale price. I would expect it to determine what the "Profit"
value
is and conpare it to the criteria. This would seem to be a standard
operation
to filter by a calulated value.



:

In the computed expression column criteria, use

< 0.75


NO quote around it. That should work unless cost or [sale price] is
itself
another computed expression.

In the SQL view you should have a WHERE clause (or the HAVING clause)
which
repeat the computed expression and which DOES NOT use the alias. Ie:

SELECT [cost]/[sale price] AS Profit ...
WHERE [cost]/[sale price] < 0.75


and NOT:

SELECT [cost]/[sale price] AS Profit ...
WHERE Profit < 0.75


since the computed expression, and alias, ARE NOT DONE YET when the
WHERE
clause is to be evaluated, in general. Sure, if cost is also a
computed
expression, you should use the expression, NOT the alias given to the
expression:


SELECT unitPrice * Quantity AS cost, cost/[sale price] AS
profit, ...
WHERE unitPrice * Quantity/[sale price] < 0.75


and NOT:

SELECT unitPrice * Quantity AS cost, cost/[sale price] AS
profit, ...
WHERE cost/[sale price] < 0.75





Vanderghast, Access MVP



I have a calculated (expression) field in my query as an example
Profit:[cost]/[sale price].
I would like to use a parameter query to find less than 75% profit.
Placing "Between[min] and [max]" or "<.75" does not fly.
 
J

Joe

Thank you you were correct no alias allowed. it does work. I have one more
simple question to close this. I can place <.75 in the criteria of the Query
form and it works. if I place
< [enter value]
it does not. What is the correct format if I want all values less than
[enter value].
I could use BETWEEN [LOW] AND [HIGH] were low would always be 0 and high
would be .75. I figure I am missing some punctuation mark

vanderghast said:
It is because you CANNOT USE ALIAS in the WHERE clause, but have to repeat
the expression the alias stands for. And you used not one, but two levels of
alias : LotsAcc depends on CountOfqtrce which is itself an alias for a
computed expression.

Furthermore, since the computed expression involves aggregate, some of the
criteria have to be moved in the HAVING clause.


Try:


SELECT rec.vid, rec.item, rec.rcvr, Count(rec.qtyrcv) AS CountOfqtyrcv,
Count(rec.dc1) AS CountOfdc1, [CountOfqtyrcv]-[CountOfdc1] AS LotsAcc,
Sum(rec.qtyrcv) AS SumOfqtyrcv, Sum(rec.qtyacc) AS SumOfqtyacc,
([LotsAcc]/[CountOfqtyrcv]) AS Rating, Max(rec.datee) AS MaxOfdatee
FROM rec
WHERE (rec.datee Between [Start] And [End])
GROUP BY rec.vid, rec.item, rec.rcvr
HAVING (Count(rec.qtyrcv)- Count(rec.dc1))/Count(rec.qtyrcv) < [ enter
value ]


.... if I am right with the parenthesis, that is...



Vanderghast, Access MVP


Joe said:
I tried that before it still prompts me for the values for LOTSACC and
COUNTOFQTYRCV



SELECT rec.vid, rec.item, rec.rcvr, Count(rec.qtyrcv) AS CountOfqtyrcv,
Count(rec.dc1) AS CountOfdc1, [CountOfqtyrcv]-[CountOfdc1] AS LotsAcc,
Sum(rec.qtyrcv) AS SumOfqtyrcv, Sum(rec.qtyacc) AS SumOfqtyacc,
([LotsAcc]/[CountOfqtyrcv]) AS Rating, Max(rec.datee) AS MaxOfdatee
FROM rec
WHERE (((rec.datee) Between [Start] And [End]) AND
((([LotsAcc]/[CountOfqtyrcv]))<[enter value]))
GROUP BY rec.vid, rec.item, rec.rcvr;


John Spencer MVP said:
Since you are using TOTALS, you will need to add the expression a second
time
and set the Total to WHERE

Field: FilterON:[cost]/[sale price]
Total: WHERE
Criteria: < [Enter Percent as decimal fraction]

As noted earlier, it helps if you post the SQL of the query that is not
working for you.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Joe wrote:
I am not using SQL I am using the query form. The problem I believe is
I can
not place "where" in the "Total" row since it is an expression.
If I place anything in the "criteria" row then it will prompt me for
the
"Cost" and the "sale price" which are in the formula and have values
already
assigned to them.
It seems once there is a criteria access no longer knows the values of
the
cost and sale price. I would expect it to determine what the "Profit"
value
is and conpare it to the criteria. This would seem to be a standard
operation
to filter by a calulated value.



:

In the computed expression column criteria, use

< 0.75


NO quote around it. That should work unless cost or [sale price] is
itself
another computed expression.

In the SQL view you should have a WHERE clause (or the HAVING clause)
which
repeat the computed expression and which DOES NOT use the alias. Ie:

SELECT [cost]/[sale price] AS Profit ...
WHERE [cost]/[sale price] < 0.75


and NOT:

SELECT [cost]/[sale price] AS Profit ...
WHERE Profit < 0.75


since the computed expression, and alias, ARE NOT DONE YET when the
WHERE
clause is to be evaluated, in general. Sure, if cost is also a
computed
expression, you should use the expression, NOT the alias given to the
expression:


SELECT unitPrice * Quantity AS cost, cost/[sale price] AS
profit, ...
WHERE unitPrice * Quantity/[sale price] < 0.75


and NOT:

SELECT unitPrice * Quantity AS cost, cost/[sale price] AS
profit, ...
WHERE cost/[sale price] < 0.75





Vanderghast, Access MVP



I have a calculated (expression) field in my query as an example
Profit:[cost]/[sale price].
I would like to use a parameter query to find less than 75% profit.
Placing "Between[min] and [max]" or "<.75" does not fly.
 
V

vanderghast

It should work in SQL view, if you add the parameter there. If you add the
criteria under the alias, in graphical design view, since the alias implies
another alias, that does not work, because the Access query designer will
just 'unroll' one alias level for you, which is not enough (because there
are still alias in the expression the Access automatically generates). So,
either you write the full expression, in the Access query designer (in
graphical view), without using ANY alias, and under that EXPRESSION (in the
Total line), instead of GROUP or WHERE or other aggregate, use EXPRESSION),
add the criteria:

< [ Enter value]



Vanderghast, Access MVP


Joe said:
Thank you you were correct no alias allowed. it does work. I have one more
simple question to close this. I can place <.75 in the criteria of the
Query
form and it works. if I place
< [enter value]
it does not. What is the correct format if I want all values less than
[enter value].
I could use BETWEEN [LOW] AND [HIGH] were low would always be 0 and high
would be .75. I figure I am missing some punctuation mark

vanderghast said:
It is because you CANNOT USE ALIAS in the WHERE clause, but have to
repeat
the expression the alias stands for. And you used not one, but two levels
of
alias : LotsAcc depends on CountOfqtrce which is itself an alias for a
computed expression.

Furthermore, since the computed expression involves aggregate, some of
the
criteria have to be moved in the HAVING clause.


Try:


SELECT rec.vid, rec.item, rec.rcvr, Count(rec.qtyrcv) AS CountOfqtyrcv,
Count(rec.dc1) AS CountOfdc1, [CountOfqtyrcv]-[CountOfdc1] AS LotsAcc,
Sum(rec.qtyrcv) AS SumOfqtyrcv, Sum(rec.qtyacc) AS SumOfqtyacc,
([LotsAcc]/[CountOfqtyrcv]) AS Rating, Max(rec.datee) AS MaxOfdatee
FROM rec
WHERE (rec.datee Between [Start] And [End])
GROUP BY rec.vid, rec.item, rec.rcvr
HAVING (Count(rec.qtyrcv)- Count(rec.dc1))/Count(rec.qtyrcv) < [ enter
value ]


.... if I am right with the parenthesis, that is...



Vanderghast, Access MVP


Joe said:
I tried that before it still prompts me for the values for LOTSACC and
COUNTOFQTYRCV



SELECT rec.vid, rec.item, rec.rcvr, Count(rec.qtyrcv) AS CountOfqtyrcv,
Count(rec.dc1) AS CountOfdc1, [CountOfqtyrcv]-[CountOfdc1] AS LotsAcc,
Sum(rec.qtyrcv) AS SumOfqtyrcv, Sum(rec.qtyacc) AS SumOfqtyacc,
([LotsAcc]/[CountOfqtyrcv]) AS Rating, Max(rec.datee) AS MaxOfdatee
FROM rec
WHERE (((rec.datee) Between [Start] And [End]) AND
((([LotsAcc]/[CountOfqtyrcv]))<[enter value]))
GROUP BY rec.vid, rec.item, rec.rcvr;


:

Since you are using TOTALS, you will need to add the expression a
second
time
and set the Total to WHERE

Field: FilterON:[cost]/[sale price]
Total: WHERE
Criteria: < [Enter Percent as decimal fraction]

As noted earlier, it helps if you post the SQL of the query that is
not
working for you.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Joe wrote:
I am not using SQL I am using the query form. The problem I believe
is
I can
not place "where" in the "Total" row since it is an expression.
If I place anything in the "criteria" row then it will prompt me for
the
"Cost" and the "sale price" which are in the formula and have values
already
assigned to them.
It seems once there is a criteria access no longer knows the values
of
the
cost and sale price. I would expect it to determine what the
"Profit"
value
is and conpare it to the criteria. This would seem to be a standard
operation
to filter by a calulated value.



:

In the computed expression column criteria, use

< 0.75


NO quote around it. That should work unless cost or [sale price]
is
itself
another computed expression.

In the SQL view you should have a WHERE clause (or the HAVING
clause)
which
repeat the computed expression and which DOES NOT use the alias.
Ie:

SELECT [cost]/[sale price] AS Profit ...
WHERE [cost]/[sale price] < 0.75


and NOT:

SELECT [cost]/[sale price] AS Profit ...
WHERE Profit < 0.75


since the computed expression, and alias, ARE NOT DONE YET when the
WHERE
clause is to be evaluated, in general. Sure, if cost is also a
computed
expression, you should use the expression, NOT the alias given to
the
expression:


SELECT unitPrice * Quantity AS cost, cost/[sale price] AS
profit, ...
WHERE unitPrice * Quantity/[sale price] < 0.75


and NOT:

SELECT unitPrice * Quantity AS cost, cost/[sale price] AS
profit, ...
WHERE cost/[sale price] < 0.75





Vanderghast, Access MVP



I have a calculated (expression) field in my query as an example
Profit:[cost]/[sale price].
I would like to use a parameter query to find less than 75%
profit.
Placing "Between[min] and [max]" or "<.75" does not fly.
 

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