How to use the current time & date to display specific value? - excel

I'm trying to set up an excel sheet which displays the name of the person available at the current time and date. I have one sheet with a list of dates and times along with the persons name who is available at that time. For example:
- 01/07/19 09:00 Bob
- 01/07/19 10:00 Bill
- 01/07/19 11:00 Ben
I can do this successfully for a full day or week using the WEEKNUM or DAYNUM functions, and the week/day number listed against the list of names.
I can use NOW() to get the current date and time, but I'm unsure how I can use this to get the desired results.
I've tried searching online for the answer but have been unable to find what I'm looking for.
Based on my example above, if the current time is between 9:00 & 10:00 I want the name Bill to be displayed.

Based on your dates being actual dates stored as number for excel and not numbers stored as text, and same for time, then the following solution should work for you. You can test your data to see if its an actual date using:
=ISNUMBER(A2) `where A2 is the cell in question
If the formula returns true then you know your are dealing with a number that has been formatted to display as a date or time.
As a side note, dates are stored as integers and are the number of days since 1900/01/01 with that date being 1. Time is stored as a decimal representing the portion of the day. 0.5 would be 12 noon.
This solution assumes the data is layed out as per the image below.
In cell F1, place your NOW() function. I have manually entered the date to control the value for demonstration purposes.
In cell F2 enter the following formula:
=INDEX(C:C,AGGREGATE(15,6,ROW($A$2:$A$4)/((INT($F$1)=$A$2:$A$4)*(MOD($F$1,1)<=$B$2:$B$4)),1))
AGGREGATE will make a list or all row number and sort them from largest to smallest. All Those row numbers will be divided by your criteria checks. If your criteria results are ALL True, then the row is divided by 1 and remains unchanged. If a criteria is not met the Row number is divided by 0 which causes an error. The 6 in the function tells aggregate to ignore error results. So you wind up with a list or row numbers that march your criteria. The 15 in aggregate tells aggregate to sort the row numbers from largest to smallest. The 1 tells aggregate to return the row number in position 1 of the sorted list. Aggregate then passes that row number to INDEX which finds the row in the corresponding column and returns the address of that cell.
now just so you are aware. The break point for time was set so that the person beside the list time is the one that will be picked when that exact time is provided. Meaning for a time of 0900 on the specified day, Bob would be selected. At 10:00:01 Ben will be selected. At 11:00:01 an error will be generated. you can control this by placing the whole thing in an IFERROR function. At 00:00:00 Bob is selected.

I believe this will do what you want:
=INDEX(C2:C4,MATCH(NOW()-TODAY(),B2:B4,1))
Where column C contains the names and column B the times
If date and time are in one column, you can try:
=INDEX(B1:B3,MATCH(NOW(),A1:A3,1))
Where column B contains the names and column A the date and time

Here is one way:
Formula in F1:
=INDEX(C2:C4,MATCH(1,INDEX((A2:A4=TODAY())*(HOUR(B2:B4)<=HOUR(NOW()))*(HOUR(B2:B4)>=HOUR(NOW())),0,1),0))
What's happening? We use MATCH to get the first TRUE in an INDEX list that compares column A against TODAY times column B for HOUR.
We can leave out the second INDEX but that would make it an array formula to be entered through CtrlShiftEnter
Note that this example is made around 9:30 on the 4th of July.

Related

VLOOKUP to find weeknumber

I'm sure there is a more appropriate method for this, but I have layers of referencing so it has to be done this way. My spreadsheet is like an onion.
I need to be able to pull the week number based on a value defined in another sheet. So far the user enters the date when they start the sheet up. It is always the 1st of the month. This is then reference for a host of things elsewhere. This value is currently in =Front!$C$3. I have a visual calender set up as 53 rows, with 1 row per seven day period. I had written =VLOOKUP(O25, $S$2:$Z$54, 1, FALSE ) which had worked on a two column table for another task with different referencing. Currently I get #N/A as the return.
I'm assuming there is a way to have the cell check the red area for a value matching 1/1/23 (formatted as a custom format to just show the day number) and return the value in column 1 (the week number)
In my case O25:O36 is just 1/1/23:1/12/23. N25:N36 is the same just referencing the adjacent cell for O.
If there is a more straight forward way of having a cell return the weeknumber for the first day of each month, so I can have a cell on Front! return the week number based on the value in =Front!$C$3 that would be ideal also.
Thanks for the second time to #FoxfireAndBurnsAndBurns again, for pointing out a simple answer. ISOWEEKNUM with the dates of the first of the month has resolved.
=ISOWEEKNUM("1/1/23")

Excel Formula to Calculate Checkin Time

I have a file from restaurant log of 1 month. I need to calculate the Checkin Time time from Time and Bill Number column.
My Format is:
Date |Time| TableNumber| Checkin time |Bill Number ..|...|...|
I can calculate it manually one at a time by copying the 1st data of Time column and copying in Checkin time where bill number is same.
I have attached a Screenshot of the data.
Example 1: Blue square
Here in the blue square we can see that first value of Time column is 0:02:37 and I have pasted it in Checkin time which has Bill Number 29 .
Example 2: Red square
First value of Time is 16:08:40 And I have pasted in Checkin time column which have bill number of 1 and so on..
I did it manually without any equation or formulas. But the problem is the data is of 1 month and I have about 6 to be calculated.
What I tried
From the formula given to me by #girlvsdata
I tried
=MINIFS(B:B,E:E,E3)
I did get the data for 1st two unique Bill numbers, but after dragging down the forumla further down, I get different Time for new bill number. + as the bill number repeats in further down rows many times, it gives me same time of 1st bill number for repeated bill numbers.
Here is the screenshot of after What I tried
Screenshot_after
I propose the following:
=IF(AND(E3=E1,C3=C1,A3=A1),D1,MIN(OFFSET(E3,0,-3,MATCH(0,(E3:E$18=E3)*(C3:C$18=C3)*(A3:A$18=A3),0)-1,1)))
It is a bit long and will likely take a while to calculate if you have lots of rows. The above formula is to be entered as an array formula, i.e. copy/type the formula then instead of pressing Enter, use Ctrl+Shift+Enter. If you do it right, excel will insert {} around it like in the screen shot below:
Change the ranges E3:E$18, C3:C$18 and A3:A$18 accordingly and notice that they are all one row below the end of the table (otherwise you get #N/A for the last bill).
If you have the latest version of Excel, you can use =MINIFS() to find the first Time for that particular Bill Number (the Checkin time).
In cell D3 enter this formula:
=MINIFS(B:B,E:E,E3)
Make sure that the cell has Time formatting for it to show correctly.

Finding pass rate in Excel within a date range

I have a large control sheet in Excel with over 1000+ students on it. I have three columns that I want to use which are (Start of 2 year study period - column 1), (End of 2 year study period - column 2) and (Pass/No Pass - column 3)
When a learner registers with us we will type in the start date of registration in the first column and then +730 for the 2nd column giving us our end date.
In the pass no pass column each learner has to complete units and when they pass this unit I mark it as a pass.
What I want to try and achieve / find out is pass rates either
A. per year or
B. every two years (registration period)
For example if I registered say 200 students between 01/01/2015 and 01/01/2017 I want to know what the code for that would be - if there is any code.
Something like =COUNTIF(C:C,"Yes")/(COUNTA(A:A)-1) would do it where "Yes" means they have passed (if you want, you can change this to "passed" etc.).
The above formula puts the total number of "Yes"'s over the total number of people registered (COUNTA(A:A)-1 counts all cells with an entry and then takes away the header)
Here's what it's look like:
EDIT: Please forget the dates entered in column B - I just entered random dates so these aren't correct but the formula works perfectly regardless.
If you want to do an analysis per year you can use the following helper column D.
Column A: Start date formatted as date (localization doesn't matter)
Column B: =A:A+730
Column D: =YEAR(A:A) (format as standard or number)
G3: =COUNTIFS(D:D,"=2016",C:C,"=Pass")
G4: =COUNTIFS(D:D,"=2016")
If you need a 2 year analysis (eg. 2016+2017) do an analysis for both years and add them up later. Then calculate the rate.

How To Ignore Blank Cells for a Formula

I'm tracking hours for my company and I need to see the updated hours daily. I have everything formatted how I want it, except I want two columns to show how many hours over and under each employees current hours are.
What I have right now is
=(D3-C3)+(F3-E3)+(H3-G3)+(J3-I3)+(L3-K3)+(N3-M3)+(P3-O3)
But it is including all the empty cells (for days that haven't been worked yet) as a zero.
I want a formula that can allow me to ignore those blank cells until they have content.
I can't just use a SUMIF >0 function because I need to count the number of hours employees have MISSED (i.e. scheduled 12 hrs, actually worked 0).
Here's an alternate approach to #Tom's, though it works on similar principles. This one, however, relies on your ability to add a couple of 'HELPER' rows, above your current data.
I'm assuming that row 1 will alternate between saying "PROJECTED", and "ACTUAL".
I'm assuming that row 2 will be dates for that week, in Date format. So A2 will be Jan 1 2015, B2 will be Feb 1 2015, C3 will be Feb 1 2015, or however often the time blocks go up. The key here is that the PROJECTED columns and the ACTUAL columns will each need the date in them.
The formula to check the variance between that row's PROJECTED amount and that row's ACTUAL amount, only for dates prior to today, is (for row 3 and copied down, and assuming the data goes to column Z):
=SUMIFS(A3:Z3,$A$1:$Z$1,"PROJECTED",$A$2:$Z$2,"<"&TODAY())-SUMIFS(A3:Z3,$A$1:$Z$1,"ACTUAL",$A$2:$Z$2,"<"&TODAY())
This checks to see the value of PROJECTED columns for that row, where the date is less than today, and subtracts the value of ACTUAL columns for that row, where the date is less than today.
If you are looking to compare with something other than TODAY(), you can set up a cell to be your 'comparison point'. Manual type the breakoff period you are concerned with into that cell, and replace "&TODAY()" with, say, "&AA1" [assuming your breakoff point is entered in cell AA1].
As it stands, either a very long series of IF's and OR's or an array formula:-
=SUM(IF(OR(D3="",C3=""),0,D3-C3),IF(OR(F3="",E3=""),0,F3-E3),IF(OR(H3="",G3=""),0,H3-G3),IF(OR(J3="",I3=""),0,J3-I3),IF(OR(L3="",K3=""),0,L3-K3),IF(OR(N3="",M3=""),0,N3-M3),IF(OR(P3="",O3=""),0,P3-O3))
=SUM(D3:P3*ISEVEN(COLUMN(D3:P3))*(C3:O3<>""))-SUM(C3:O3*ISODD(COLUMN((C3:O3))*(D3:P3<>"")))
The second one must be entered with CtrlShiftEnter
Note that it could easily be broken by insertion/deletion of columns.

Month-to-date totals

I have an Excel workbook that has several different worksheets in it. The one worksheet that contains the main data has 100's of entries. This sheet also gets a new entry every day in the row column. The first column is the date column that is formatted as date and time.
I need a formula that checks the newest entry's date to see if its month matches the current month and then sums all entries for that month. I know that I am going to use a SUMIF but the hard part is the rest of the formula. I forgot to mention that I need the formula to divide by the number of current month entries used.
Assuming your dates are in A1:A26 and amounts to be summed are in in B1:B26 here is the formula to use.
=SUMIFS(B1:B26,A1:A26,">="&DATE(YEAR(TODAY()),MONTH(TODAY()),1),A1:A26,"<="&TODAY())
This returns the amounts that are in a date that is greater than or equal to the first day of the current month, AND less than or equal to TODAY.
There are a couple ways you could do this and I would suggest using sumproduct formula.
I'm assuming your data has dates in column A starting in row 2, and a value in column B.
In column C you could have a total in each line which is the sum of all rows above the current one that the month matches.
Formula in C2 would be below which can be carried down
=SUMPRODUCT(--(MONTH(A2)=MONTH($A$2:A2)),$B$2:B2)
Otherwise if you have a single cell and just want to get the latest total this formula would do it. This assumes the latest entry will also be the newest date (highest value)
=SUMPRODUCT(--(MONTH(MAX(A:A))=MONTH(A2:A1000)),B2:B1000)
In sumproduct the first part of the formula --(A=B) returns true or false values which equate to 1s and 0s. The second part is just your value columns.
The second formula does the same thing but it compares the month of the newest date to all others in the column.
Gordon
Since new entries are added daily I am assuming these are in date order ascending, so please try:
=SUMIF(A:A,">"&EOMONTH(TODAY(),-1),AD1:AD100)
or adjust the AD range to suit (could use AD:AD).

Resources