Count last days in a range IF - excel-formula

I have a table of data that shows what hours employees have worked over the course of a week. Where a staff member has worked more then 5 days the 6th and 7th day (if applicable) is calculated at time and a half, from a base rate of $20 an hour.
I can count the number of hours where a staff member has worked 7 days week pretty easy i.e. IF counter =7 sum G3:H3, however I am stuck with counting the 6th day as this could fall on the Saturday or Sunday.
Does anyone know how I could count the last cell in the range that has data? The challenge is row six where the employee has worked Saturday and Sunday, with only Sunday which is the 6th day entitled to overtime.
Thanks
Scott

Use this array formula to add up the hours:
=SUM(IF(COUNTIF(OFFSET(B3,0,0,,TRANSPOSE(ROW($1:$7))),">0")>5,1.5,1)*(B3:H3))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when Exiting edit mode.
Then to get the total pay just multiply that by 20:
=SUM(IF(COUNTIF(OFFSET(B3,0,0,,TRANSPOSE(ROW($1:$7))),">0")>5,1.5,1)*(B3:H3))*20
Still an array formula.

I've managed to find the answer via a reasonably simple formula
=LOOKUP(2,1/(B2:H2<>""),B2:H2)
Scott

Related

How to do I use Excel to make three cells change when any of the others are changed?

I want to make a table that can calculate the cost per week, per month and per year of any value.
If the per week value is entered it needs to calculate the per month and per year value.
If the per month value is entered, it needs to calculate the per week and per year value.
If the per year value is entered, it needs to calculate the per week and per month value.
I can only use three cells.
I haven't a clue how to do this. I don't even know how to run the code in Excel. I heard you have to use VBA but I have never touched Visual Basic let alone, used in in Excel.
Please can some one help. This is very important to me. Thanks in advance for any help :)
Going with a more formula driven route, I would suggest using an input range and a result range. In the attached screenshot, the blue cells are for inputs while the below formulas go i the row below the inputs.
For days
= if(not(isblank(A8)),A8,if(not(isblank(B8)),B8/30,C8/365))
For months
=if(not(isblank(A8)),A8*30,if(not(isblank(B8)),B8,C8/12))
For years
=if(not(isblank(A8)),A8*365,if(not(isblank(B8)),B8*12,C8))
Note1: I assumed 30 days a month and 365 days in a year.
Note 2: The order the formula calculates is first days, then months, then years. So, if something is in days it will need to be cleared out when inputting months and so on.

Excel. Weeknum function. #VALUE! error. Calendar

Dear person. As you can see in the picture there is a #VALUE! error when it tries to show some weeknumbers.
Referring to the picture:
Nr. 1. I'm trying to figure out how to show the weeknumbers that have datenumbers in that week
Nr. 2. I'm trying to figure out how to show a blank cell for the rows with no datenumbers in that week
The workbook: https://www.dropbox.com/s/ed6dt022i0yz6py/Calendar.xlsx?dl=0
Help!:)
I think this is the one you want based on weeks from Monday to Sunday
=IFERROR(WEEKNUM(AGGREGATE(15,0,C17:I17,1),2),"")
I have chosen to use Aggregate because it will error out if there are no numbers in the range, so IFERROR will give a blank. You could just use MIN or MAX instead and test for the result being zero. You could also use LOOKUP or HLOOKUP. This might be the shortest way
=IFERROR(WEEKNUM(LOOKUP(99999,C17:I17),2),"")
The week starting with December 31st ('week 53') is really week 1 of 2019 so you could add a separate condition for this.
To fix the 'week 53' issue, I can't do any better than this rather long formula at present
=IF(COUNT(C17:I17)=0,"",IF(AND(MONTH(LOOKUP(9E+99,C17:I17))=12,C17<>"",I17=""),1,WEEKNUM(LOOKUP(9E+99,C17:I17),2)))
which says 'if it is the last week of December and at least one of the days in that week is empty, then the week is week one of the following year'.
This could be further modified to deal with an ISO year where week 1 is the first week containing a Thursday.

Calculate the first week of year which starts from first Sunday of every Feb

I have an issue here. I want to calculate the week nummber of first sunday of business year. Where I work their calendar starts on February 1st. To calculate i have a column A2 in excel which has the date in mm/dd/yyyy format. I want to generate the corresponding fiscal week for the column.
example of my result set:
for 2/1/15 the week of year number should be 1
For 2/7/16 the week number of year should be 1
I tried the below formula, but its starting the week from the first day of the fiscal year and not the first sunday of the year.
=INT((A1-WEEKDAY(E9165)-DATE(YEAR(A1+7-WEEKDAY(A1))-(MONTH(A1)<2),2,1))/7)+2
Please help...
-Sandra
Assuming that your work years always start on the first sunday after February 1st:
=IF(WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1)<=0,52+WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1),WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1))
We first determine the week number of the date starting from the first Sunday of February. To do this I have used WEEKNUM()-WEEKNUM(02/01/SAMEYEAR) taking 1 day from the date to force week 1 as Excel begins counting from week 0 by default. Using IF() we state that if the outcome is 0 or less then add the result to 52, which will give us the correct result for dates in January as they produce negative values.
Edit - Very long formula but gives you the week of the quarter in Q1 W1 format:
=SUBSTITUTE(CONCATENATE("Q",INT(IF(WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1)<=0,52+WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1),WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1))/13)+(IF(INT(IF(WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1)<=0,52+WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1),WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1))-INT((IF(WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1)<=0,52+WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1),WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1))/13))*13)=0,0,1))," W",INT(IF(WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1)<=0,52+WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1),WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1))-INT((IF(WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1)<=0,52+WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1),WEEKNUM(A1)-WEEKNUM(DATE(YEAR(A1),2,1)-1))/13))*13)),"W0","W1")
Apologies for the length, I tried multiple methods to try to find a neater solution, but this was all that I could get to work. It would be a lot neater if there were multiple columns used.
Use this formula:
=IF(A1>=IF(WEEKDAY(DATE(YEAR(A1),2,1),1)=1,DATE(YEAR(A1),2,1),DATE(YEAR(A1),2,7-WEEKDAY(DATE(YEAR(A1),2,1),1)+2)),ROUNDUP((A1-IF(WEEKDAY(DATE(YEAR(A1),2,1),1)=1,DATE(YEAR(A1),2,1),DATE(YEAR(A1),2,7-WEEKDAY(DATE(YEAR(A1),2,1),1)+2))+1)/7,0),ROUNDUP((A1-IF(WEEKDAY(DATE(YEAR(A1),2,1),1)=1,DATE(YEAR(A1)-1,2,1),DATE(YEAR(A1)-1,2,7-WEEKDAY(DATE(YEAR(A1)-1,2,1),1)+2))+1)/7,0))
Way late to the party but was looking for the answer and found this thread. Ended up play around with the function myself and it's much easier to just deduct the dates; =WEEKNUM("date"- days you wish to offset)
Ex; If cell A1 holds my date, 2/1/2021 I wish to convert; =WEEKNUM(A1-31) result "1".

Calculate the number of biweekly pays in 1 month

To create a monthly budget in Google Sheets, biweekly pay needs to be calculated. Some months there are three paydays and some there are two. Paydays are every second Wednesday night.
The below formula worked previously, and now it does not.
Before being rounded, the formula calculates to =ROUNDDOWN(1.14)*1000 which multiplies the pay amount by one except there is never only one payday in a month. This month there are two pay days, 14/09/16 and 28/09/16.
=ROUNDDOWN((EOMONTH(TODAY(),0)-(MOD(DATE(2016,8,31)-DATE(YEAR(TODAY()),MONTH(TODAY()),1),14)+DATE(YEAR(TODAY()),MONTH(TODAY()),1)))/14)*1000
Where is the error in my formula?
Consider this formula:
=(INT((EOMONTH(TODAY(),0)-DATE(2016,8,31))/14)-INT((EOMONTH(TODAY(),-1)-DATE(2016,8,31))/14))*1000
It calculates all the paydays from the end of the current month back to your date of 8/31/2016 and subtracts all the paydays from the prior month back to the same date.
In march of 2017 it will give the correct 3 paydays.

Excel function to determine the last Friday in a month

I'm looking for an Excel function to return the last Friday in a month for a given date.
ie: Any date in the month as input will give the date of the last Friday as output.
14-July-09 should give 31-July-09
7-March-05 should give 35-March-09
Building on #Toomas answer above, I had to make some amendments for Excel 2007, but came up with the following:
=EOMONTH(A1,0)-MOD(WEEKDAY(EOMONTH(A1,0))+1,7)
Which is assuming that the WEEKDAY returned for Friday is 6 and then applying a shifted MOD 7 to achieve the correct day.
Try this formula:
=IF(WEEKDAY(EOMONTH(A5;0);16)=7;EOMONTH(A5;0);EOMONTH(A5;0)-WEEKDAY(EOMONTH(A5;0);16))
Enter to A5 date value of which you are looking for the last Friday in a month.
The following formula achives this for a date in cell A1:
=DATE(YEAR(A1),MONTH(A1)+1,0)+MOD(-WEEKDAY(DATE(YEAR(A1),MONTH(A1)+1,0),2)-2,-7)
I came here looking for the formula to get the most recent Friday in the past which turned out to be =TODAY()-WEEKDAY(TODAY())-1
In case anyone needs to do this for next year (or future years):
=EOMONTH(DATE(YEAR(TODAY())+1,MONTH(TODAY()),1),0)-MOD(WEEKDAY(EOMONTH(DATE(YEAR(TODAY())+1,MONTH(TODAY()),1),0))+1,7)
Here's one that will show the last Friday of the current month.
And if the date is in the past it will show you next month's last Friday.
And if it's December right now, it'll show you next year's January's Friday.
=IF(DATE(YEAR(TODAY()),MONTH(TODAY())+1,0)+MOD(-WEEKDAY(DATE(YEAR(TODAY()),MONTH(TODAY())+1,0),2)-2,-7)>=TODAY(), DATE(IF(MONTH(TODAY())+1>12,YEAR(TODAY()+1),YEAR(TODAY())),MONTH(TODAY())+1,0)+MOD(-WEEKDAY(DATE(YEAR(TODAY()),MONTH(TODAY())+1,0),2)-2,-7), DATE(IF(MONTH(TODAY())=12,YEAR(TODAY())+1,YEAR(TODAY())),MONTH(IF(MONTH(TODAY())=12,1,MONTH(TODAY())))+1,0)+MOD(-WEEKDAY(DATE(IF(MONTH(TODAY())=12,YEAR(TODAY())+1,YEAR(TODAY())),MONTH(IF(MONTH(TODAY())=12,1,MONTH(TODAY())))+1,0),2)-2,-7))
You can try
=DATE(YEAR(A1),MONTH(A1)+1,1)-1+CHOOSE(WEEKDAY(DATE(YEAR(A1),MONTH(A1)+1,1)-1),-2,-3,-4,-5,-6,0,-1)
to find the last friday of the month. Assumes A1 has the date.
Hey the formatting is outdated so ill show what I came up with:
=EOMONTH(A1;A2)-(WEEKDAY(EOMONTH(A1;A2);15)-1)
[A1] is an interval of months later, from [A2] the stating date, that the result date should be.
We have some equipment that need maintenance last Friday of the month, an number of months since last Maintenace.
EOMONTH(A1;A2): we find the date, of the last day, of target month.
WEEKDAY([Date];15): assign a number for day of the week.
[15] makes Friday the value 1 and Thursday the value 7.
so if the last day of the month is Friday, the calculation would be:
[Date]-(1-1) = [Date] therefor the date won't change.
[Date] in my original code example, is the last day of the target month: [A2] date + [A1] number of months later.
if the last day is Wednesday, we want it to subtract 5 days: [Date]-(6-1) = [Date]-5
As a sidenote:
=WORKDAY(A2+1;-1;[hollydays])
will round a date back to the earlier Workday if it lands in a weekend or holyday
[holyday] can be an area of cells with predefined dates to skip eg: [$C$1:$C$20].
$ is so the area won't change when you extend the function to other cells.
if you don't care about holydays use =WORKDAY(A2+1;-1)
Awesome! Basically, like trying to find the first or second Monday of the month,
=DATE(TheYear,5,1)+CHOOSE(WEEKDAY(DATE(TheYear,5,1)),1,0,6,5,4,3,2)
which returns the first Monday of the month, in this case May
but to find the last weekday of the month, in the formula, you start with the next month and subtract
=DATE(TheYear,6,1)-1+CHOOSE(WEEKDAY(DATE(TheYear,6,1)),-6,-5,-4,-3,-2,-1,0)
which returns the last Monday of May
I have a cell that I named TheYear, in which I enter the year I'm working with, but you can point to whatever cell you have the year you want (e.g. A1).
I don't know why the pointers to the days of the week are in reverse order but to find the day (e.g. Tuesday instead of Monday), change the order of those numbers but they have to stay in order. For example, 4th Thursday of November:
=DATE(TheYear,11,1)+21+CHOOSE(WEEKDAY(DATE(TheYear,11,1)),4,3,2,1,0,6,5)
=EOMONTH(TODAY(),0)-WEEKDAY(EOMONTH(TODAY(),0))-1
This gives the last Friday of this month. You can replace both instances of Today() with any date you like or a cell reference that has a date to get the last Friday in any other month.
=WORKDAY.INTL((EOMONTH(A4,0)+1),-1,"1111011")

Resources