Help with a formuola to show me which hourly rate an employee was on when he made a sale?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

Ok really need some help here as i'm totaly stuck
Hopefully I can explain this Ok

Every week I get a list of all the sales since day one, (we have a very old crm and this is how the data comes in,
now all i have to do is put the hourly rate for each employee down column N,
but heres the problem i have some time empolyees get promoted and have more than one rate

So this i my situation,

In the raw data sheet (where i need the formula,
Coloumn A has the date sold
Column C has the employees Number,

Now in sheet "Employees Data" Column AC has the Employees Number,
Column AO Has the start date
Column AP has the end date

Now because nobody is perfect it is possible the end date is before the date sold, in which case the most recent rate applies.

So all I need is for a formula to look at the date sold and the Employees Number, go to sheet "Employees Data" find the employees name that has a date to do with the start date and return the hourly rate in column BE

If you need more info please feel free to ask as im struggling to explain this,
but basically,
find the employee, see how many rows he has, if its just one then the rate is correct, if its more than one find the one with a start date (and end date?) before and after the sale date?

please help been trying to do this all day?

Thanks

Tony
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi Tony,

Having to allow for no end date and sales after end date added complexity but I believe this does what you ask.

Here's my test Employee Data:

Tonywatsonhelp.xlsx
ACANAOAPAQBDBE
1Employee NumberStart DateEnd Date Hourly Rate
2EMP0021/1/20092/2/2017$ 12
3EMP0046/6/20166/6/2020$ 13
4EMP0071/1/20161/1/2020$ 22
5EMP0022/3/20173/3/2018$ 14
6EMP0046/7/20201/1/2021$ 15
7EMP0071/1/20206/6/2020$ 25
8EMP0023/4/2018$ 16
Employees Data
Cell Formulas
RangeFormula
AO8,AO5:AO6AO5=AP2+1
AO7AO7=AP4


Here's my test List of Sales

Tonywatsonhelp.xlsx
ABCN
1Date SoldEmployee NumberRate
201-Jan-16EMP0021
327-Jun-16EMP0042
406-Sep-16EMP0073
516-Feb-17EMP0024
619-May-17EMP0042
708-Nov-17EMP0073
825-Mar-18EMP0027
920-Jul-18EMP0042
1024-Nov-18EMP999No such employee
1125-Feb-19EMP0027
1210-May-19EMP0042
1326-Jul-19EMP0073
1408-Oct-19EMP0027
1507-Jul-20EMP0045
1607-Jul-20EMP0076
ListOfSales
Cell Formulas
RangeFormula
N2:N16N2=IFERROR(IFERROR(AGGREGATE(14,6,ROW($A$2:$A$9999)-ROW($A$1)/(('Employees Data'!$AC$2:$AC$9999=C2)*('Employees Data'!$AO$2:$AO$9999<=A2)*('Employees Data'!$AP$2:$AP$9999>=A2)),1),IFERROR(AGGREGATE(14,6,ROW($A$2:$A$9999)-ROW($A$1)/(('Employees Data'!$AC$2:$AC$9999=C2)*('Employees Data'!$AO$2:$AO$9999<=A2)*('Employees Data'!$AP$2:$AP$9999="")),1),AGGREGATE(14,6,ROW($A$2:$A$9999)-ROW($A$1)/(('Employees Data'!$AC$2:$AC$9999=C2)*('Employees Data'!$AO$2:$AO$9999<=A2)),1))),"No such employee")
 
Upvote 0
brilliant, I cant get it not to work, so thank you very much toadstool
 
Upvote 0
brilliant, I cant get it not to work, so thank you very much toadstool
You're welcome!

Basically it's three AGGREGATE functions wrapped by IFERROR functions.

The first AGGREGATE looks for the highest row number (so promotion/raise dates must be ascending) for that Employee where the start date is less than or equal to the Sale Date and the End Date is higher or equal to the Sale Date.

If that fails it falls into the IFERROR which is an AGGREGATE which looks for the highest row number for that Employee where the start date is less than or equal to the Sale Date and the End Date is null (still employed?).

If that fails then it must be the case where the paperwork dates don't match so it just looks for the highest row number for that Employee where the Start Date is less than or equal to the Sales Date.

If all fail then there must be "No such employee" so it gives that message.

Sorry but I was testing using the row numbers returned by the AGGREGATEs and forgot to put in the INDEX which actually retrieves the Hourly Rate, so here it is:

Tonywatsonhelp.xlsx
ABCN
1Date SoldEmployee NumberRate
201-Jan-16EMP002$ 12
327-Jun-16EMP004$ 13
406-Sep-16EMP007$ 22
516-Feb-17EMP002$ 14
619-May-17EMP004$ 13
708-Nov-17EMP007$ 22
825-Mar-18EMP002$ 16
920-Jul-18EMP004$ 13
1024-Nov-18EMP999 No such employee
1125-Feb-19EMP002$ 16
1210-May-19EMP004$ 13
1326-Jul-19EMP007$ 22
1408-Oct-19EMP002$ 16
1507-Jul-20EMP004$ 15
1607-Jul-20EMP007$ 25
ListOfSales
Cell Formulas
RangeFormula
N2:N16N2=IFERROR(INDEX('Employees Data'!$BE$2:$BE$9999,IFERROR(AGGREGATE(14,6,ROW($A$2:$A$9999)-ROW($A$1)/(('Employees Data'!$AC$2:$AC$9999=C2)*('Employees Data'!$AO$2:$AO$9999<=A2)*('Employees Data'!$AP$2:$AP$9999>=A2)),1),IFERROR(AGGREGATE(14,6,ROW($A$2:$A$9999)-ROW($A$1)/(('Employees Data'!$AC$2:$AC$9999=C2)*('Employees Data'!$AO$2:$AO$9999<=A2)*('Employees Data'!$AP$2:$AP$9999="")),1),AGGREGATE(14,6,ROW($A$2:$A$9999)-ROW($A$1)/(('Employees Data'!$AC$2:$AC$9999=C2)*('Employees Data'!$AO$2:$AO$9999<=A2)),1)))),"No such employee")
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top