I have a report that I need to show only the employees that meet a certain set of criteria. There are 3 tables used for this report. The first table is the Employee table that gives the specifics of the employee. The second table is the Sales Data (tblSales) that has the employee ID, Sales date, and Sales Type. The 3rd table has the sales requirement data. The criteria is a bit odd and I will try to make it clear (hopefully). The report shows the employees that have met or exceeded the "qualified" sales in the last 12 months. The tricky part is what constitutes a qualified sale. There are 2 types of sales, "S" and "SF". All of sales type "S" are qualifying. The first 6 "SF" type of sale per calendar year are not qualifying. That is where it gets tricky. So I need a query that will give me a list of the employees that have met or exceeded the sales target.
So the basic formula would be something like this:
SFFirst would be the total # of SF sales from Jan 1 of the previous year to the previous month as the current month but for the previous year. So for example taking today, June 25, 2015 SFFirst would be the # of SFSales from 1/1/14 to 5/31/14.
SFSecond would be the total # of SF sales from the current month but for the previous year to Dec 31 of the previous year. So in the above example it would be June 1, 2014 to Dec 31, 2014.
SFCurrent is the total # of SF sales form Jan 1 of the current year to the last day of the previous month.
STotal is the total number of S sales in the previous month.
SFTotal is the # of qualified SF sales for the previous 12 months.
So the formula would be something like this:
If SFFirst >=6 then SFTotal=SFSecond
Else If SFSecond+SFFirst-6<0 then SFTotal=0
Else SFTotal=SFSecond+SFFirst-6
I can get a query for each part but I can't figure out how to combine them.
The query for the SFFirst is:
SELECT EMP_ID, IIf(Sum(IIf(SalesType="SF",1,0))>5,6,Sum(IIf(SalesType="SF",1,0))) AS SFFirst
FROM tblSalesData
WHERE (SalesDate BETWEEN DateSerial(Year(Now())-1,1,1) AND DateSerial(Year(Now())-1,Month(Now()),0)) AND (SickType = 'SF')
GROUP BY EMP_ID;
I hope this makes sense. Thanks for looking at this.
So the basic formula would be something like this:
SFFirst would be the total # of SF sales from Jan 1 of the previous year to the previous month as the current month but for the previous year. So for example taking today, June 25, 2015 SFFirst would be the # of SFSales from 1/1/14 to 5/31/14.
SFSecond would be the total # of SF sales from the current month but for the previous year to Dec 31 of the previous year. So in the above example it would be June 1, 2014 to Dec 31, 2014.
SFCurrent is the total # of SF sales form Jan 1 of the current year to the last day of the previous month.
STotal is the total number of S sales in the previous month.
SFTotal is the # of qualified SF sales for the previous 12 months.
So the formula would be something like this:
If SFFirst >=6 then SFTotal=SFSecond
Else If SFSecond+SFFirst-6<0 then SFTotal=0
Else SFTotal=SFSecond+SFFirst-6
I can get a query for each part but I can't figure out how to combine them.
The query for the SFFirst is:
SELECT EMP_ID, IIf(Sum(IIf(SalesType="SF",1,0))>5,6,Sum(IIf(SalesType="SF",1,0))) AS SFFirst
FROM tblSalesData
WHERE (SalesDate BETWEEN DateSerial(Year(Now())-1,1,1) AND DateSerial(Year(Now())-1,Month(Now()),0)) AND (SickType = 'SF')
GROUP BY EMP_ID;
I hope this makes sense. Thanks for looking at this.
Last edited: