具有多个条件的复杂Excel方程

弗林

我有一张工作表,用于根据时间表计算税金,扣除额和401k。它还可以计算我的PTO,患病天数和补偿天数(我没有加班,当我加班时,我会在年底将这段时间作为额外带薪休假的时间)。我的问题是,使用时间表很难计算我的病假,其他所有时间都是每小时或每小时。但是在病假的时候,我每年都会得到一定数量的钱。

基本上,我每年有10天(80小时)。因此,我花了80个小时,将其除以26,这使我每个工资期得到多少病假。问题是,由于我得到的是双周工资,所以这实际上是不正确的。因此,例如,本月我有2张薪水单,我会得到0.92天的病假时间,但实际上我应该得到1天。在一年中的2个月中,我有3张薪水,我将得到1.38天的病假时间,这当然也不正确。

因此,问题是我试图弄清楚如何编写公式来给我正确的天数。请参阅屏幕截图:

在此处输入图片说明

So basiclaly on G6, the formula takes the rolled over sick days from the previous year (G39) and adds the current sick time to it. It decides that by checking if the gross pay for that pay period is there, then multiplies that amount by the sick time accrual rate (G40) and divides that by 8 to give me the days.

But what I want to do is to check how many months have been filled out and return that. So in this example May has been completed, so it would return 1 day. Since September has 3 pay periods, you will need to have all three September paychecks filled out for it to increment from 4 to 5 (may, jun, jul, aug makes 4).

Any ideas? Everything I've tried to do this it just fails. Keep in mind that those dates are dynamic, next year when I change the start date for the tax year, the months that have 3 months will change to match the actual pay periods for that year. So this formula will need to actually be able to count that any month has 3 pay periods to advance the sick day count, otherwise to do it if there are only 2 that have been filled.

Forward Ed

Attempt #2 to answer! >8(

The end equation to do this all in one cell is going to get ugly,but it will work. In order to explain this and basically how I developed it, I am going to break it down into parts. At the end the parts will be back substituted into the big equation.

The first thing I did was determine what row was last filled, or as per the comments what is the last row of column P that has a value greater than 0. In order to determine this I used the aggregate function in a temporary cell of T15 (yes, in the middle of your spreadsheet but it wont matter in the end):

=AGGREGATE(14,6,(P5:P30>0)*(ROW(P5:P30)-ROW(P5)+1),1)

To break this function down:

  • 14 tells it we want to do an array type calculation sorting the array from largest to smallest.
  • 6 tells it to ignore errors
  • (P5:P30>0) tells it to build a true (or 1) and false (or 0) array of cells greater than 0
  • (ROW(P5:P30)-ROW(P5)+1) generates an array listing row numbers
  • 1 tells it to return the largest value in the array, if it was 2 the second largest.

Now the important thing here is what happens when you multiply the greater than 0 array with the row number array. You wind up getting only the row numbers where there is a value in P greater than 0. And when we sort that and ask for the largest number we get the last row you have completed. Something to work with.

So now we can look up the last date completed, do some checks to see if its the end of the month or not and figure out how many sick days. The ugly formula starts out as:

=IF(MONTH(INDEX(I5:I30,T15))=MONTH(INDEX(I5:I30,T15)+14),MONTH(INDEX(I5:I30,T15))-1,MONTH(INDEX(I5:I30,T15)))

The logic test here is to find our if the last filled out date and the date 14 days in the future are still the same month. If they are the same month, you are not at the end of the month yet and there for have only earn up to the previous month's number in sick days. As such this part will tell us the previous month's number os sick days:

MONTH(INDEX(I5:I30,T15))-1

Now if the date 14 days in the future is not the same month then we know the last entry for the month has been completed and therefore we have accrued that month's number in sick days and use basically the same formula:

MONTH(INDEX(I5:I30,T15))-1

well I can see we have called on cell T15 4 times just to determine if we are subtracting 1 or 0. While the IF formula may feel more inline with your thought process, we can rearrange things and still get the same results but shortening the formula, reducing the calls to cell t15 by 1 and dropping the IF all together. This only works because we are dealing with 1 and 0 which is also true and false.

=MONTH(INDEX(I5:I30,T15))-(MONTH(INDEX(I5:I30,T15))=MONTH(INDEX(I5:I30,T15)+14))

Now lets bypass that T15 calculation and back substitute it in to the month formula above to get:

=MONTH(INDEX(I5:I30,AGGREGATE(14,6,(P5:P30>0)*(ROW(P5:P30)-ROW(P5)+1),1)))-(MONTH(INDEX(I5:I30,AGGREGATE(14,6,(P5:P30>0)*(ROW(P5:P30)-ROW(P5)+1),1)))=MONTH(INDEX(I5:I30,AGGREGATE(14,6,(P5:P30>0)*(ROW(P5:P30)-ROW(P5)+1),1))+14))

Not done yet. That only tells you the number of days you have accrued this year. Not what you really want to know. you need to convert it to hours. It also need to be reduced by the number of sick days used. The following need to be added to the big ugly above:

  • *8 for 8 sick hours to a sick day
  • -sum($L$5:$L$30) to account for sick time used

this results in:

=(MONTH(INDEX(I5:I30,AGGREGATE(14,6,(P5:P30>0)*(ROW(P5:P30)-ROW(P5)+1),1)))-(MONTH(INDEX(I5:I30,AGGREGATE(14,6,(P5:P30>0)*(ROW(P5:P30)-ROW(P5)+1),1)))=MONTH(INDEX(I5:I30,AGGREGATE(14,6,(P5:P30>0)*(ROW(P5:P30)-ROW(P5)+1),1))+14)))*8-sum($L$5:$L$30)

Now I did notice during testing that if no entries are in the spreadsheet, then the row of the last entry become 0 and this is simply not acceptable as it causes some strange results. So we will wrap this whole formula in a small error catcher to make sure 0 is the results when no payperiods have been completed.

=if(sum(P5:P30)=0,0,(MONTH(INDEX(I5:I30,AGGREGATE(14,6,(P5:P30>0)*(ROW(P5:P30)-ROW(P5)+1),1)))-(MONTH(INDEX(I5:I30,AGGREGATE(14,6,(P5:P30>0)*(ROW(P5:P30)-ROW(P5)+1),1)))=MONTH(INDEX(I5:I30,AGGREGATE(14,6,(P5:P30>0)*(ROW(P5:P30)-ROW(P5)+1),1))+14)))*8-sum($L$5:$L$30))

锦上添花的是从上一年开始累计的病假天数增加了。由于我不确定患病率和病假开始如何协同工作,因此我将把该计算留给您,让您知道上一年结转的任何数字,只需在最后一个末尾将其添加到上述公式中即可) 。

这是我的测试床,上面显示了概念证明:

概念证明

警告:此方法## WILL ##会产生错误的结果,因为最后一个日期之前的支付期= = 0,且支付期> 0,请参见以下示例:

方法问题

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

具有多个条件的“复杂”查询(BEGINNER)

来自分类Dev

具有复杂条件的Excel SUMIFS函数

来自分类Dev

具有多个条件的Excel和公式

来自分类Dev

具有多个条件的EXCEL公式

来自分类Dev

Excel-具有多个条件的vlookup

来自分类Dev

具有多个条件的Excel COUNTIFS

来自分类Dev

具有多个变量的因子方程

来自分类Dev

如果具有多个条件,则为Excel平均

来自分类Dev

Excel数组公式查找具有多个条件的最小日期

来自分类Dev

在Excel中具有多个匹配条件的SUMIF

来自分类Dev

具有多个单元格比较的Excel条件格式

来自分类Dev

Excel Basic:具有不同输出的多个条件和案例

来自分类Dev

Excel 或 R - 创建具有多个条件的变量?

来自分类Dev

将 Excel TextJoin 与具有多个条件的 Countifs() 结合使用

来自分类Dev

具有数组常量的Excel方程

来自分类Dev

具有AND和OR的复杂Arel条件

来自分类Dev

具有AND和OR的复杂Arel条件

来自分类Dev

具有多个JOINS的复杂选择逻辑

来自分类Dev

具有多个属性的复杂过滤查询

来自分类Dev

具有结果的复杂Excel查找

来自分类Dev

具有多个条件的if语句

来自分类Dev

具有多个条件的$ sum

来自分类Dev

具有多个条件的NSPredicate

来自分类Dev

具有多个条件的计数?

来自分类Dev

具有多个条件的子集

来自分类Dev

具有多个条件的分组

来自分类Dev

具有多个条件的VLOOKUP

来自分类Dev

具有多个条件的$ sum

来自分类Dev

具有多个条件的if语句