Union Query with a Crosstab Query

R

ryguy7272

I have two select queries; one for one type of revenue booked by sales reps
which is called 'Bookings' and the other for another type of revenue
generated by sales reps, and this is classified as 'Search'. These two
queries are combined in another query which is a Union Query. This works
fine. Now, I split out the sales rep revenue, by rep and by advertiser, via
a Crosstab Query. All of this works fine. I'm wondering if I can add in
another revenue element, which is a 'Goal'. When I pull in the Goal, through
the Select Queries, the Goal is repeated each time the Rep name appears (the
rep name appears several times to show the Bookings by Advertiser and several
times to show the Search by Advertiser). My question is this: How can I get
the Goal to appear once, either through the Union Query or the Crosstab
Query? Ultimately this will be exported to Excel and I can eliminate dupes
in Excel, but that takes a little work; I'd like to just do everything in
Access if possible. That way, I can just export the final query as a
SpreadSheet and just fire off an email to the recipient...rather than
creating an Excel macro to clean up the Goal-redundancies.

I can post all SQL if that helps; I'm just trying to get a grasp of the
concept at this point. Maybe this is not even possible, but I'd like to know
one way or the other.

Thanks!!
Ryan--
 
K

Ken Snell \(MVP\)

Use a DLookup function to return the value of the Goal field in the query:

SELECT *,
DLookup("Goal", "TableQueryName", "SalesRep='" &
[SalesRepFieldFromTableName] & "'") AS Goal
FROM TableName;
 
R

ryguy7272

Thanks Ken!! It looks like it should work but...

I received this message:
The specified field '[Rep]' could refer to more than one table listed in the
FROM clause of your SQL statement.

SQL is below:
SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals", "Rep='" &
[Rep] & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN [Bookings and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] = tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser;


I believe this will work, but I'm getting that error message and when I
click through, I just see all blanks in the 'Goals' Field...but it certainly
seems like it will work because the 'Goals' Field is in there...it's just
that no 'Goals' are being pulled in. Would love to resolve this before the
end of '08…



Thanks so much,
Ryan---


--
RyGuy


Ken Snell (MVP) said:
Use a DLookup function to return the value of the Goal field in the query:

SELECT *,
DLookup("Goal", "TableQueryName", "SalesRep='" &
[SalesRepFieldFromTableName] & "'") AS Goal
FROM TableName;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


ryguy7272 said:
I have two select queries; one for one type of revenue booked by sales reps
which is called 'Bookings' and the other for another type of revenue
generated by sales reps, and this is classified as 'Search'. These two
queries are combined in another query which is a Union Query. This works
fine. Now, I split out the sales rep revenue, by rep and by advertiser,
via
a Crosstab Query. All of this works fine. I'm wondering if I can add in
another revenue element, which is a 'Goal'. When I pull in the Goal,
through
the Select Queries, the Goal is repeated each time the Rep name appears
(the
rep name appears several times to show the Bookings by Advertiser and
several
times to show the Search by Advertiser). My question is this: How can I
get
the Goal to appear once, either through the Union Query or the Crosstab
Query? Ultimately this will be exported to Excel and I can eliminate
dupes
in Excel, but that takes a little work; I'd like to just do everything in
Access if possible. That way, I can just export the final query as a
SpreadSheet and just fire off an email to the recipient...rather than
creating an Excel macro to clean up the Goal-redundancies.

I can post all SQL if that helps; I'm just trying to get a grasp of the
concept at this point. Maybe this is not even possible, but I'd like to
know
one way or the other.

Thanks!!
Ryan--
 
K

Ken Snell \(MVP\)

No problem... just give the full reference to that field -- assuming that
it's the [Bookings and Pipe by Advertiser - RVP].Rep field:

SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals", "Rep='" &
[Bookings and Pipe by Advertiser - RVP].Rep & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN [Bookings and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] = tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


ryguy7272 said:
Thanks Ken!! It looks like it should work but...

I received this message:
The specified field '[Rep]' could refer to more than one table listed in
the
FROM clause of your SQL statement.

SQL is below:
SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals", "Rep='" &
[Rep] & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN [Bookings and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] = [Bookings and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] = tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser;


I believe this will work, but I'm getting that error message and when I
click through, I just see all blanks in the 'Goals' Field...but it
certainly
seems like it will work because the 'Goals' Field is in there...it's just
that no 'Goals' are being pulled in. Would love to resolve this before
the
end of '08.



Thanks so much,
Ryan---


--
RyGuy


Ken Snell (MVP) said:
Use a DLookup function to return the value of the Goal field in the
query:

SELECT *,
DLookup("Goal", "TableQueryName", "SalesRep='" &
[SalesRepFieldFromTableName] & "'") AS Goal
FROM TableName;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


ryguy7272 said:
I have two select queries; one for one type of revenue booked by sales
reps
which is called 'Bookings' and the other for another type of revenue
generated by sales reps, and this is classified as 'Search'. These two
queries are combined in another query which is a Union Query. This
works
fine. Now, I split out the sales rep revenue, by rep and by
advertiser,
via
a Crosstab Query. All of this works fine. I'm wondering if I can add
in
another revenue element, which is a 'Goal'. When I pull in the Goal,
through
the Select Queries, the Goal is repeated each time the Rep name appears
(the
rep name appears several times to show the Bookings by Advertiser and
several
times to show the Search by Advertiser). My question is this: How can
I
get
the Goal to appear once, either through the Union Query or the Crosstab
Query? Ultimately this will be exported to Excel and I can eliminate
dupes
in Excel, but that takes a little work; I'd like to just do everything
in
Access if possible. That way, I can just export the final query as a
SpreadSheet and just fire off an email to the recipient...rather than
creating an Excel macro to clean up the Goal-redundancies.

I can post all SQL if that helps; I'm just trying to get a grasp of the
concept at this point. Maybe this is not even possible, but I'd like
to
know
one way or the other.

Thanks!!
Ryan--
 
R

ryguy7272

Evidently, I am still doing something wrong. I have this in the 'Field' of
the QBE Grid:
Goals: DLookUp("[Total - Q408]","tblGoals","Rep = '" & [Bookings and Pipe by
Advertiser - RVP]![Rep] & "'")

The result is 13 incidences of $3,000,000 for Goals for Adam, I surmise it
is because he has 13 Advertisers and I am grouping by Advertiser (as well as
grouping by a couple of other Fields). Next, I have 35 incidences of
$8,000,000 for Goals for Alex, and again, I have 35 Advertisers for Alex. I
thought I could just show $3,000,000 one time for Adam and show $8,000,000
one time for Alex. However, the $3,000,000 is repeated 13 times and
$8,000,000 is repeated 35 times! How can I display the Goal only one time
per Rep? I thought the Dlookup would return the first match (kind of like a
Vlookup in Excel). There doesn't seem to be any advantage to using the
Dlookup, over say, dragging and dropping my Field 'Total - Q408' into the QBE
Grid. Please help!!

Thanks so much,
Ryan---


--
RyGuy


Ken Snell (MVP) said:
No problem... just give the full reference to that field -- assuming that
it's the [Bookings and Pipe by Advertiser - RVP].Rep field:

SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals", "Rep='" &
[Bookings and Pipe by Advertiser - RVP].Rep & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN [Bookings and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] = tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


ryguy7272 said:
Thanks Ken!! It looks like it should work but...

I received this message:
The specified field '[Rep]' could refer to more than one table listed in
the
FROM clause of your SQL statement.

SQL is below:
SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals", "Rep='" &
[Rep] & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN [Bookings and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] = [Bookings and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] = tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser;


I believe this will work, but I'm getting that error message and when I
click through, I just see all blanks in the 'Goals' Field...but it
certainly
seems like it will work because the 'Goals' Field is in there...it's just
that no 'Goals' are being pulled in. Would love to resolve this before
the
end of '08.



Thanks so much,
Ryan---


--
RyGuy


Ken Snell (MVP) said:
Use a DLookup function to return the value of the Goal field in the
query:

SELECT *,
DLookup("Goal", "TableQueryName", "SalesRep='" &
[SalesRepFieldFromTableName] & "'") AS Goal
FROM TableName;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


I have two select queries; one for one type of revenue booked by sales
reps
which is called 'Bookings' and the other for another type of revenue
generated by sales reps, and this is classified as 'Search'. These two
queries are combined in another query which is a Union Query. This
works
fine. Now, I split out the sales rep revenue, by rep and by
advertiser,
via
a Crosstab Query. All of this works fine. I'm wondering if I can add
in
another revenue element, which is a 'Goal'. When I pull in the Goal,
through
the Select Queries, the Goal is repeated each time the Rep name appears
(the
rep name appears several times to show the Bookings by Advertiser and
several
times to show the Search by Advertiser). My question is this: How can
I
get
the Goal to appear once, either through the Union Query or the Crosstab
Query? Ultimately this will be exported to Excel and I can eliminate
dupes
in Excel, but that takes a little work; I'd like to just do everything
in
Access if possible. That way, I can just export the final query as a
SpreadSheet and just fire off an email to the recipient...rather than
creating an Excel macro to clean up the Goal-redundancies.

I can post all SQL if that helps; I'm just trying to get a grasp of the
concept at this point. Maybe this is not even possible, but I'd like
to
know
one way or the other.

Thanks!!
Ryan--
 
K

Ken Snell \(MVP\)

The issue is not the DLookup. It returns only a single value for each record
in the query. The problem is that your query itself is returning the
multiple records. You can confirm this by taking the DLookup field out of
the query and running it.

With the DLookup field, can you not take the tblGoals table out of the
query? I assume that that is the source of the duplication of records. The
DLookup field does what you were wanting from the tblGoals table initially.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/




ryguy7272 said:
Evidently, I am still doing something wrong. I have this in the 'Field'
of
the QBE Grid:
Goals: DLookUp("[Total - Q408]","tblGoals","Rep = '" & [Bookings and Pipe
by
Advertiser - RVP]![Rep] & "'")

The result is 13 incidences of $3,000,000 for Goals for Adam, I surmise it
is because he has 13 Advertisers and I am grouping by Advertiser (as well
as
grouping by a couple of other Fields). Next, I have 35 incidences of
$8,000,000 for Goals for Alex, and again, I have 35 Advertisers for Alex.
I
thought I could just show $3,000,000 one time for Adam and show $8,000,000
one time for Alex. However, the $3,000,000 is repeated 13 times and
$8,000,000 is repeated 35 times! How can I display the Goal only one time
per Rep? I thought the Dlookup would return the first match (kind of like
a
Vlookup in Excel). There doesn't seem to be any advantage to using the
Dlookup, over say, dragging and dropping my Field 'Total - Q408' into the
QBE
Grid. Please help!!

Thanks so much,
Ryan---


--
RyGuy


Ken Snell (MVP) said:
No problem... just give the full reference to that field -- assuming that
it's the [Bookings and Pipe by Advertiser - RVP].Rep field:

SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals", "Rep='" &
[Bookings and Pipe by Advertiser - RVP].Rep & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN [Bookings and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] = [Bookings and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] = tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


ryguy7272 said:
Thanks Ken!! It looks like it should work but...

I received this message:
The specified field '[Rep]' could refer to more than one table listed
in
the
FROM clause of your SQL statement.

SQL is below:
SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum 08Q4
C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals", "Rep='" &
[Rep] & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN [Bookings
and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] = [Bookings and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE =
tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] = tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser;


I believe this will work, but I'm getting that error message and when I
click through, I just see all blanks in the 'Goals' Field...but it
certainly
seems like it will work because the 'Goals' Field is in there...it's
just
that no 'Goals' are being pulled in. Would love to resolve this before
the
end of '08.



Thanks so much,
Ryan---


--
RyGuy


:

Use a DLookup function to return the value of the Goal field in the
query:

SELECT *,
DLookup("Goal", "TableQueryName", "SalesRep='" &
[SalesRepFieldFromTableName] & "'") AS Goal
FROM TableName;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


I have two select queries; one for one type of revenue booked by
sales
reps
which is called 'Bookings' and the other for another type of revenue
generated by sales reps, and this is classified as 'Search'. These
two
queries are combined in another query which is a Union Query. This
works
fine. Now, I split out the sales rep revenue, by rep and by
advertiser,
via
a Crosstab Query. All of this works fine. I'm wondering if I can
add
in
another revenue element, which is a 'Goal'. When I pull in the
Goal,
through
the Select Queries, the Goal is repeated each time the Rep name
appears
(the
rep name appears several times to show the Bookings by Advertiser
and
several
times to show the Search by Advertiser). My question is this: How
can
I
get
the Goal to appear once, either through the Union Query or the
Crosstab
Query? Ultimately this will be exported to Excel and I can
eliminate
dupes
in Excel, but that takes a little work; I'd like to just do
everything
in
Access if possible. That way, I can just export the final query as
a
SpreadSheet and just fire off an email to the recipient...rather
than
creating an Excel macro to clean up the Goal-redundancies.

I can post all SQL if that helps; I'm just trying to get a grasp of
the
concept at this point. Maybe this is not even possible, but I'd
like
to
know
one way or the other.

Thanks!!
Ryan--
 
R

ryguy7272

You are absolutely right Ken! The Dlookup is doing what I want! However, I
am still plagued with many, many, many duplicates for Goals. Let me explain
once more what I want to do and maybe you, or someone, can tell me how best
to do it.

I have a Sales Rep, a VP, a Region, an Advertiser, and then a Total spent by
that Advertiser. This part of the query is working just fine. The problem
occurs when I use Dlookup to pull in the Goals for each Sales Rep. I need
the line by line itemized format for everything but the Goals. For instance,
when I look at Adam, I want to see all 13 of his Advertisers and the money
that each Advertiser spent. For Alex, I want to see all 35 of his
Advertisers and the money that each Advertiser spent, and so on and so forth.
I was hoping to come up with a way of pulling in the Goal for each Rep and
then exporting everything to Excel, do a Subtotal by Rep, and send this, via
Email, to a colleague. The thing that I’m stuck on is that I’m getting a
$3,000,000 Goal for Adam repeated 13 times. I wanted to sum the dollar
amounts spent by the Advertisers that Adam works with, and compare this sum
to his Goal. This is why I want to display the Goal only once. Perhaps
there is a better way of doing this?

BTW, the Dlookup function is very cool!! I’ve never used it before, but I’m
sure I’ll find opportunities to use it more and more in the very near future.


Thanks,
Ryan---


--
RyGuy


Ken Snell (MVP) said:
The issue is not the DLookup. It returns only a single value for each record
in the query. The problem is that your query itself is returning the
multiple records. You can confirm this by taking the DLookup field out of
the query and running it.

With the DLookup field, can you not take the tblGoals table out of the
query? I assume that that is the source of the duplication of records. The
DLookup field does what you were wanting from the tblGoals table initially.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/




ryguy7272 said:
Evidently, I am still doing something wrong. I have this in the 'Field'
of
the QBE Grid:
Goals: DLookUp("[Total - Q408]","tblGoals","Rep = '" & [Bookings and Pipe
by
Advertiser - RVP]![Rep] & "'")

The result is 13 incidences of $3,000,000 for Goals for Adam, I surmise it
is because he has 13 Advertisers and I am grouping by Advertiser (as well
as
grouping by a couple of other Fields). Next, I have 35 incidences of
$8,000,000 for Goals for Alex, and again, I have 35 Advertisers for Alex.
I
thought I could just show $3,000,000 one time for Adam and show $8,000,000
one time for Alex. However, the $3,000,000 is repeated 13 times and
$8,000,000 is repeated 35 times! How can I display the Goal only one time
per Rep? I thought the Dlookup would return the first match (kind of like
a
Vlookup in Excel). There doesn't seem to be any advantage to using the
Dlookup, over say, dragging and dropping my Field 'Total - Q408' into the
QBE
Grid. Please help!!

Thanks so much,
Ryan---


--
RyGuy


Ken Snell (MVP) said:
No problem... just give the full reference to that field -- assuming that
it's the [Bookings and Pipe by Advertiser - RVP].Rep field:

SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals", "Rep='" &
[Bookings and Pipe by Advertiser - RVP].Rep & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN [Bookings and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] = [Bookings and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] = tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Thanks Ken!! It looks like it should work but...

I received this message:
The specified field '[Rep]' could refer to more than one table listed
in
the
FROM clause of your SQL statement.

SQL is below:
SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum 08Q4
C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals", "Rep='" &
[Rep] & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN [Bookings
and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] = [Bookings and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE =
tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] = tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser;


I believe this will work, but I'm getting that error message and when I
click through, I just see all blanks in the 'Goals' Field...but it
certainly
seems like it will work because the 'Goals' Field is in there...it's
just
that no 'Goals' are being pulled in. Would love to resolve this before
the
end of '08.



Thanks so much,
Ryan---


--
RyGuy


:

Use a DLookup function to return the value of the Goal field in the
query:

SELECT *,
DLookup("Goal", "TableQueryName", "SalesRep='" &
[SalesRepFieldFromTableName] & "'") AS Goal
FROM TableName;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


I have two select queries; one for one type of revenue booked by
sales
reps
which is called 'Bookings' and the other for another type of revenue
generated by sales reps, and this is classified as 'Search'. These
two
queries are combined in another query which is a Union Query. This
works
fine. Now, I split out the sales rep revenue, by rep and by
advertiser,
via
a Crosstab Query. All of this works fine. I'm wondering if I can
add
in
another revenue element, which is a 'Goal'. When I pull in the
Goal,
through
the Select Queries, the Goal is repeated each time the Rep name
appears
(the
rep name appears several times to show the Bookings by Advertiser
and
several
times to show the Search by Advertiser). My question is this: How
can
I
get
the Goal to appear once, either through the Union Query or the
Crosstab
Query? Ultimately this will be exported to Excel and I can
eliminate
dupes
in Excel, but that takes a little work; I'd like to just do
everything
in
Access if possible. That way, I can just export the final query as
a
SpreadSheet and just fire off an email to the recipient...rather
than
creating an Excel macro to clean up the Goal-redundancies.

I can post all SQL if that helps; I'm just trying to get a grasp of
the
concept at this point. Maybe this is not even possible, but I'd
like
to
know
one way or the other.

Thanks!!
Ryan--
 
R

ryguy7272

I just thought of something. The Reps field is sorted in Alpha order. Maybe
I could add a field to count the number of Reps, starting at 1 and
incrementing by 1 for each name in the list. If the counter could reset to 1
when it encounters a new name, I may be able to use the Dlookup on this field
and when there is a 1, pull in the Goal for that Rep.
For numerical values:
DLookup("FieldName" , "TableName" , "Criteria = n")

How could I implement that?

Ryan---


--
RyGuy


ryguy7272 said:
You are absolutely right Ken! The Dlookup is doing what I want! However, I
am still plagued with many, many, many duplicates for Goals. Let me explain
once more what I want to do and maybe you, or someone, can tell me how best
to do it.

I have a Sales Rep, a VP, a Region, an Advertiser, and then a Total spent by
that Advertiser. This part of the query is working just fine. The problem
occurs when I use Dlookup to pull in the Goals for each Sales Rep. I need
the line by line itemized format for everything but the Goals. For instance,
when I look at Adam, I want to see all 13 of his Advertisers and the money
that each Advertiser spent. For Alex, I want to see all 35 of his
Advertisers and the money that each Advertiser spent, and so on and so forth.
I was hoping to come up with a way of pulling in the Goal for each Rep and
then exporting everything to Excel, do a Subtotal by Rep, and send this, via
Email, to a colleague. The thing that I’m stuck on is that I’m getting a
$3,000,000 Goal for Adam repeated 13 times. I wanted to sum the dollar
amounts spent by the Advertisers that Adam works with, and compare this sum
to his Goal. This is why I want to display the Goal only once. Perhaps
there is a better way of doing this?

BTW, the Dlookup function is very cool!! I’ve never used it before, but I’m
sure I’ll find opportunities to use it more and more in the very near future.


Thanks,
Ryan---


--
RyGuy


Ken Snell (MVP) said:
The issue is not the DLookup. It returns only a single value for each record
in the query. The problem is that your query itself is returning the
multiple records. You can confirm this by taking the DLookup field out of
the query and running it.

With the DLookup field, can you not take the tblGoals table out of the
query? I assume that that is the source of the duplication of records. The
DLookup field does what you were wanting from the tblGoals table initially.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/




ryguy7272 said:
Evidently, I am still doing something wrong. I have this in the 'Field'
of
the QBE Grid:
Goals: DLookUp("[Total - Q408]","tblGoals","Rep = '" & [Bookings and Pipe
by
Advertiser - RVP]![Rep] & "'")

The result is 13 incidences of $3,000,000 for Goals for Adam, I surmise it
is because he has 13 Advertisers and I am grouping by Advertiser (as well
as
grouping by a couple of other Fields). Next, I have 35 incidences of
$8,000,000 for Goals for Alex, and again, I have 35 Advertisers for Alex.
I
thought I could just show $3,000,000 one time for Adam and show $8,000,000
one time for Alex. However, the $3,000,000 is repeated 13 times and
$8,000,000 is repeated 35 times! How can I display the Goal only one time
per Rep? I thought the Dlookup would return the first match (kind of like
a
Vlookup in Excel). There doesn't seem to be any advantage to using the
Dlookup, over say, dragging and dropping my Field 'Total - Q408' into the
QBE
Grid. Please help!!

Thanks so much,
Ryan---


--
RyGuy


:

No problem... just give the full reference to that field -- assuming that
it's the [Bookings and Pipe by Advertiser - RVP].Rep field:

SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals", "Rep='" &
[Bookings and Pipe by Advertiser - RVP].Rep & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN [Bookings and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] = [Bookings and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] = tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Thanks Ken!! It looks like it should work but...

I received this message:
The specified field '[Rep]' could refer to more than one table listed
in
the
FROM clause of your SQL statement.

SQL is below:
SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum 08Q4
C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals", "Rep='" &
[Rep] & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN [Bookings
and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] = [Bookings and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE =
tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] = tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser;


I believe this will work, but I'm getting that error message and when I
click through, I just see all blanks in the 'Goals' Field...but it
certainly
seems like it will work because the 'Goals' Field is in there...it's
just
that no 'Goals' are being pulled in. Would love to resolve this before
the
end of '08.



Thanks so much,
Ryan---


--
RyGuy


:

Use a DLookup function to return the value of the Goal field in the
query:

SELECT *,
DLookup("Goal", "TableQueryName", "SalesRep='" &
[SalesRepFieldFromTableName] & "'") AS Goal
FROM TableName;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


I have two select queries; one for one type of revenue booked by
sales
reps
which is called 'Bookings' and the other for another type of revenue
generated by sales reps, and this is classified as 'Search'. These
two
queries are combined in another query which is a Union Query. This
works
fine. Now, I split out the sales rep revenue, by rep and by
advertiser,
via
a Crosstab Query. All of this works fine. I'm wondering if I can
add
in
another revenue element, which is a 'Goal'. When I pull in the
Goal,
through
the Select Queries, the Goal is repeated each time the Rep name
appears
(the
rep name appears several times to show the Bookings by Advertiser
and
several
times to show the Search by Advertiser). My question is this: How
can
I
get
the Goal to appear once, either through the Union Query or the
Crosstab
Query? Ultimately this will be exported to Excel and I can
eliminate
dupes
in Excel, but that takes a little work; I'd like to just do
everything
in
Access if possible. That way, I can just export the final query as
a
SpreadSheet and just fire off an email to the recipient...rather
than
creating an Excel macro to clean up the Goal-redundancies.

I can post all SQL if that helps; I'm just trying to get a grasp of
the
concept at this point. Maybe this is not even possible, but I'd
like
to
know
one way or the other.

Thanks!!
Ryan--
 
K

Ken Snell \(MVP\)

Change your query to this:

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
DLookup("Total - Q408", "tblGoals", "Rep='" & [Rep] & "'") AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser - RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser - RVP].Advertiser;


Note that I've removed the tblGoals table from the query. It's not needed
for any of the fields or calculations, and it was causing the duplication of
the data that you were seeing.

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


ryguy7272 said:
You are absolutely right Ken! The Dlookup is doing what I want! However,
I
am still plagued with many, many, many duplicates for Goals. Let me
explain
once more what I want to do and maybe you, or someone, can tell me how
best
to do it.

I have a Sales Rep, a VP, a Region, an Advertiser, and then a Total spent
by
that Advertiser. This part of the query is working just fine. The
problem
occurs when I use Dlookup to pull in the Goals for each Sales Rep. I need
the line by line itemized format for everything but the Goals. For
instance,
when I look at Adam, I want to see all 13 of his Advertisers and the money
that each Advertiser spent. For Alex, I want to see all 35 of his
Advertisers and the money that each Advertiser spent, and so on and so
forth.
I was hoping to come up with a way of pulling in the Goal for each Rep and
then exporting everything to Excel, do a Subtotal by Rep, and send this,
via
Email, to a colleague. The thing that I'm stuck on is that I'm getting a
$3,000,000 Goal for Adam repeated 13 times. I wanted to sum the dollar
amounts spent by the Advertisers that Adam works with, and compare this
sum
to his Goal. This is why I want to display the Goal only once. Perhaps
there is a better way of doing this?

BTW, the Dlookup function is very cool!! I've never used it before, but I'm
sure I'll find opportunities to use it more and more in the very near
future.


Thanks,
Ryan---


--
RyGuy


Ken Snell (MVP) said:
The issue is not the DLookup. It returns only a single value for each
record
in the query. The problem is that your query itself is returning the
multiple records. You can confirm this by taking the DLookup field out of
the query and running it.

With the DLookup field, can you not take the tblGoals table out of the
query? I assume that that is the source of the duplication of records.
The
DLookup field does what you were wanting from the tblGoals table
initially.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/




ryguy7272 said:
Evidently, I am still doing something wrong. I have this in the
'Field'
of
the QBE Grid:
Goals: DLookUp("[Total - Q408]","tblGoals","Rep = '" & [Bookings and
Pipe
by
Advertiser - RVP]![Rep] & "'")

The result is 13 incidences of $3,000,000 for Goals for Adam, I surmise
it
is because he has 13 Advertisers and I am grouping by Advertiser (as
well
as
grouping by a couple of other Fields). Next, I have 35 incidences of
$8,000,000 for Goals for Alex, and again, I have 35 Advertisers for
Alex.
I
thought I could just show $3,000,000 one time for Adam and show
$8,000,000
one time for Alex. However, the $3,000,000 is repeated 13 times and
$8,000,000 is repeated 35 times! How can I display the Goal only one
time
per Rep? I thought the Dlookup would return the first match (kind of
like
a
Vlookup in Excel). There doesn't seem to be any advantage to using the
Dlookup, over say, dragging and dropping my Field 'Total - Q408' into
the
QBE
Grid. Please help!!

Thanks so much,
Ryan---


--
RyGuy


:

No problem... just give the full reference to that field -- assuming
that
it's the [Bookings and Pipe by Advertiser - RVP].Rep field:

SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum 08Q4
C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals", "Rep='"
&
[Bookings and Pipe by Advertiser - RVP].Rep & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN [Bookings
and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] = [Bookings
and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE =
tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] = tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Thanks Ken!! It looks like it should work but...

I received this message:
The specified field '[Rep]' could refer to more than one table
listed
in
the
FROM clause of your SQL statement.

SQL is below:
SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum 08Q4
C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals",
"Rep='" &
[Rep] & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN [Bookings
and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] = [Bookings
and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE =
tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] =
tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser;


I believe this will work, but I'm getting that error message and
when I
click through, I just see all blanks in the 'Goals' Field...but it
certainly
seems like it will work because the 'Goals' Field is in there...it's
just
that no 'Goals' are being pulled in. Would love to resolve this
before
the
end of '08.



Thanks so much,
Ryan---


--
RyGuy


:

Use a DLookup function to return the value of the Goal field in the
query:

SELECT *,
DLookup("Goal", "TableQueryName", "SalesRep='" &
[SalesRepFieldFromTableName] & "'") AS Goal
FROM TableName;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


I have two select queries; one for one type of revenue booked by
sales
reps
which is called 'Bookings' and the other for another type of
revenue
generated by sales reps, and this is classified as 'Search'.
These
two
queries are combined in another query which is a Union Query.
This
works
fine. Now, I split out the sales rep revenue, by rep and by
advertiser,
via
a Crosstab Query. All of this works fine. I'm wondering if I
can
add
in
another revenue element, which is a 'Goal'. When I pull in the
Goal,
through
the Select Queries, the Goal is repeated each time the Rep name
appears
(the
rep name appears several times to show the Bookings by Advertiser
and
several
times to show the Search by Advertiser). My question is this:
How
can
I
get
the Goal to appear once, either through the Union Query or the
Crosstab
Query? Ultimately this will be exported to Excel and I can
eliminate
dupes
in Excel, but that takes a little work; I'd like to just do
everything
in
Access if possible. That way, I can just export the final query
as
a
SpreadSheet and just fire off an email to the recipient...rather
than
creating an Excel macro to clean up the Goal-redundancies.

I can post all SQL if that helps; I'm just trying to get a grasp
of
the
concept at this point. Maybe this is not even possible, but I'd
like
to
know
one way or the other.

Thanks!!
Ryan--
 
R

ryguy7272

Thanks a bunch Ken! However, the problem is still the same. With the
tblGoals out of the Query, the Goal is still repeated multiple times for each
Rep. Maybe Access isn't able to do what I want to do. I can do it in Excel,
but I was hoping to just do everything in Access rather than swapping data
back and forth between Access and Excel.

Is there some way to count Rep's names, maybe in a helper Field,
incrementing by 1, and then restart with 1 each time a new Rep name is
encountered? I think I could do a Dlookup based on the 1s and when a 1 is
encountered pull in that individual's Goal. Would that work? I know Excel
can do that.

Thanks!
Ryan---

--
RyGuy


Ken Snell (MVP) said:
Change your query to this:

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
DLookup("Total - Q408", "tblGoals", "Rep='" & [Rep] & "'") AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser - RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser - RVP].Advertiser;


Note that I've removed the tblGoals table from the query. It's not needed
for any of the fields or calculations, and it was causing the duplication of
the data that you were seeing.

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


ryguy7272 said:
You are absolutely right Ken! The Dlookup is doing what I want! However,
I
am still plagued with many, many, many duplicates for Goals. Let me
explain
once more what I want to do and maybe you, or someone, can tell me how
best
to do it.

I have a Sales Rep, a VP, a Region, an Advertiser, and then a Total spent
by
that Advertiser. This part of the query is working just fine. The
problem
occurs when I use Dlookup to pull in the Goals for each Sales Rep. I need
the line by line itemized format for everything but the Goals. For
instance,
when I look at Adam, I want to see all 13 of his Advertisers and the money
that each Advertiser spent. For Alex, I want to see all 35 of his
Advertisers and the money that each Advertiser spent, and so on and so
forth.
I was hoping to come up with a way of pulling in the Goal for each Rep and
then exporting everything to Excel, do a Subtotal by Rep, and send this,
via
Email, to a colleague. The thing that I'm stuck on is that I'm getting a
$3,000,000 Goal for Adam repeated 13 times. I wanted to sum the dollar
amounts spent by the Advertisers that Adam works with, and compare this
sum
to his Goal. This is why I want to display the Goal only once. Perhaps
there is a better way of doing this?

BTW, the Dlookup function is very cool!! I've never used it before, but I'm
sure I'll find opportunities to use it more and more in the very near
future.


Thanks,
Ryan---


--
RyGuy


Ken Snell (MVP) said:
The issue is not the DLookup. It returns only a single value for each
record
in the query. The problem is that your query itself is returning the
multiple records. You can confirm this by taking the DLookup field out of
the query and running it.

With the DLookup field, can you not take the tblGoals table out of the
query? I assume that that is the source of the duplication of records.
The
DLookup field does what you were wanting from the tblGoals table
initially.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/




Evidently, I am still doing something wrong. I have this in the
'Field'
of
the QBE Grid:
Goals: DLookUp("[Total - Q408]","tblGoals","Rep = '" & [Bookings and
Pipe
by
Advertiser - RVP]![Rep] & "'")

The result is 13 incidences of $3,000,000 for Goals for Adam, I surmise
it
is because he has 13 Advertisers and I am grouping by Advertiser (as
well
as
grouping by a couple of other Fields). Next, I have 35 incidences of
$8,000,000 for Goals for Alex, and again, I have 35 Advertisers for
Alex.
I
thought I could just show $3,000,000 one time for Adam and show
$8,000,000
one time for Alex. However, the $3,000,000 is repeated 13 times and
$8,000,000 is repeated 35 times! How can I display the Goal only one
time
per Rep? I thought the Dlookup would return the first match (kind of
like
a
Vlookup in Excel). There doesn't seem to be any advantage to using the
Dlookup, over say, dragging and dropping my Field 'Total - Q408' into
the
QBE
Grid. Please help!!

Thanks so much,
Ryan---


--
RyGuy


:

No problem... just give the full reference to that field -- assuming
that
it's the [Bookings and Pipe by Advertiser - RVP].Rep field:

SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum 08Q4
C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals", "Rep='"
&
[Bookings and Pipe by Advertiser - RVP].Rep & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN [Bookings
and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] = [Bookings
and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE =
tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] = tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Thanks Ken!! It looks like it should work but...

I received this message:
The specified field '[Rep]' could refer to more than one table
listed
in
the
FROM clause of your SQL statement.

SQL is below:
SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum 08Q4
C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals",
"Rep='" &
[Rep] & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN [Bookings
and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] = [Bookings
and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE =
tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] =
tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser;


I believe this will work, but I'm getting that error message and
when I
click through, I just see all blanks in the 'Goals' Field...but it
certainly
seems like it will work because the 'Goals' Field is in there...it's
just
that no 'Goals' are being pulled in. Would love to resolve this
before
the
end of '08.



Thanks so much,
Ryan---


--
RyGuy


:

Use a DLookup function to return the value of the Goal field in the
query:

SELECT *,
DLookup("Goal", "TableQueryName", "SalesRep='" &
[SalesRepFieldFromTableName] & "'") AS Goal
FROM TableName;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


I have two select queries; one for one type of revenue booked by
sales
reps
which is called 'Bookings' and the other for another type of
revenue
generated by sales reps, and this is classified as 'Search'.
These
two
queries are combined in another query which is a Union Query.
This
works
fine. Now, I split out the sales rep revenue, by rep and by
advertiser,
via
a Crosstab Query. All of this works fine. I'm wondering if I
can
add
in
another revenue element, which is a 'Goal'. When I pull in the
Goal,
through
the Select Queries, the Goal is repeated each time the Rep name
appears
(the
rep name appears several times to show the Bookings by Advertiser
and
several
times to show the Search by Advertiser). My question is this:
How
can
I
get
the Goal to appear once, either through the Union Query or the
Crosstab
Query? Ultimately this will be exported to Excel and I can
eliminate
dupes
in Excel, but that takes a little work; I'd like to just do
everything
in
Access if possible. That way, I can just export the final query
as
a
SpreadSheet and just fire off an email to the recipient...rather
 
K

Ken Snell \(MVP\)

Not knowing your data, can you do a selective edit of the query to see what
is causing the multiple records? By this, I mean delete one table and run
the query; if you still get the duplicate records, start with the original
query again and delete a different table.

Once you can tell us which join is causing the duplication, then we can
design the SQL statement to eliminate the duplication.

As for the "1" idea, I think that is overcomplicating the setup. We should
be able to get the results by just restructuring the query.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


ryguy7272 said:
Thanks a bunch Ken! However, the problem is still the same. With the
tblGoals out of the Query, the Goal is still repeated multiple times for
each
Rep. Maybe Access isn't able to do what I want to do. I can do it in
Excel,
but I was hoping to just do everything in Access rather than swapping data
back and forth between Access and Excel.

Is there some way to count Rep's names, maybe in a helper Field,
incrementing by 1, and then restart with 1 each time a new Rep name is
encountered? I think I could do a Dlookup based on the 1s and when a 1 is
encountered pull in that individual's Goal. Would that work? I know
Excel
can do that.

Thanks!
Ryan---

--
RyGuy


Ken Snell (MVP) said:
Change your query to this:

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
DLookup("Total - Q408", "tblGoals", "Rep='" & [Rep] & "'") AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser -
RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser -
RVP].Advertiser;


Note that I've removed the tblGoals table from the query. It's not needed
for any of the fields or calculations, and it was causing the duplication
of
the data that you were seeing.

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


ryguy7272 said:
You are absolutely right Ken! The Dlookup is doing what I want!
However,
I
am still plagued with many, many, many duplicates for Goals. Let me
explain
once more what I want to do and maybe you, or someone, can tell me how
best
to do it.

I have a Sales Rep, a VP, a Region, an Advertiser, and then a Total
spent
by
that Advertiser. This part of the query is working just fine. The
problem
occurs when I use Dlookup to pull in the Goals for each Sales Rep. I
need
the line by line itemized format for everything but the Goals. For
instance,
when I look at Adam, I want to see all 13 of his Advertisers and the
money
that each Advertiser spent. For Alex, I want to see all 35 of his
Advertisers and the money that each Advertiser spent, and so on and so
forth.
I was hoping to come up with a way of pulling in the Goal for each Rep
and
then exporting everything to Excel, do a Subtotal by Rep, and send
this,
via
Email, to a colleague. The thing that I'm stuck on is that I'm getting
a
$3,000,000 Goal for Adam repeated 13 times. I wanted to sum the dollar
amounts spent by the Advertisers that Adam works with, and compare this
sum
to his Goal. This is why I want to display the Goal only once.
Perhaps
there is a better way of doing this?

BTW, the Dlookup function is very cool!! I've never used it before,
but I'm
sure I'll find opportunities to use it more and more in the very near
future.


Thanks,
Ryan---


--
RyGuy


:

The issue is not the DLookup. It returns only a single value for each
record
in the query. The problem is that your query itself is returning the
multiple records. You can confirm this by taking the DLookup field out
of
the query and running it.

With the DLookup field, can you not take the tblGoals table out of the
query? I assume that that is the source of the duplication of records.
The
DLookup field does what you were wanting from the tblGoals table
initially.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/




Evidently, I am still doing something wrong. I have this in the
'Field'
of
the QBE Grid:
Goals: DLookUp("[Total - Q408]","tblGoals","Rep = '" & [Bookings and
Pipe
by
Advertiser - RVP]![Rep] & "'")

The result is 13 incidences of $3,000,000 for Goals for Adam, I
surmise
it
is because he has 13 Advertisers and I am grouping by Advertiser (as
well
as
grouping by a couple of other Fields). Next, I have 35 incidences
of
$8,000,000 for Goals for Alex, and again, I have 35 Advertisers for
Alex.
I
thought I could just show $3,000,000 one time for Adam and show
$8,000,000
one time for Alex. However, the $3,000,000 is repeated 13 times and
$8,000,000 is repeated 35 times! How can I display the Goal only
one
time
per Rep? I thought the Dlookup would return the first match (kind
of
like
a
Vlookup in Excel). There doesn't seem to be any advantage to using
the
Dlookup, over say, dragging and dropping my Field 'Total - Q408'
into
the
QBE
Grid. Please help!!

Thanks so much,
Ryan---


--
RyGuy


:

No problem... just give the full reference to that field --
assuming
that
it's the [Bookings and Pipe by Advertiser - RVP].Rep field:

SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by
Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum
08Q4
C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals",
"Rep='"
&
[Bookings and Pipe by Advertiser - RVP].Rep & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings
and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] = [Bookings
and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE =
tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] =
tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe by
Advertiser - RVP].Advertiser;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Thanks Ken!! It looks like it should work but...

I received this message:
The specified field '[Rep]' could refer to more than one table
listed
in
the
FROM clause of your SQL statement.

SQL is below:
SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe
by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by
Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum
08Q4
C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals",
"Rep='" &
[Rep] & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings
and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] =
[Bookings
and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE =
tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] =
tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings
and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe
by
Advertiser - RVP].Advertiser;


I believe this will work, but I'm getting that error message and
when I
click through, I just see all blanks in the 'Goals' Field...but
it
certainly
seems like it will work because the 'Goals' Field is in
there...it's
just
that no 'Goals' are being pulled in. Would love to resolve this
before
the
end of '08.



Thanks so much,
Ryan---


--
RyGuy


:

Use a DLookup function to return the value of the Goal field in
the
query:

SELECT *,
DLookup("Goal", "TableQueryName", "SalesRep='" &
[SalesRepFieldFromTableName] & "'") AS Goal
FROM TableName;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


message
I have two select queries; one for one type of revenue booked
by
sales
reps
which is called 'Bookings' and the other for another type of
revenue
generated by sales reps, and this is classified as 'Search'.
These
two
queries are combined in another query which is a Union Query.
This
works
fine. Now, I split out the sales rep revenue, by rep and by
advertiser,
via
a Crosstab Query. All of this works fine. I'm wondering if I
can
add
in
another revenue element, which is a 'Goal'. When I pull in
the
Goal,
through
the Select Queries, the Goal is repeated each time the Rep
name
appears
(the
rep name appears several times to show the Bookings by
Advertiser
and
several
times to show the Search by Advertiser). My question is this:
How
can
I
get
the Goal to appear once, either through the Union Query or the
Crosstab
Query? Ultimately this will be exported to Excel and I can
eliminate
dupes
in Excel, but that takes a little work; I'd like to just do
everything
in
Access if possible. That way, I can just export the final
query
as
a
SpreadSheet and just fire off an email to the
recipient...rather
 
K

Ken Snell \(MVP\)

Or, perhaps I'm completely misunderstanding what you want. Do you want those
duplicate records in the query, but just want the Goals amount to be
displayed for a single record for a Rep and not for all the records for that
Rep?
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Ken Snell (MVP) said:
Not knowing your data, can you do a selective edit of the query to see
what is causing the multiple records? By this, I mean delete one table and
run the query; if you still get the duplicate records, start with the
original query again and delete a different table.

Once you can tell us which join is causing the duplication, then we can
design the SQL statement to eliminate the duplication.

As for the "1" idea, I think that is overcomplicating the setup. We should
be able to get the results by just restructuring the query.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


ryguy7272 said:
Thanks a bunch Ken! However, the problem is still the same. With the
tblGoals out of the Query, the Goal is still repeated multiple times for
each
Rep. Maybe Access isn't able to do what I want to do. I can do it in
Excel,
but I was hoping to just do everything in Access rather than swapping
data
back and forth between Access and Excel.

Is there some way to count Rep's names, maybe in a helper Field,
incrementing by 1, and then restart with 1 each time a new Rep name is
encountered? I think I could do a Dlookup based on the 1s and when a 1
is
encountered pull in that individual's Goal. Would that work? I know
Excel
can do that.

Thanks!
Ryan---

--
RyGuy


Ken Snell (MVP) said:
Change your query to this:

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
DLookup("Total - Q408", "tblGoals", "Rep='" & [Rep] & "'") AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser -
RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser -
RVP].Advertiser;


Note that I've removed the tblGoals table from the query. It's not
needed
for any of the fields or calculations, and it was causing the
duplication of
the data that you were seeing.

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


You are absolutely right Ken! The Dlookup is doing what I want!
However,
I
am still plagued with many, many, many duplicates for Goals. Let me
explain
once more what I want to do and maybe you, or someone, can tell me how
best
to do it.

I have a Sales Rep, a VP, a Region, an Advertiser, and then a Total
spent
by
that Advertiser. This part of the query is working just fine. The
problem
occurs when I use Dlookup to pull in the Goals for each Sales Rep. I
need
the line by line itemized format for everything but the Goals. For
instance,
when I look at Adam, I want to see all 13 of his Advertisers and the
money
that each Advertiser spent. For Alex, I want to see all 35 of his
Advertisers and the money that each Advertiser spent, and so on and so
forth.
I was hoping to come up with a way of pulling in the Goal for each Rep
and
then exporting everything to Excel, do a Subtotal by Rep, and send
this,
via
Email, to a colleague. The thing that I'm stuck on is that I'm
getting a
$3,000,000 Goal for Adam repeated 13 times. I wanted to sum the
dollar
amounts spent by the Advertisers that Adam works with, and compare
this
sum
to his Goal. This is why I want to display the Goal only once.
Perhaps
there is a better way of doing this?

BTW, the Dlookup function is very cool!! I've never used it before,
but I'm
sure I'll find opportunities to use it more and more in the very near
future.


Thanks,
Ryan---


--
RyGuy


:

The issue is not the DLookup. It returns only a single value for each
record
in the query. The problem is that your query itself is returning the
multiple records. You can confirm this by taking the DLookup field
out of
the query and running it.

With the DLookup field, can you not take the tblGoals table out of
the
query? I assume that that is the source of the duplication of
records.
The
DLookup field does what you were wanting from the tblGoals table
initially.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/




Evidently, I am still doing something wrong. I have this in the
'Field'
of
the QBE Grid:
Goals: DLookUp("[Total - Q408]","tblGoals","Rep = '" & [Bookings
and
Pipe
by
Advertiser - RVP]![Rep] & "'")

The result is 13 incidences of $3,000,000 for Goals for Adam, I
surmise
it
is because he has 13 Advertisers and I am grouping by Advertiser
(as
well
as
grouping by a couple of other Fields). Next, I have 35 incidences
of
$8,000,000 for Goals for Alex, and again, I have 35 Advertisers for
Alex.
I
thought I could just show $3,000,000 one time for Adam and show
$8,000,000
one time for Alex. However, the $3,000,000 is repeated 13 times
and
$8,000,000 is repeated 35 times! How can I display the Goal only
one
time
per Rep? I thought the Dlookup would return the first match (kind
of
like
a
Vlookup in Excel). There doesn't seem to be any advantage to using
the
Dlookup, over say, dragging and dropping my Field 'Total - Q408'
into
the
QBE
Grid. Please help!!

Thanks so much,
Ryan---


--
RyGuy


:

No problem... just give the full reference to that field --
assuming
that
it's the [Bookings and Pipe by Advertiser - RVP].Rep field:

SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe
by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by
Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum
08Q4
C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals",
"Rep='"
&
[Bookings and Pipe by Advertiser - RVP].Rep & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings
and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] =
[Bookings
and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE =
tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] =
tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings
and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe
by
Advertiser - RVP].Advertiser;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Thanks Ken!! It looks like it should work but...

I received this message:
The specified field '[Rep]' could refer to more than one table
listed
in
the
FROM clause of your SQL statement.

SQL is below:
SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings
and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe
by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by
Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum
08Q4
C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals",
"Rep='" &
[Rep] & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings
and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] =
[Bookings
and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE =
tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] =
tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings
and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe
by
Advertiser - RVP].Advertiser;


I believe this will work, but I'm getting that error message and
when I
click through, I just see all blanks in the 'Goals' Field...but
it
certainly
seems like it will work because the 'Goals' Field is in
there...it's
just
that no 'Goals' are being pulled in. Would love to resolve this
before
the
end of '08.



Thanks so much,
Ryan---


--
RyGuy


:

Use a DLookup function to return the value of the Goal field in
the
query:

SELECT *,
DLookup("Goal", "TableQueryName", "SalesRep='" &
[SalesRepFieldFromTableName] & "'") AS Goal
FROM TableName;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


message
I have two select queries; one for one type of revenue booked
by
sales
reps
which is called 'Bookings' and the other for another type of
revenue
generated by sales reps, and this is classified as 'Search'.
These
two
queries are combined in another query which is a Union Query.
This
works
fine. Now, I split out the sales rep revenue, by rep and by
advertiser,
via
a Crosstab Query. All of this works fine. I'm wondering if
I
can
add
in
another revenue element, which is a 'Goal'. When I pull in
the
Goal,
through
the Select Queries, the Goal is repeated each time the Rep
name
appears
(the
rep name appears several times to show the Bookings by
Advertiser
and
several
times to show the Search by Advertiser). My question is
this:
How
can
I
get
the Goal to appear once, either through the Union Query or
the
Crosstab
Query? Ultimately this will be exported to Excel and I can
eliminate
dupes
in Excel, but that takes a little work; I'd like to just do
everything
in
Access if possible. That way, I can just export the final
query
as
a
SpreadSheet and just fire off an email to the
recipient...rather
 
R

ryguy7272

Yes, yes, yes! I need some duplicate records in the query, but just want the
Goals amount to be displayed for a single record for a Rep. I have a rep
named Adam and he has 13 Advertisers. I am showing the revenue from each
Advertiser, which is 13 records, and I want to show Adam’s Goal, which is one
record. This is one of two select Queries. I then combine the results in a
UnionQuery and finally rearrange it in a CrosstabQuery. The UnionQuery and
CrosstabQuery work great without the Goals in there. Howver, I need the
Goals in there so I can compare the sum of the revenues from all Advertisers
with the Goal. This is how I can tell if a rep is 70% to Goal, 90% to Goal,
100% to Goal, or whatever…20% to Goal. Does that make sense?

I’m trying to learn how to do this in Access. I can do it in Excel pretty
easy, but I’d like to learn the nuts and bolts of Access and it would be a
whole lot easier to keep this all in Access, and simply convert the final
Query to a spreadsheet, after all work is done in Access.

Thanks for the follow through Ken!!


--
RyGuy


Ken Snell (MVP) said:
Or, perhaps I'm completely misunderstanding what you want. Do you want those
duplicate records in the query, but just want the Goals amount to be
displayed for a single record for a Rep and not for all the records for that
Rep?
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Ken Snell (MVP) said:
Not knowing your data, can you do a selective edit of the query to see
what is causing the multiple records? By this, I mean delete one table and
run the query; if you still get the duplicate records, start with the
original query again and delete a different table.

Once you can tell us which join is causing the duplication, then we can
design the SQL statement to eliminate the duplication.

As for the "1" idea, I think that is overcomplicating the setup. We should
be able to get the results by just restructuring the query.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


ryguy7272 said:
Thanks a bunch Ken! However, the problem is still the same. With the
tblGoals out of the Query, the Goal is still repeated multiple times for
each
Rep. Maybe Access isn't able to do what I want to do. I can do it in
Excel,
but I was hoping to just do everything in Access rather than swapping
data
back and forth between Access and Excel.

Is there some way to count Rep's names, maybe in a helper Field,
incrementing by 1, and then restart with 1 each time a new Rep name is
encountered? I think I could do a Dlookup based on the 1s and when a 1
is
encountered pull in that individual's Goal. Would that work? I know
Excel
can do that.

Thanks!
Ryan---

--
RyGuy


:

Change your query to this:

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
DLookup("Total - Q408", "tblGoals", "Rep='" & [Rep] & "'") AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser -
RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser -
RVP].Advertiser;


Note that I've removed the tblGoals table from the query. It's not
needed
for any of the fields or calculations, and it was causing the
duplication of
the data that you were seeing.

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


You are absolutely right Ken! The Dlookup is doing what I want!
However,
I
am still plagued with many, many, many duplicates for Goals. Let me
explain
once more what I want to do and maybe you, or someone, can tell me how
best
to do it.

I have a Sales Rep, a VP, a Region, an Advertiser, and then a Total
spent
by
that Advertiser. This part of the query is working just fine. The
problem
occurs when I use Dlookup to pull in the Goals for each Sales Rep. I
need
the line by line itemized format for everything but the Goals. For
instance,
when I look at Adam, I want to see all 13 of his Advertisers and the
money
that each Advertiser spent. For Alex, I want to see all 35 of his
Advertisers and the money that each Advertiser spent, and so on and so
forth.
I was hoping to come up with a way of pulling in the Goal for each Rep
and
then exporting everything to Excel, do a Subtotal by Rep, and send
this,
via
Email, to a colleague. The thing that I'm stuck on is that I'm
getting a
$3,000,000 Goal for Adam repeated 13 times. I wanted to sum the
dollar
amounts spent by the Advertisers that Adam works with, and compare
this
sum
to his Goal. This is why I want to display the Goal only once.
Perhaps
there is a better way of doing this?

BTW, the Dlookup function is very cool!! I've never used it before,
but I'm
sure I'll find opportunities to use it more and more in the very near
future.


Thanks,
Ryan---


--
RyGuy


:

The issue is not the DLookup. It returns only a single value for each
record
in the query. The problem is that your query itself is returning the
multiple records. You can confirm this by taking the DLookup field
out of
the query and running it.

With the DLookup field, can you not take the tblGoals table out of
the
query? I assume that that is the source of the duplication of
records.
The
DLookup field does what you were wanting from the tblGoals table
initially.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/




Evidently, I am still doing something wrong. I have this in the
'Field'
of
the QBE Grid:
Goals: DLookUp("[Total - Q408]","tblGoals","Rep = '" & [Bookings
and
Pipe
by
Advertiser - RVP]![Rep] & "'")

The result is 13 incidences of $3,000,000 for Goals for Adam, I
surmise
it
is because he has 13 Advertisers and I am grouping by Advertiser
(as
well
as
grouping by a couple of other Fields). Next, I have 35 incidences
of
$8,000,000 for Goals for Alex, and again, I have 35 Advertisers for
Alex.
I
thought I could just show $3,000,000 one time for Adam and show
$8,000,000
one time for Alex. However, the $3,000,000 is repeated 13 times
and
$8,000,000 is repeated 35 times! How can I display the Goal only
one
time
per Rep? I thought the Dlookup would return the first match (kind
of
like
a
Vlookup in Excel). There doesn't seem to be any advantage to using
the
Dlookup, over say, dragging and dropping my Field 'Total - Q408'
into
the
QBE
Grid. Please help!!

Thanks so much,
Ryan---


--
RyGuy


:

No problem... just give the full reference to that field --
assuming
that
it's the [Bookings and Pipe by Advertiser - RVP].Rep field:

SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe
by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by
Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum
08Q4
C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals",
"Rep='"
&
[Bookings and Pipe by Advertiser - RVP].Rep & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings
and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] =
[Bookings
and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE =
tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] =
tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings
and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe
by
Advertiser - RVP].Advertiser;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Thanks Ken!! It looks like it should work but...

I received this message:
The specified field '[Rep]' could refer to more than one table
listed
in
the
FROM clause of your SQL statement.

SQL is below:
SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings
and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and Pipe
by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by
Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum
08Q4
C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals",
"Rep='" &
[Rep] & "'") AS Goal
 
K

Ken Snell \(MVP\)

OK, then let's try this query.

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
IIf((SELECT Min(T.RVP) AS MinRVP FROM [Bookings and Pipe by Advertiser -
RVP] AS T
WHERE T.Rep = tblRVP_Mapping.[Sales Rep]) = [Bookings and Pipe by
Advertiser - RVP].RVP,
DLookup("Total - Q408", "tblGoals", "Rep='" & [Bookings and Pipe by
Advertiser - RVP].Rep & "'"), NULL) AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser - RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser - RVP].Advertiser;


The above query should show the Goals amount for just one of the records for
each SalesRep, though it may not be the first record in the query's order
for that SalesRep. If you want that, you can change the query to this:

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
IIf((SELECT Min(T.RVP) AS MinRVP FROM [Bookings and Pipe by Advertiser -
RVP] AS T
WHERE T.Rep = tblRVP_Mapping.[Sales Rep]) = [Bookings and Pipe by
Advertiser - RVP].RVP,
DLookup("Total - Q408", "tblGoals", "Rep='" & [Bookings and Pipe by
Advertiser - RVP].Rep & "'"), NULL) AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser - RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser - RVP].Advertiser
ORDER BY [Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP;
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


ryguy7272 said:
Yes, yes, yes! I need some duplicate records in the query, but just want
the
Goals amount to be displayed for a single record for a Rep. I have a rep
named Adam and he has 13 Advertisers. I am showing the revenue from each
Advertiser, which is 13 records, and I want to show Adam's Goal, which is
one
record. This is one of two select Queries. I then combine the results in
a
UnionQuery and finally rearrange it in a CrosstabQuery. The UnionQuery
and
CrosstabQuery work great without the Goals in there. Howver, I need the
Goals in there so I can compare the sum of the revenues from all
Advertisers
with the Goal. This is how I can tell if a rep is 70% to Goal, 90% to
Goal,
100% to Goal, or whatever.20% to Goal. Does that make sense?

I'm trying to learn how to do this in Access. I can do it in Excel pretty
easy, but I'd like to learn the nuts and bolts of Access and it would be a
whole lot easier to keep this all in Access, and simply convert the final
Query to a spreadsheet, after all work is done in Access.

Thanks for the follow through Ken!!


--
RyGuy


Ken Snell (MVP) said:
Or, perhaps I'm completely misunderstanding what you want. Do you want
those
duplicate records in the query, but just want the Goals amount to be
displayed for a single record for a Rep and not for all the records for
that
Rep?
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Ken Snell (MVP) said:
Not knowing your data, can you do a selective edit of the query to see
what is causing the multiple records? By this, I mean delete one table
and
run the query; if you still get the duplicate records, start with the
original query again and delete a different table.

Once you can tell us which join is causing the duplication, then we can
design the SQL statement to eliminate the duplication.

As for the "1" idea, I think that is overcomplicating the setup. We
should
be able to get the results by just restructuring the query.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Thanks a bunch Ken! However, the problem is still the same. With the
tblGoals out of the Query, the Goal is still repeated multiple times
for
each
Rep. Maybe Access isn't able to do what I want to do. I can do it in
Excel,
but I was hoping to just do everything in Access rather than swapping
data
back and forth between Access and Excel.

Is there some way to count Rep's names, maybe in a helper Field,
incrementing by 1, and then restart with 1 each time a new Rep name is
encountered? I think I could do a Dlookup based on the 1s and when a
1
is
encountered pull in that individual's Goal. Would that work? I know
Excel
can do that.

Thanks!
Ryan---

--
RyGuy


:

Change your query to this:

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings
and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
DLookup("Total - Q408", "tblGoals", "Rep='" & [Rep] & "'") AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser -
RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser -
RVP].Advertiser;


Note that I've removed the tblGoals table from the query. It's not
needed
for any of the fields or calculations, and it was causing the
duplication of
the data that you were seeing.

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


You are absolutely right Ken! The Dlookup is doing what I want!
However,
I
am still plagued with many, many, many duplicates for Goals. Let
me
explain
once more what I want to do and maybe you, or someone, can tell me
how
best
to do it.

I have a Sales Rep, a VP, a Region, an Advertiser, and then a Total
spent
by
that Advertiser. This part of the query is working just fine. The
problem
occurs when I use Dlookup to pull in the Goals for each Sales Rep.
I
need
the line by line itemized format for everything but the Goals. For
instance,
when I look at Adam, I want to see all 13 of his Advertisers and
the
money
that each Advertiser spent. For Alex, I want to see all 35 of his
Advertisers and the money that each Advertiser spent, and so on and
so
forth.
I was hoping to come up with a way of pulling in the Goal for each
Rep
and
then exporting everything to Excel, do a Subtotal by Rep, and send
this,
via
Email, to a colleague. The thing that I'm stuck on is that I'm
getting a
$3,000,000 Goal for Adam repeated 13 times. I wanted to sum the
dollar
amounts spent by the Advertisers that Adam works with, and compare
this
sum
to his Goal. This is why I want to display the Goal only once.
Perhaps
there is a better way of doing this?

BTW, the Dlookup function is very cool!! I've never used it
before,
but I'm
sure I'll find opportunities to use it more and more in the very
near
future.


Thanks,
Ryan---


--
RyGuy


:

The issue is not the DLookup. It returns only a single value for
each
record
in the query. The problem is that your query itself is returning
the
multiple records. You can confirm this by taking the DLookup field
out of
the query and running it.

With the DLookup field, can you not take the tblGoals table out of
the
query? I assume that that is the source of the duplication of
records.
The
DLookup field does what you were wanting from the tblGoals table
initially.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/




Evidently, I am still doing something wrong. I have this in the
'Field'
of
the QBE Grid:
Goals: DLookUp("[Total - Q408]","tblGoals","Rep = '" & [Bookings
and
Pipe
by
Advertiser - RVP]![Rep] & "'")

The result is 13 incidences of $3,000,000 for Goals for Adam, I
surmise
it
is because he has 13 Advertisers and I am grouping by Advertiser
(as
well
as
grouping by a couple of other Fields). Next, I have 35
incidences
of
$8,000,000 for Goals for Alex, and again, I have 35 Advertisers
for
Alex.
I
thought I could just show $3,000,000 one time for Adam and show
$8,000,000
one time for Alex. However, the $3,000,000 is repeated 13 times
and
$8,000,000 is repeated 35 times! How can I display the Goal
only
one
time
per Rep? I thought the Dlookup would return the first match
(kind
of
like
a
Vlookup in Excel). There doesn't seem to be any advantage to
using
the
Dlookup, over say, dragging and dropping my Field 'Total - Q408'
into
the
QBE
Grid. Please help!!

Thanks so much,
Ryan---


--
RyGuy


:

No problem... just give the full reference to that field --
assuming
that
it's the [Bookings and Pipe by Advertiser - RVP].Rep field:

SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings
and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and
Pipe
by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by
Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser - RVP]![Sum
08Q4
C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals",
"Rep='"
&
[Bookings and Pipe by Advertiser - RVP].Rep & "'") AS Goal
FROM (tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings
and
Pipe by Advertiser - RVP] ON tblRVP_Mapping.[Sales Rep] =
[Bookings
and
Pipe
by Advertiser - RVP].Rep) ON tblRep_Summary.AE =
tblRVP_Mapping.[Backyard
ID]) INNER JOIN tblGoals ON tblRVP_Mapping.[Backyard ID] =
tblGoals.ID
GROUP BY [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings
and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and
Pipe
by
Advertiser - RVP].Advertiser;

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


message
Thanks Ken!! It looks like it should work but...

I received this message:
The specified field '[Rep]' could refer to more than one
table
listed
in
the
FROM clause of your SQL statement.

SQL is below:
SELECT [Bookings and Pipe by Advertiser - RVP].Rep, [Bookings
and
Pipe
by
Advertiser - RVP].RVP, tblRep_Summary.Region, [Bookings and
Pipe
by
Advertiser - RVP].Advertiser, Sum([Bookings and Pipe by
Advertiser -
RVP]![Sum 08Q4 C1]+[Bookings and Pipe by Advertiser -
RVP]![Sum
08Q4
C2])
AS
[Bookings by Advertiser], DLookup("Total - Q408", "tblGoals",
"Rep='" &
[Rep] & "'") AS Goal
 
R

ryguy7272

Thanks once again Ken! When I attempt to run both (new) queries, I now get
prompted to enter a parameter. Message Reads: Enter Parameter Value:
tblRVP_Mapping.Sales Rep

When I click ‘OK’ nothing is returned.

I fiddled around with the IIF function for a bout ½ hour and couldn’t figure
it out. I’ve seen the T. method used before, but I am not familiar with it
at all. Perhaps that is the culprit. Also, why would Access need T.RVP?
Wouldn’t it be T.Rep? The Reps are under the RVPs, that’s for sure, but I am
querying for Rep and Advertiser revenue; I’m just pulling in the RVP names to
see the hierarchy of the teams.

I’ll keep playing with it. I hope I can make this work. It has been a
great learning opportunity and if I can get this thing working it will be
very practical and very useful. Any idea what could be causing the parameter
to jump up?

Thanks once again,
Ryan---


--
RyGuy


Ken Snell (MVP) said:
OK, then let's try this query.

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
IIf((SELECT Min(T.RVP) AS MinRVP FROM [Bookings and Pipe by Advertiser -
RVP] AS T
WHERE T.Rep = tblRVP_Mapping.[Sales Rep]) = [Bookings and Pipe by
Advertiser - RVP].RVP,
DLookup("Total - Q408", "tblGoals", "Rep='" & [Bookings and Pipe by
Advertiser - RVP].Rep & "'"), NULL) AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser - RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser - RVP].Advertiser;


The above query should show the Goals amount for just one of the records for
each SalesRep, though it may not be the first record in the query's order
for that SalesRep. If you want that, you can change the query to this:

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
IIf((SELECT Min(T.RVP) AS MinRVP FROM [Bookings and Pipe by Advertiser -
RVP] AS T
WHERE T.Rep = tblRVP_Mapping.[Sales Rep]) = [Bookings and Pipe by
Advertiser - RVP].RVP,
DLookup("Total - Q408", "tblGoals", "Rep='" & [Bookings and Pipe by
Advertiser - RVP].Rep & "'"), NULL) AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser - RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser - RVP].Advertiser
ORDER BY [Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP;
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


ryguy7272 said:
Yes, yes, yes! I need some duplicate records in the query, but just want
the
Goals amount to be displayed for a single record for a Rep. I have a rep
named Adam and he has 13 Advertisers. I am showing the revenue from each
Advertiser, which is 13 records, and I want to show Adam's Goal, which is
one
record. This is one of two select Queries. I then combine the results in
a
UnionQuery and finally rearrange it in a CrosstabQuery. The UnionQuery
and
CrosstabQuery work great without the Goals in there. Howver, I need the
Goals in there so I can compare the sum of the revenues from all
Advertisers
with the Goal. This is how I can tell if a rep is 70% to Goal, 90% to
Goal,
100% to Goal, or whatever.20% to Goal. Does that make sense?

I'm trying to learn how to do this in Access. I can do it in Excel pretty
easy, but I'd like to learn the nuts and bolts of Access and it would be a
whole lot easier to keep this all in Access, and simply convert the final
Query to a spreadsheet, after all work is done in Access.

Thanks for the follow through Ken!!


--
RyGuy


Ken Snell (MVP) said:
Or, perhaps I'm completely misunderstanding what you want. Do you want
those
duplicate records in the query, but just want the Goals amount to be
displayed for a single record for a Rep and not for all the records for
that
Rep?
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Not knowing your data, can you do a selective edit of the query to see
what is causing the multiple records? By this, I mean delete one table
and
run the query; if you still get the duplicate records, start with the
original query again and delete a different table.

Once you can tell us which join is causing the duplication, then we can
design the SQL statement to eliminate the duplication.

As for the "1" idea, I think that is overcomplicating the setup. We
should
be able to get the results by just restructuring the query.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Thanks a bunch Ken! However, the problem is still the same. With the
tblGoals out of the Query, the Goal is still repeated multiple times
for
each
Rep. Maybe Access isn't able to do what I want to do. I can do it in
Excel,
but I was hoping to just do everything in Access rather than swapping
data
back and forth between Access and Excel.

Is there some way to count Rep's names, maybe in a helper Field,
incrementing by 1, and then restart with 1 each time a new Rep name is
encountered? I think I could do a Dlookup based on the 1s and when a
1
is
encountered pull in that individual's Goal. Would that work? I know
Excel
can do that.

Thanks!
Ryan---

--
RyGuy


:

Change your query to this:

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings
and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
DLookup("Total - Q408", "tblGoals", "Rep='" & [Rep] & "'") AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser -
RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser -
RVP].Advertiser;


Note that I've removed the tblGoals table from the query. It's not
needed
for any of the fields or calculations, and it was causing the
duplication of
the data that you were seeing.

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


You are absolutely right Ken! The Dlookup is doing what I want!
However,
I
am still plagued with many, many, many duplicates for Goals. Let
me
explain
once more what I want to do and maybe you, or someone, can tell me
how
best
to do it.

I have a Sales Rep, a VP, a Region, an Advertiser, and then a Total
spent
by
that Advertiser. This part of the query is working just fine. The
problem
occurs when I use Dlookup to pull in the Goals for each Sales Rep.
I
need
the line by line itemized format for everything but the Goals. For
instance,
when I look at Adam, I want to see all 13 of his Advertisers and
the
money
that each Advertiser spent. For Alex, I want to see all 35 of his
Advertisers and the money that each Advertiser spent, and so on and
so
forth.
I was hoping to come up with a way of pulling in the Goal for each
Rep
and
then exporting everything to Excel, do a Subtotal by Rep, and send
this,
via
Email, to a colleague. The thing that I'm stuck on is that I'm
getting a
$3,000,000 Goal for Adam repeated 13 times. I wanted to sum the
dollar
amounts spent by the Advertisers that Adam works with, and compare
this
sum
to his Goal. This is why I want to display the Goal only once.
Perhaps
there is a better way of doing this?

BTW, the Dlookup function is very cool!! I've never used it
before,
but I'm
sure I'll find opportunities to use it more and more in the very
near
future.


Thanks,
Ryan---


--
RyGuy


:

The issue is not the DLookup. It returns only a single value for
each
record
in the query. The problem is that your query itself is returning
the
multiple records. You can confirm this by taking the DLookup field
out of
the query and running it.

With the DLookup field, can you not take the tblGoals table out of
the
query? I assume that that is the source of the duplication of
records.
The
DLookup field does what you were wanting from the tblGoals table
initially.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/




Evidently, I am still doing something wrong. I have this in the
'Field'
of
the QBE Grid:
Goals: DLookUp("[Total - Q408]","tblGoals","Rep = '" & [Bookings
and
Pipe
by
Advertiser - RVP]![Rep] & "'")

The result is 13 incidences of $3,000,000 for Goals for Adam, I
surmise
it
 
K

Ken Snell \(MVP\)

Looks like I used the wrong field in the subquery -- the
tblRVP_Mapping.[Sales Rep] field is not in the SELECT clause. Try this for
the query:

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
IIf((SELECT Min(T.RVP) AS MinRVP FROM [Bookings and Pipe by Advertiser -
RVP] AS T
WHERE T.Rep = [Bookings and Pipe by Advertiser - RVP].[Rep]) =
[Bookings and Pipe by Advertiser - RVP].RVP,
DLookup("Total - Q408", "tblGoals", "Rep='" & [Bookings and Pipe by
Advertiser - RVP].Rep & "'"), NULL) AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser - RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser - RVP].Advertiser;


The use of the T is to give the subquery's table an alias so that Jet/ACCESS
are not confused by which instance of the [Bookings and Pipe by Advertiser -
RVP] table is to be used in the subquery as the FROM table and in the WHERE
clause.


--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/



ryguy7272 said:
Thanks once again Ken! When I attempt to run both (new) queries, I now
get
prompted to enter a parameter. Message Reads: Enter Parameter Value:
tblRVP_Mapping.Sales Rep

When I click 'OK' nothing is returned.

I fiddled around with the IIF function for a bout ½ hour and couldn't
figure
it out. I've seen the T. method used before, but I am not familiar with
it
at all. Perhaps that is the culprit. Also, why would Access need T.RVP?
Wouldn't it be T.Rep? The Reps are under the RVPs, that's for sure, but I
am
querying for Rep and Advertiser revenue; I'm just pulling in the RVP names
to
see the hierarchy of the teams.

I'll keep playing with it. I hope I can make this work. It has been a
great learning opportunity and if I can get this thing working it will be
very practical and very useful. Any idea what could be causing the
parameter
to jump up?

Thanks once again,
Ryan---


--
RyGuy


Ken Snell (MVP) said:
OK, then let's try this query.

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
IIf((SELECT Min(T.RVP) AS MinRVP FROM [Bookings and Pipe by Advertiser -
RVP] AS T
WHERE T.Rep = tblRVP_Mapping.[Sales Rep]) = [Bookings and Pipe by
Advertiser - RVP].RVP,
DLookup("Total - Q408", "tblGoals", "Rep='" & [Bookings and Pipe by
Advertiser - RVP].Rep & "'"), NULL) AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser -
RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser -
RVP].Advertiser;


The above query should show the Goals amount for just one of the records
for
each SalesRep, though it may not be the first record in the query's order
for that SalesRep. If you want that, you can change the query to this:

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
IIf((SELECT Min(T.RVP) AS MinRVP FROM [Bookings and Pipe by Advertiser -
RVP] AS T
WHERE T.Rep = tblRVP_Mapping.[Sales Rep]) = [Bookings and Pipe by
Advertiser - RVP].RVP,
DLookup("Total - Q408", "tblGoals", "Rep='" & [Bookings and Pipe by
Advertiser - RVP].Rep & "'"), NULL) AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser -
RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser -
RVP].Advertiser
ORDER BY [Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP;
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


ryguy7272 said:
Yes, yes, yes! I need some duplicate records in the query, but just
want
the
Goals amount to be displayed for a single record for a Rep. I have a
rep
named Adam and he has 13 Advertisers. I am showing the revenue from
each
Advertiser, which is 13 records, and I want to show Adam's Goal, which
is
one
record. This is one of two select Queries. I then combine the results
in
a
UnionQuery and finally rearrange it in a CrosstabQuery. The UnionQuery
and
CrosstabQuery work great without the Goals in there. Howver, I need
the
Goals in there so I can compare the sum of the revenues from all
Advertisers
with the Goal. This is how I can tell if a rep is 70% to Goal, 90% to
Goal,
100% to Goal, or whatever.20% to Goal. Does that make sense?

I'm trying to learn how to do this in Access. I can do it in Excel
pretty
easy, but I'd like to learn the nuts and bolts of Access and it would
be a
whole lot easier to keep this all in Access, and simply convert the
final
Query to a spreadsheet, after all work is done in Access.

Thanks for the follow through Ken!!


--
RyGuy


:

Or, perhaps I'm completely misunderstanding what you want. Do you want
those
duplicate records in the query, but just want the Goals amount to be
displayed for a single record for a Rep and not for all the records
for
that
Rep?
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Not knowing your data, can you do a selective edit of the query to
see
what is causing the multiple records? By this, I mean delete one
table
and
run the query; if you still get the duplicate records, start with
the
original query again and delete a different table.

Once you can tell us which join is causing the duplication, then we
can
design the SQL statement to eliminate the duplication.

As for the "1" idea, I think that is overcomplicating the setup. We
should
be able to get the results by just restructuring the query.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Thanks a bunch Ken! However, the problem is still the same. With
the
tblGoals out of the Query, the Goal is still repeated multiple
times
for
each
Rep. Maybe Access isn't able to do what I want to do. I can do it
in
Excel,
but I was hoping to just do everything in Access rather than
swapping
data
back and forth between Access and Excel.

Is there some way to count Rep's names, maybe in a helper Field,
incrementing by 1, and then restart with 1 each time a new Rep name
is
encountered? I think I could do a Dlookup based on the 1s and when
a
1
is
encountered pull in that individual's Goal. Would that work? I
know
Excel
can do that.

Thanks!
Ryan---

--
RyGuy


:

Change your query to this:

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4
C1]+[Bookings
and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by
Advertiser],
DLookup("Total - Q408", "tblGoals", "Rep='" & [Rep] & "'") AS
Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser -
RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser -
RVP].Advertiser;


Note that I've removed the tblGoals table from the query. It's not
needed
for any of the fields or calculations, and it was causing the
duplication of
the data that you were seeing.

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


You are absolutely right Ken! The Dlookup is doing what I want!
However,
I
am still plagued with many, many, many duplicates for Goals.
Let
me
explain
once more what I want to do and maybe you, or someone, can tell
me
how
best
to do it.

I have a Sales Rep, a VP, a Region, an Advertiser, and then a
Total
spent
by
that Advertiser. This part of the query is working just fine.
The
problem
occurs when I use Dlookup to pull in the Goals for each Sales
Rep.
I
need
the line by line itemized format for everything but the Goals.
For
instance,
when I look at Adam, I want to see all 13 of his Advertisers and
the
money
that each Advertiser spent. For Alex, I want to see all 35 of
his
Advertisers and the money that each Advertiser spent, and so on
and
so
forth.
I was hoping to come up with a way of pulling in the Goal for
each
Rep
and
then exporting everything to Excel, do a Subtotal by Rep, and
send
this,
via
Email, to a colleague. The thing that I'm stuck on is that I'm
getting a
$3,000,000 Goal for Adam repeated 13 times. I wanted to sum the
dollar
amounts spent by the Advertisers that Adam works with, and
compare
this
sum
to his Goal. This is why I want to display the Goal only once.
Perhaps
there is a better way of doing this?

BTW, the Dlookup function is very cool!! I've never used it
before,
but I'm
sure I'll find opportunities to use it more and more in the very
near
future.


Thanks,
Ryan---


--
RyGuy


:

The issue is not the DLookup. It returns only a single value
for
each
record
in the query. The problem is that your query itself is
returning
the
multiple records. You can confirm this by taking the DLookup
field
out of
the query and running it.

With the DLookup field, can you not take the tblGoals table out
of
the
query? I assume that that is the source of the duplication of
records.
The
DLookup field does what you were wanting from the tblGoals
table
initially.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/




message
Evidently, I am still doing something wrong. I have this in
the
'Field'
of
the QBE Grid:
Goals: DLookUp("[Total - Q408]","tblGoals","Rep = '" &
[Bookings
and
Pipe
by
Advertiser - RVP]![Rep] & "'")

The result is 13 incidences of $3,000,000 for Goals for Adam,
I
surmise
it
 
R

ryguy7272

Ken!! Thanks so much for the effort!! Even with the last SQL-string that
you posted, I still could not get my desired results, and I didn't really
understand your IIF function. I got my final results this way:
Step 1) Created 3 Select Queries

Step 2) Created one Union Query with this SQL:
SELECT [Rep], [RVP], [Region], [Advertiser], [Bookings by Advertiser] as
Revenue, "Bookings" as Bookings from [Mark - Bookings by Advertiser]
UNION ALL SELECT [Sales Rep], [RVP], [Region], [Entity], [Search by
Advertiser], "Search" as Search from [Mark - Search by Advertiser]
UNION ALL SELECT [Sales Rep], [RVP], [Region], [Entity], [Goal], "Goal" as
Goals from [Mark - Goals by Advertiser];

Step 3) Created one Crosstab Query with this SQL:
TRANSFORM Sum([Mark - Union].Revenue) AS SumOfRevenue
SELECT [Mark - Union].Rep, [Mark - Union].RVP, [Mark - Union].Region, [Mark
- Union].Advertiser
FROM [Mark - Union]
GROUP BY [Mark - Union].Rep, [Mark - Union].RVP, [Mark - Union].Region,
[Mark - Union].Advertiser
PIVOT [Mark - Union].Bookings;

That works!!!

I learned quite a lot during the process. I have a better appreciation for
the Dlookup function and for Unions and Crosstabs. Your solution seemed much
more elegant than my own, but I could never get it working. All I got was
blanks, or nulls, in the Goals Field, for the final SQL-string that you
posted for me. I'll work on it a little more, as I'd like to eventually use
your method, but for now, I have to go with my solution because deadlines are
looming.

Thanks again for everything!!!

Regards,
Ryan---

--
RyGuy


ryguy7272 said:
Thanks once again Ken! When I attempt to run both (new) queries, I now get
prompted to enter a parameter. Message Reads: Enter Parameter Value:
tblRVP_Mapping.Sales Rep

When I click ‘OK’ nothing is returned.

I fiddled around with the IIF function for a bout ½ hour and couldn’t figure
it out. I’ve seen the T. method used before, but I am not familiar with it
at all. Perhaps that is the culprit. Also, why would Access need T.RVP?
Wouldn’t it be T.Rep? The Reps are under the RVPs, that’s for sure, but I am
querying for Rep and Advertiser revenue; I’m just pulling in the RVP names to
see the hierarchy of the teams.

I’ll keep playing with it. I hope I can make this work. It has been a
great learning opportunity and if I can get this thing working it will be
very practical and very useful. Any idea what could be causing the parameter
to jump up?

Thanks once again,
Ryan---


--
RyGuy


Ken Snell (MVP) said:
OK, then let's try this query.

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
IIf((SELECT Min(T.RVP) AS MinRVP FROM [Bookings and Pipe by Advertiser -
RVP] AS T
WHERE T.Rep = tblRVP_Mapping.[Sales Rep]) = [Bookings and Pipe by
Advertiser - RVP].RVP,
DLookup("Total - Q408", "tblGoals", "Rep='" & [Bookings and Pipe by
Advertiser - RVP].Rep & "'"), NULL) AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser - RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser - RVP].Advertiser;


The above query should show the Goals amount for just one of the records for
each SalesRep, though it may not be the first record in the query's order
for that SalesRep. If you want that, you can change the query to this:

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
IIf((SELECT Min(T.RVP) AS MinRVP FROM [Bookings and Pipe by Advertiser -
RVP] AS T
WHERE T.Rep = tblRVP_Mapping.[Sales Rep]) = [Bookings and Pipe by
Advertiser - RVP].RVP,
DLookup("Total - Q408", "tblGoals", "Rep='" & [Bookings and Pipe by
Advertiser - RVP].Rep & "'"), NULL) AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser - RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser - RVP].Advertiser
ORDER BY [Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP;
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


ryguy7272 said:
Yes, yes, yes! I need some duplicate records in the query, but just want
the
Goals amount to be displayed for a single record for a Rep. I have a rep
named Adam and he has 13 Advertisers. I am showing the revenue from each
Advertiser, which is 13 records, and I want to show Adam's Goal, which is
one
record. This is one of two select Queries. I then combine the results in
a
UnionQuery and finally rearrange it in a CrosstabQuery. The UnionQuery
and
CrosstabQuery work great without the Goals in there. Howver, I need the
Goals in there so I can compare the sum of the revenues from all
Advertisers
with the Goal. This is how I can tell if a rep is 70% to Goal, 90% to
Goal,
100% to Goal, or whatever.20% to Goal. Does that make sense?

I'm trying to learn how to do this in Access. I can do it in Excel pretty
easy, but I'd like to learn the nuts and bolts of Access and it would be a
whole lot easier to keep this all in Access, and simply convert the final
Query to a spreadsheet, after all work is done in Access.

Thanks for the follow through Ken!!


--
RyGuy


:

Or, perhaps I'm completely misunderstanding what you want. Do you want
those
duplicate records in the query, but just want the Goals amount to be
displayed for a single record for a Rep and not for all the records for
that
Rep?
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Not knowing your data, can you do a selective edit of the query to see
what is causing the multiple records? By this, I mean delete one table
and
run the query; if you still get the duplicate records, start with the
original query again and delete a different table.

Once you can tell us which join is causing the duplication, then we can
design the SQL statement to eliminate the duplication.

As for the "1" idea, I think that is overcomplicating the setup. We
should
be able to get the results by just restructuring the query.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Thanks a bunch Ken! However, the problem is still the same. With the
tblGoals out of the Query, the Goal is still repeated multiple times
for
each
Rep. Maybe Access isn't able to do what I want to do. I can do it in
Excel,
but I was hoping to just do everything in Access rather than swapping
data
back and forth between Access and Excel.

Is there some way to count Rep's names, maybe in a helper Field,
incrementing by 1, and then restart with 1 each time a new Rep name is
encountered? I think I could do a Dlookup based on the 1s and when a
1
is
encountered pull in that individual's Goal. Would that work? I know
Excel
can do that.

Thanks!
Ryan---

--
RyGuy


:

Change your query to this:

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings
and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
DLookup("Total - Q408", "tblGoals", "Rep='" & [Rep] & "'") AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser -
RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser -
RVP].Advertiser;


Note that I've removed the tblGoals table from the query. It's not
needed
for any of the fields or calculations, and it was causing the
duplication of
the data that you were seeing.

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


You are absolutely right Ken! The Dlookup is doing what I want!
However,
I
am still plagued with many, many, many duplicates for Goals. Let
me
explain
once more what I want to do and maybe you, or someone, can tell me
how
best
to do it.

I have a Sales Rep, a VP, a Region, an Advertiser, and then a Total
spent
by
that Advertiser. This part of the query is working just fine. The
problem
occurs when I use Dlookup to pull in the Goals for each Sales Rep.
I
need
the line by line itemized format for everything but the Goals. For
instance,
when I look at Adam, I want to see all 13 of his Advertisers and
the
money
that each Advertiser spent. For Alex, I want to see all 35 of his
Advertisers and the money that each Advertiser spent, and so on and
so
forth.
I was hoping to come up with a way of pulling in the Goal for each
Rep
and
then exporting everything to Excel, do a Subtotal by Rep, and send
this,
via
Email, to a colleague. The thing that I'm stuck on is that I'm
getting a
$3,000,000 Goal for Adam repeated 13 times. I wanted to sum the
dollar
amounts spent by the Advertisers that Adam works with, and compare
this
sum
to his Goal. This is why I want to display the Goal only once.
Perhaps
there is a better way of doing this?

BTW, the Dlookup function is very cool!! I've never used it
before,
but I'm
sure I'll find opportunities to use it more and more in the very
near
future.


Thanks,
Ryan---


--
RyGuy


:

The issue is not the DLookup. It returns only a single value for
each
record
in the query. The problem is that your query itself is returning
the
multiple records. You can confirm this by taking the DLookup field
out of
the query and running it.

With the DLookup field, can you not take the tblGoals table out of
the
 
K

Ken Snell \(MVP\)

Glad you found a workaround. My suggested query may not be exactly right if
I'm not using the correct data fields in it. I don't have a clear mental
picture of the data and table structure, so you may be able to use my
suggestion if you can replace my "wrong" fields with the "right" fields.
Good luck.

The IIf function that I had in the suggested query was intended to do this:
a) Find the "minimum" value of the RVP field for a given Sales Rep, and use
this to identify one record of the data that should get the Goals amount.
b) If the record in the query was the "minimum RVP" value, show the Goals
amount in it.
c) If the record was any other "RVP" value, show a NULL value for the Goals
amount.

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/



ryguy7272 said:
Ken!! Thanks so much for the effort!! Even with the last SQL-string that
you posted, I still could not get my desired results, and I didn't really
understand your IIF function. I got my final results this way:
Step 1) Created 3 Select Queries

Step 2) Created one Union Query with this SQL:
SELECT [Rep], [RVP], [Region], [Advertiser], [Bookings by Advertiser] as
Revenue, "Bookings" as Bookings from [Mark - Bookings by Advertiser]
UNION ALL SELECT [Sales Rep], [RVP], [Region], [Entity], [Search by
Advertiser], "Search" as Search from [Mark - Search by Advertiser]
UNION ALL SELECT [Sales Rep], [RVP], [Region], [Entity], [Goal], "Goal" as
Goals from [Mark - Goals by Advertiser];

Step 3) Created one Crosstab Query with this SQL:
TRANSFORM Sum([Mark - Union].Revenue) AS SumOfRevenue
SELECT [Mark - Union].Rep, [Mark - Union].RVP, [Mark - Union].Region,
[Mark
- Union].Advertiser
FROM [Mark - Union]
GROUP BY [Mark - Union].Rep, [Mark - Union].RVP, [Mark - Union].Region,
[Mark - Union].Advertiser
PIVOT [Mark - Union].Bookings;

That works!!!

I learned quite a lot during the process. I have a better appreciation
for
the Dlookup function and for Unions and Crosstabs. Your solution seemed
much
more elegant than my own, but I could never get it working. All I got was
blanks, or nulls, in the Goals Field, for the final SQL-string that you
posted for me. I'll work on it a little more, as I'd like to eventually
use
your method, but for now, I have to go with my solution because deadlines
are
looming.

Thanks again for everything!!!

Regards,
Ryan---

--
RyGuy


ryguy7272 said:
Thanks once again Ken! When I attempt to run both (new) queries, I now
get
prompted to enter a parameter. Message Reads: Enter Parameter Value:
tblRVP_Mapping.Sales Rep

When I click 'OK' nothing is returned.

I fiddled around with the IIF function for a bout ½ hour and couldn't
figure
it out. I've seen the T. method used before, but I am not familiar with
it
at all. Perhaps that is the culprit. Also, why would Access need T.RVP?
Wouldn't it be T.Rep? The Reps are under the RVPs, that's for sure, but
I am
querying for Rep and Advertiser revenue; I'm just pulling in the RVP
names to
see the hierarchy of the teams.

I'll keep playing with it. I hope I can make this work. It has been a
great learning opportunity and if I can get this thing working it will be
very practical and very useful. Any idea what could be causing the
parameter
to jump up?

Thanks once again,
Ryan---


--
RyGuy


Ken Snell (MVP) said:
OK, then let's try this query.

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings
and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
IIf((SELECT Min(T.RVP) AS MinRVP FROM [Bookings and Pipe by
Advertiser -
RVP] AS T
WHERE T.Rep = tblRVP_Mapping.[Sales Rep]) = [Bookings and Pipe by
Advertiser - RVP].RVP,
DLookup("Total - Q408", "tblGoals", "Rep='" & [Bookings and Pipe by
Advertiser - RVP].Rep & "'"), NULL) AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser -
RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser -
RVP].Advertiser;


The above query should show the Goals amount for just one of the
records for
each SalesRep, though it may not be the first record in the query's
order
for that SalesRep. If you want that, you can change the query to this:

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4 C1]+[Bookings
and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by Advertiser],
IIf((SELECT Min(T.RVP) AS MinRVP FROM [Bookings and Pipe by
Advertiser -
RVP] AS T
WHERE T.Rep = tblRVP_Mapping.[Sales Rep]) = [Bookings and Pipe by
Advertiser - RVP].RVP,
DLookup("Total - Q408", "tblGoals", "Rep='" & [Bookings and Pipe by
Advertiser - RVP].Rep & "'"), NULL) AS Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by Advertiser -
RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser -
RVP].Advertiser
ORDER BY [Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP;
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Yes, yes, yes! I need some duplicate records in the query, but just
want
the
Goals amount to be displayed for a single record for a Rep. I have a
rep
named Adam and he has 13 Advertisers. I am showing the revenue from
each
Advertiser, which is 13 records, and I want to show Adam's Goal,
which is
one
record. This is one of two select Queries. I then combine the
results in
a
UnionQuery and finally rearrange it in a CrosstabQuery. The
UnionQuery
and
CrosstabQuery work great without the Goals in there. Howver, I need
the
Goals in there so I can compare the sum of the revenues from all
Advertisers
with the Goal. This is how I can tell if a rep is 70% to Goal, 90%
to
Goal,
100% to Goal, or whatever.20% to Goal. Does that make sense?

I'm trying to learn how to do this in Access. I can do it in Excel
pretty
easy, but I'd like to learn the nuts and bolts of Access and it would
be a
whole lot easier to keep this all in Access, and simply convert the
final
Query to a spreadsheet, after all work is done in Access.

Thanks for the follow through Ken!!


--
RyGuy


:

Or, perhaps I'm completely misunderstanding what you want. Do you
want
those
duplicate records in the query, but just want the Goals amount to be
displayed for a single record for a Rep and not for all the records
for
that
Rep?
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


message
Not knowing your data, can you do a selective edit of the query to
see
what is causing the multiple records? By this, I mean delete one
table
and
run the query; if you still get the duplicate records, start with
the
original query again and delete a different table.

Once you can tell us which join is causing the duplication, then
we can
design the SQL statement to eliminate the duplication.

As for the "1" idea, I think that is overcomplicating the setup.
We
should
be able to get the results by just restructuring the query.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


Thanks a bunch Ken! However, the problem is still the same.
With the
tblGoals out of the Query, the Goal is still repeated multiple
times
for
each
Rep. Maybe Access isn't able to do what I want to do. I can do
it in
Excel,
but I was hoping to just do everything in Access rather than
swapping
data
back and forth between Access and Excel.

Is there some way to count Rep's names, maybe in a helper Field,
incrementing by 1, and then restart with 1 each time a new Rep
name is
encountered? I think I could do a Dlookup based on the 1s and
when a
1
is
encountered pull in that individual's Goal. Would that work? I
know
Excel
can do that.

Thanks!
Ryan---

--
RyGuy


:

Change your query to this:

SELECT
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region,
[Bookings and Pipe by Advertiser - RVP].Advertiser,
Sum([Bookings and Pipe by Advertiser - RVP]![Sum 08Q4
C1]+[Bookings
and
Pipe by Advertiser - RVP]![Sum 08Q4 C2]) AS [Bookings by
Advertiser],
DLookup("Total - Q408", "tblGoals", "Rep='" & [Rep] & "'") AS
Goal
FROM
(tblRep_Summary INNER JOIN (tblRVP_Mapping INNER JOIN
[Bookings and Pipe by Advertiser - RVP] ON
tblRVP_Mapping.[Sales Rep] = [Bookings and Pipe by
Advertiser -
RVP].Rep)
ON tblRep_Summary.AE = tblRVP_Mapping.[Backyard ID])
GROUP BY
[Bookings and Pipe by Advertiser - RVP].Rep,
[Bookings and Pipe by Advertiser - RVP].RVP,
tblRep_Summary.Region, [Bookings and Pipe by Advertiser -
RVP].Advertiser;


Note that I've removed the tblGoals table from the query. It's
not
needed
for any of the fields or calculations, and it was causing the
duplication of
the data that you were seeing.

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


message
You are absolutely right Ken! The Dlookup is doing what I
want!
However,
I
am still plagued with many, many, many duplicates for Goals.
Let
me
explain
once more what I want to do and maybe you, or someone, can
tell me
how
best
to do it.
I have a Sales Rep, a VP, a Region, an Advertiser, and then a
Total
spent
by
that Advertiser. This part of the query is working just fine.
The
problem
occurs when I use Dlookup to pull in the Goals for each Sales
Rep.
I
need
the line by line itemized format for everything but the Goals.
For
instance,
when I look at Adam, I want to see all 13 of his Advertisers
and
the
money
that each Advertiser spent. For Alex, I want to see all 35 of
his
Advertisers and the money that each Advertiser spent, and so
on and
so
forth.
I was hoping to come up with a way of pulling in the Goal for
each
Rep
and
then exporting everything to Excel, do a Subtotal by Rep, and
send
this,
via
Email, to a colleague. The thing that I'm stuck on is that
I'm
getting a
$3,000,000 Goal for Adam repeated 13 times. I wanted to sum
the
dollar
amounts spent by the Advertisers that Adam works with, and
compare
this
sum
to his Goal. This is why I want to display the Goal only
once.
Perhaps
there is a better way of doing this?

BTW, the Dlookup function is very cool!! I've never used it
before,
but I'm
sure I'll find opportunities to use it more and more in the
very
near
future.


Thanks,
Ryan---


--
RyGuy


:

The issue is not the DLookup. It returns only a single value
for
each
record
in the query. The problem is that your query itself is
returning
the
multiple records. You can confirm this by taking the DLookup
field
out of
the query and running it.

With the DLookup field, can you not take the tblGoals table
out of
the
 

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