Calculate maximum of 3 amounts for daily pay but I have the same date on multiple rows

megera716

Board Regular
Joined
Jan 3, 2013
Messages
140
Office Version
  1. 365
Platform
  1. Windows
I've got a table of people, procedures they performed by day and the duration of each procedure. Comp structure is such that the employee's pay for that day is the greatest of 3 options:
1) Actual hours worked * $100
2) $750
3) If 3 procedures are performed in a day, $500 for the first one, $250 for the second, $250 for the third. So basically $1000.

That is their pay for the WHOLE DAY so I'm struggling with how to write this so it doesn't try to put the daily pay amount on every row for that day. I am fine if it's easier for the formula to be written to say $375 ($750/2) for Procedure 1 and $375 for Procedure 2 instead of $750 on #1 and $0 on #2. This is extra "fun" (to me) because we're working with times here and I know that can make things wonky. Like if I multiply Employee 1's December 1 total time worked of 4:36 (4h 36m) by $100, the result is $19.17 o_O.
1706901951023.png


Yes, I did change the formula on Row 6 just to see if I could make that work and that one actually works the best of the three! But it's only for when they do have 3 procedures that day -- notice the $500, $250, $250 on Employee 2 for 12/5/2023 -- but obviously I want one formula to work the whole way down.
1706901971104.png


I would be eternally grateful to anyone who can help me automate this!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Maybe this:

Book1
ABCDEFGHIJKLMNO
1NameProcedureDateStartEndDurationPay
2Emp 1112/1/20237:5710:532:56750
3Emp 1212/1/202312:2914:091:40 
4Emp 1112/19/20236:558:531:58750
5Emp 1212/19/202311:3313:372:04 
6Emp 2112/5/20236:107:421:321000
7Emp 2212/5/20238:329:331:01 
8Emp 2312/5/202310:3214:043:32 
Sheet5
Cell Formulas
RangeFormula
O2:O8O2=IF(COUNTIFS($C$2:C2,C2,$E$2:E2,E2)=1,MAX((HOUR(N2)+MINUTE(N2)/60+SECOND(N2)/(60*60))*100,750,IF(COUNTIFS($C$2:$C$8,C2,$E$2:$E$8,E2)=3,1000,0)),"")
 
Upvote 1
Solution
Maybe this:

Book1
ABCDEFGHIJKLMNO
1NameProcedureDateStartEndDurationPay
2Emp 1112/1/20237:5710:532:56750
3Emp 1212/1/202312:2914:091:40 
4Emp 1112/19/20236:558:531:58750
5Emp 1212/19/202311:3313:372:04 
6Emp 2112/5/20236:107:421:321000
7Emp 2212/5/20238:329:331:01 
8Emp 2312/5/202310:3214:043:32 
Sheet5
Cell Formulas
RangeFormula
O2:O8O2=IF(COUNTIFS($C$2:C2,C2,$E$2:E2,E2)=1,MAX((HOUR(N2)+MINUTE(N2)/60+SECOND(N2)/(60*60))*100,750,IF(COUNTIFS($C$2:$C$8,C2,$E$2:$E$8,E2)=3,1000,0)),"")
OMG!!!11!! :love: I don't know how it works but it works! If you wouldn't mind breaking it down for me so I can follow it better, I'd be so grateful but I am already so grateful that I have a solution!

Mostly not following the first COUNTIFS and why we're not including the whole range in there (to row 8) or absoluting the end of the range (e.g., it's $C$2:C2, not $C$2:$C$2 or $C$2:$C$8, but the second countifs IS to $C$8 and $E$8). Will this be dependent on the data always being sorted this specific way? (which was by employee, then by date, then by procedure #). If yes, that's fine. Just want to make sure I understand how to apply this to what will be a continuously-growing table.
 
Upvote 0
OMG!!!11!! :love: I don't know how it works but it works! If you wouldn't mind breaking it down for me so I can follow it better, I'd be so grateful but I am already so grateful that I have a solution!

Mostly not following the first COUNTIFS and why we're not including the whole range in there (to row 8) or absoluting the end of the range (e.g., it's $C$2:C2, not $C$2:$C$2 or $C$2:$C$8, but the second countifs IS to $C$8 and $E$8). Will this be dependent on the data always being sorted this specific way? (which was by employee, then by date, then by procedure #). If yes, that's fine. Just want to make sure I understand how to apply this to what will be a continuously-growing table.
=IF(COUNTIFS($C$2:C2,C2,$E$2:E2,E2)=1,MAX((HOUR(N2)+MINUTE(N2)/60+SECOND(N2)/(60*60))*100,750,IF(COUNTIFS($C$2:$C$8,C2,$E$2:$E$8,E2)=3,1000,0)),"")

The first COUNTIFS allows us to identify which row to display the result on, letting us find where the first unique value starts for each employee/date combo. By leaving the end of the range open (not absolute), the range will increase as the formula is dragged down, therefor limiting the area to the first row through the current row. See the example below to see that by limiting the range, we can get an incremental count instead of the total count for the whole range:
Book1
ABC
1NameCOUNT openCOUNT absolute
2A13
3A23
4A33
5B14
6B24
7B34
8B44
9C11
Sheet6
Cell Formulas
RangeFormula
B2:B9B2=COUNTIF($A$2:A2,A2)
C2:C9C2=COUNTIF($A$2:$A$9,A2)


The second COUNTIF is using the entire range as absolute so we can see if the total count is 3, as seen in the above example. Also, if we locked the range at $C$2:$C$2 it would only ever look at row 2 no matter how far it is dragged down.

It should not matter how the data is sorted.

You're welcome, and happy to help.
 
Upvote 1
=IF(COUNTIFS($C$2:C2,C2,$E$2:E2,E2)=1,MAX((HOUR(N2)+MINUTE(N2)/60+SECOND(N2)/(60*60))*100,750,IF(COUNTIFS($C$2:$C$8,C2,$E$2:$E$8,E2)=3,1000,0)),"")

The first COUNTIFS allows us to identify which row to display the result on, letting us find where the first unique value starts for each employee/date combo. By leaving the end of the range open (not absolute), the range will increase as the formula is dragged down, therefor limiting the area to the first row through the current row. See the example below to see that by limiting the range, we can get an incremental count instead of the total count for the whole range:
Book1
ABC
1NameCOUNT openCOUNT absolute
2A13
3A23
4A33
5B14
6B24
7B34
8B44
9C11
Sheet6
Cell Formulas
RangeFormula
B2:B9B2=COUNTIF($A$2:A2,A2)
C2:C9C2=COUNTIF($A$2:$A$9,A2)


The second COUNTIF is using the entire range as absolute so we can see if the total count is 3, as seen in the above example. Also, if we locked the range at $C$2:$C$2 it would only ever look at row 2 no matter how far it is dragged down.

It should not matter how the data is sorted.

You're welcome, and happy to help.

Fantastic, thank you so much for the original solution AND the added explanation!
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

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