Formula help , countifs, conditional formatting

mariearcus

New Member
Joined
Dec 8, 2015
Messages
13
This is a long shot but I'm hoping someone can help and that the calculation I'm trying to make can run in excel.

In brief, I work in HR and we need to create a new way to calculate holiday pay using extracted data (into excel) from our payroll system.

Holiday pay for 200 of our employees needs to be worked out by adding up the last 12 weeks or normal pay and dividing by 12. The issue is there are exceptions such as when the employee takes a day holiday, sick or attends college then we have to exclude that week and go back to week 13 et c....

So far I've just added conditional formatting to highlight which weeks should be included in the average 12 weeks calculation. My issue is how to create a formula to add up JUST the 12 weeks which should be included?

The spreadsheet is setup like this...

Column A - employee name
B - basic pay £
C - price work £
D - holiday pay £
E - sick pay £
F - college pay£
G - include/exclude

The spreadsheet includes pay data going back 20 weeks, but could be more or less depending on how we extract the data.

Each week I will need to download the data from our weekly payroll system and add to the spreadsheet so whatever formula I use needs to work like this.
 
But H17 says exclude?

Apologies! You are quite correct.

It should be (to work out holiday pay for week 35 holiday). Adding up the cells H4-H6, H8-H15 and H18... total of £6,506.12, divided by 12 is £542.17.

Perhaps do we have to add in the formula some element of including column B for the period and working back 12 weeks from that? Is that possible?
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi mariearcus,

I believe I am following your request. You have already determined the weeks that can be included based on sick/holiday time. Then next step would be to determine the 12 most recent weeks by employee. This is complicated as you have stated that you have more than 12 includable options. There are always a couple different ways to do things in Excel, but I sorted your data by the week/year column descending (so the most recent week/year will be at the top of your dataset). Once sorted, I used the following formula to find the includable week number for each employee (most recent week would be 1, next is 2, and so on), while excluding the records that were not listed as 'include'.

I put employee name in Column A and Include/Exclude information in Column O.
Formula in P2: =IF(O2<>"include","",COUNTIFS($A$2:A2,A2,$O$2:O2,O2))

We now have enough information to solve your analysis. From here, you can use a formula, or you could summarize with a pivot table. Regardless of method you are now able to filter/criteria on only WeekNumber's between 1 and 12 - excluding blanks and any numbers above 12.

If you are not comfortable with doing a pivot table, a formula won't be easier. In that case you could filter on week number between 1 and 12 and copy that data to a new tab. That way you would have only the data you want, and you could SUMIF() on just the employee name.

NH


Example:
[TABLE="width: 463"]
<tbody>[TR]
[TD]Employee_Name
[/TD]
[TD]Week/Year
[/TD]
[TD]IncludeStatus
[/TD]
[TD]WeekNumber
[/TD]
[/TR]
[TR]
[TD]WnameA
[/TD]
[TD]35 2015
[/TD]
[TD]include
[/TD]
[TD]1
[/TD]
[/TR]
[TR]
[TD]WnameB
[/TD]
[TD]35 2015
[/TD]
[TD]include
[/TD]
[TD]1
[/TD]
[/TR]
[TR]
[TD]WnameC
[/TD]
[TD]35 2015
[/TD]
[TD]include
[/TD]
[TD]1
[/TD]
[/TR]
[TR]
[TD]WnameD
[/TD]
[TD]35 2015
[/TD]
[TD]include
[/TD]
[TD]1
[/TD]
[/TR]
[TR]
[TD]WnameA
[/TD]
[TD]34 2015
[/TD]
[TD]include
[/TD]
[TD]2
[/TD]
[/TR]
[TR]
[TD]WnameB
[/TD]
[TD]34 2015
[/TD]
[TD]include
[/TD]
[TD]2
[/TD]
[/TR]
[TR]
[TD]WnameC
[/TD]
[TD]34 2015
[/TD]
[TD]include
[/TD]
[TD]2
[/TD]
[/TR]
[TR]
[TD]WnameD
[/TD]
[TD]34 2015
[/TD]
[TD]include
[/TD]
[TD]2
[/TD]
[/TR]
[TR]
[TD]WnameA
[/TD]
[TD]33 2015
[/TD]
[TD]include
[/TD]
[TD]3
[/TD]
[/TR]
[TR]
[TD]WnameB
[/TD]
[TD]33 2015
[/TD]
[TD]exclude
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]WnameC
[/TD]
[TD]33 2015
[/TD]
[TD]include
[/TD]
[TD]3
[/TD]
[/TR]
[TR]
[TD]WnameD
[/TD]
[TD]33 2015
[/TD]
[TD]include
[/TD]
[TD]3
[/TD]
[/TR]
[TR]
[TD]WnameA
[/TD]
[TD]32 2015
[/TD]
[TD]include
[/TD]
[TD]4
[/TD]
[/TR]
[TR]
[TD]WnameB
[/TD]
[TD]32 2015
[/TD]
[TD]exclude
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]WnameC
[/TD]
[TD]32 2015
[/TD]
[TD]include
[/TD]
[TD]4
[/TD]
[/TR]
[TR]
[TD]WnameD
[/TD]
[TD]32 2015
[/TD]
[TD]include
[/TD]
[TD]4
[/TD]
[/TR]
[TR]
[TD]WnameA
[/TD]
[TD]31 2015
[/TD]
[TD]include
[/TD]
[TD]5
[/TD]
[/TR]
[TR]
[TD]WnameB
[/TD]
[TD]31 2015
[/TD]
[TD]include
[/TD]
[TD]3
[/TD]
[/TR]
[TR]
[TD]WnameC
[/TD]
[TD]31 2015
[/TD]
[TD]include
[/TD]
[TD]5
[/TD]
[/TR]
[TR]
[TD]WnameD
[/TD]
[TD]31 2015
[/TD]
[TD]include
[/TD]
[TD]5
[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Hi mariearcus,

the file with the solution is here -> https://drive.google.com/file/d/0B1t6R5UwL0-2d1NqRGNhMm0zTFE/view?usp=sharing

this works as you describe below.

let me know if you have any additional questions.


Angel

Apologies! You are quite correct.

It should be (to work out holiday pay for week 35 holiday). Adding up the cells H4-H6, H8-H15 and H18... total of £6,506.12, divided by 12 is £542.17.

Perhaps do we have to add in the formula some element of including column B for the period and working back 12 weeks from that? Is that possible?
 
Upvote 0
Angel - that's amazing! Thank you so much, I can't believe that was so quick, just goes to show how much I need to learn!

I'm intrigued to find out what the formulas mean - in as basic language as you can explain! The column you added for 'count' in column P is really useful.

Will I be ok to copy and paste these formulas in as I add the data each week or will it cause any issues?

Many thanks again
:)
 
Upvote 0
Angel - just looking at the result in cell Q53 and not sure it's right. It should be adding up the cells H42-H53 which is £3825... then dividing by 12 should be £318.75 but it says £506.92?
 
Upvote 0
You are right! I made an awful mistake, it was counting all the way to the top, but we need to restart with every employee change... sorry about that.

I've fixed it, it's using an indirect referencing (the formulas will look a little awkward but they work), and I had to add yet a new column.

I'll reply later today with the explanation of what the formulas are doing (I'm in the middle of something right now).

here's the updated file -> https://drive.google.com/open?id=0B1t6R5UwL0-2d1NqRGNhMm0zTFE

Let me know if everything is square now.

thanks,

Angel

Angel - just looking at the result in cell Q53 and not sure it's right. It should be adding up the cells H42-H53 which is £3825... then dividing by 12 should be £318.75 but it says £506.92?
 
Upvote 0
Hi mariearcus,

Ok, here's the explanation, there are several thinks happening here:

1) Let's start with formula on P3 =COUNTIFS($A$3:A3,A3,$O$3:O3,"include")

This is counting on a range from $A$3 (the beginning of the list) to the current cell (A3 in the first line but will increase as the formula is copied) and is increasing every time two things happen 1) the name is the same (that's the ,A3, this changes once you copy the formula down) 2) counts the "include" weeks beginning from the top of the list $O$3 to the current cell (initially O3 but increases as the formula is copied). So this creates a count of the included weeks; this identifies when we need to start calculating the 12 week holiday pay.

2) Formula on Q3 =IF(A3<>A2,ROW(H3),Q2)

This is only checking when the name of the employee has changed, so when ever the name changes it will return the row number of when it changed, this is needed for the calculation in the "R" column.

3) The last formula I will reference row 18, as it's where it begins to do something, formula on R18 =IF(P18<12,"",AVERAGEIFS(INDIRECT("H"&Q18&":"&CELL("address",H18),TRUE),INDIRECT("O"&Q18&":"&CELL("address",O18),TRUE),"include",INDIRECT("P"&Q18&":"&CELL("address",P18),TRUE),">"&P18-12))

This one reads like a tongue twister, but it's not as complex as it looks, the first part is the simple IF(P18<12, this is only checking if we have enough weeks to calculate, if we don't it simply returns empty "".

The second part uses a method called INDIRECTreference, Excel translates the formula into a Range reference, the translation on cell R18 would read: AVERAGEIF(H3:H18,O3:O18,"include",P3:P18,">"&P18-12), please note that the 3 in the formula comes from the Q column, that's the reason that we need it.
Anyway, what this is doing is establishing that we are going to average the salaries on H3:H18 with the following rules 1) only average the values in column H where range O3:018 reads "include"; 2) only average the values in column H where the week value in range P3:P18 is > 0 (that's the P18-12, this will change on R19 and will read P19-12 which translate to > 1, hence averaging salaries from week 2 through 12 to maintain the 12 week average).

To finalize the explanation, column Q changes when employee name changes, so the evaluation range (referenced by the INDIRECT formula) will shift dynamically for each employee to only average their own week range.
ALmOC0o.png



Hope above is clear and I didn't confuse you more.

Cheers,
Angel
 
Upvote 0
Hi mariearcus,

Please disregard my previous post; I thought about it a second time and found a cleaner solution.

I got rid of the tongue twisting formula and the extra column, here's the formula for column Q =IF(P18<12,"",AVERAGEIFS($H$3:H18,$O$3:O18,"include",$P$3:P18,">"&P18-12,$A$3:A18,A18))

So, the simpler explanation is =IF(P18<12,"",AVERAGEIFS($H$3:H18,$O$3:O18,"include",$P$3:P18,">"&P18-12,$A$3:A18,A18))

The first part, if we don't have 12 weeks, do nothing and return empty "". Second part, average from top of table $H$3 to current row H18, following condition 1: range $O$3 to current row must read "include"; condition 2: range $P$3 to current row is > P18-12 (P18=12 so 12-12=0 so > 0, for next row P19=13 this changes to > 1, so we keep averaging only 12 weeks at a time); condition 3: for range $A$3 to current range only use the name were the current row is at (this is the part that excludes other employees and will average only the current employee named in the current row).


Vhg9Vrb.png


You can find the solution file here https://drive.google.com/file/d/0B1t6R5UwL0-2d1NqRGNhMm0zTFE/view?usp=sharing

Cheers,

Angel
 
Upvote 0
mariearcus

You may well want to keep those helper columns, but in case you are interested, I believe that you can do your calculations without them as follows.

The formula in O3 is an array formula so should be entered without the {} but confirmed with Ctrl+Shift+Enter, not just Enter. If confirmed correctly, Excel will insert the {}. The formula can then be copied down.

Excel Workbook
AHNO
2EmployeeTotal 'Normal' Pay to be includedTotal - these weeks to be excludedHoliday Pay (weekly rate) 12 week average of 'Normal' pay
3WnameB402.92109.23 
4WnameB553.580
5WnameB541.140
6WnameB553.580
7WnameB435.4114.24
8WnameB541.140
9WnameB528.70
10WnameB553.580
11WnameB528.70
12WnameB541.140
13WnameB566.020
14WnameB528.70
15WnameB528.70
16WnameB0571.2
17WnameB422.96114.24
18WnameB541.140542.18
19WnameB547.360541.66
20WnameA0512.13
21WnameA0512.13
22WnameA0512.13
23WnameA51.21427.39
24WnameA0181.69
25WnameA8500
26WnameA8000
27WnameA8170
28WnameA900110.93
29WnameA7310
30WnameA6000
31WnameA348221.85
32WnameA6070
33WnameA6890
34WnameA8390
35WnameA851.50
36WnameA7500
37WnameC276.250
38WnameC318.750
39WnameC63.75289
40WnameC2550
41WnameC25572.25
42WnameC318.750
43WnameC318.750
44WnameC318.750
45WnameC318.750
46WnameC318.750
47WnameC318.750
48WnameC318.750
49WnameC318.750
50WnameC318.750309.90
51WnameC318.750313.44
52WnameC318.750313.44
53WnameC318.750318.75
54WnameD410.50
55WnameD450.190
56WnameD322.140
57WnameD312.990
58WnameD114.77191.25
59WnameD64.763.75
60WnameD0139.58
61WnameD227.140
62WnameD514.840
63WnameD413.6465.45
64WnameD355.8165.45
65WnameD460.160
66WnameD515.130
67WnameD443.420
68WnameD368.390
69WnameD341.570
70WnameD338.410392.07
Sheet1 (2)
 
Upvote 0
Thank you for your help - apologies I've been off line for the weekend and yesterday (Christmas stuff!) - so just looking at this now :)
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

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