Also see: Total Queries: Showing Those With 0 Count Other Total Queries
This example calculates how many contacts are converted into sales--which are sold by the sales representative. There are apartments and subdivisions contacted as potential customers and entered into a database; when any of them are converted into sales, a field called "video_sold_by" has the value entered "Sales Representative" or "Customer Service." Otherwise, the value (as manipulated later in the query) is "no sale." What needs to happen is, within a certain subdivision, all such attempts need to be totaled, and all which are designated with the "sales representative" need to be totaled, which then enables you to calculate a percentage.
Here is some sample data from the table:
tblMainTEP Drop Date | subdivision_id | Rep ID | Video Sold By | Digital Sold By | Internet Sold By |
15-Dec-02 | 3 | 10 | |||
11-Oct-02 | 1 | 2 | Customer Service | ||
25-Mar-02 | 2 | 5 | Customer Service | ||
5-Jun-02 | 2 | 5 | Customer Service | Customer Service | Sales Representative |
12-Mar-02 | 3 | 5 | |||
19-Feb-02 | 3 | 5 | Customer Service | ||
2-Apr-02 | 3 | 5 | Customer Service | ||
10-May-02 | 3 | 5 | Sales Representative | ||
28-May-04 | 2 | Customer Service | |||
17-Jul-02 | 4 | 2 | Customer Service | ||
5-Mar-02 | 4 | 2 | Sales Representative | ||
9-Sep-02 | 4 | 2 | |||
25-Jun-02 | 4 | 2 | |||
9-Jul-02 | 4 | 2 | Customer Service | ||
6-Mar-02 | 5 | 1 | Customer Service | ||
29-Aug-02 | 5 | 1 | |||
14-May-02 | 5 | 1 | Customer Service | ||
6-Mar-02 | 5 | 1 | Customer Service | Customer Service | |
30-Sep-02 | 5 | 1 | Customer Service | ||
24-Jul-02 | 5 | 1 | |||
22-Mar-02 | 5 | 1 | Customer Service | ||
6-Mar-02 | 5 | 1 |
Yes, the Rep ID field links up to the sales representative's name in another table tblRepresentatives (representative_name) and the subdivision_id links up to the subdivision's name in another table tblSubdivisions (subdivision_name).
In this example, the subdivision "Butterfield Ranch" has total sales ATTEMPTS of 84, and 8 of them were converted to sales by the sales representatives.
This required two queries. The first one, named qrySalesRepSalesPercentages, looked like this:
You have to add up all the entries, and you also have to add up only those with the value "sales representative" in the "video_sold_by" field (and also, with that value in the "high_speed_internet_sold_by" fields and "digital_sold_by" fields). The fields that do this are TotSales and VidCnt, especially (for handling the video sales portion).
Here is the syntax of the TotSales field which adds up all the entries:
TotSales: Count(IIf(IsNull([video_sold_by]),"nosale",[video_sold_by]))This configures those with no entry in "video_sold_by" (which weren't sold by anyone) with the value "nosale" in there, and counts it as well. (I'm not sure if I need to do that; I inherited from earlier configurations of queries I was working on towards this end. (I am wondering if I could reconfigure this to read TotSales: Count(([video_sold_by])) and it would still work.)
Here is the syntax of the expression that adds up ONLY those with the value "sales representative" in the "video_sold_by" field:
VidCnt: Sum(IIf([video_sold_by]="Sales Representative",1,0))The query returns results like this (only Butterfield Ranch shown, though this query returns all records by a certain representative:
TEP Drop Date | Rep ID | Video Sold By | Rep Name | sub Name | TotSales | VidCnt |
2 | Sales Representative | Mark Dirtadian | Butterfield Ranch | 1 | 1 | |
04-Mar-02 | 2 | Mark Dirtadian | Butterfield Ranch | 1 | 0 | |
13-Mar-02 | 2 | Sales Representative | Mark Dirtadian | Butterfield Ranch | 1 | 1 |
18-Mar-02 | 2 | Customer Service | Mark Dirtadian | Butterfield Ranch | 3 | 0 |
18-Mar-02 | 2 | Sales Representative | Mark Dirtadian | Butterfield Ranch | 1 | 1 |
20-Mar-02 | 2 | Customer Service | Mark Dirtadian | Butterfield Ranch | 1 | 0 |
25-Mar-02 | 2 | Customer Service | Mark Dirtadian | Butterfield Ranch | 2 | 0 | 25-Mar-02 | 2 | Sales Representative | Mark Dirtadian | Butterfield Ranch | 1 | 1 |
27-Mar-02 | 2 | Mark Dirtadian | Butterfield Ranch | 2 | 0 |
Again, all subdivisions are shown; this was only shortened for brievity.
For adding up sales rep. sales for "digital" and "high speed internet," you can actually place expressions for those in the same query near the end--following the same logic followed for VidCnt. Here are those expressions:
The crosstab query totals everything--within each month, all values on VidCnt (for video) are added up (total sales rep sales), and all values from TotSales are added up within each month, and then they are divided to obtain the sales percentage.
Here is a screenshot of the crosstab query:
Created using Microsoft WORDPAD.