Time 13:15:09 Batch 09:00 to 18:00
I have to compare if Column1(Time) is between the time mentioned in Column2(Batch)
This can also be accomplished using MEDIAN function in Excel.
Try the following formula:
=TIMEVALUE(RIGHT(A1,8))=MEDIAN(RIGHT(A1,8),MID(B1,7,5),RIGHT(B1,5))
And to be on safer side you can use TIMEVALUE for all the values used in formula as:
=TIMEVALUE(RIGHT(A1,8))=MEDIAN(TIMEVALUE(RIGHT(A1,8)),TIMEVALUE(MID(B1,7,5)),TIMEVALUE(RIGHT(B1,5)))
we will assume your data is all in a string and the format of the string does not change. We will pull out the time through some string manipulations and counting and use the timevalue function in the end.
Let assume for now that we are pulling the column A time out and placing it in column B. This is a temporary step and will disappear when all combined in one cell at the end. Since we know the time is the last 8 characters we can use the following:
=Timevalue(Right(A1,8))
Now let pull the first time in column B. Lets us a left right string strip combination to pull the time. We could also use mid. The first formula would look like:
=timevalue(right(left(B1,11),5))
or
=timevalue(MID(B1,7,5))
To pull out the second time the easiest approach would be a reapeat of what we did for the first time we pulled out and use the RIGHT formula:
=timevalue(right(B1,5))
Now you could put all those in separate columns to ensure they are working and assist you will building your final equation. With all that in one cell, you final equation would look something like.
=if(AND(Timevalue(Right(A1,8))<=timevalue(right(B1,5)),Timevalue(Right(A1,8))>=timevalue(MID(B1,7,5))),"Time is within batch time","Time outside batchtime")
Related
I am trying to get a formula that will help count cells that fall within a time window. I came up with a formula but it only works when the time is from AM to PM and not for PM (previous day) to AM (next day). As shown in the image, I want to be able to count the number of Korea trades (from Table 2) within trading window (Table 3). I was trying to use the highlighted formula but apparently it's not working on Table 1.
Formula: =COUNTIFS(D13:D16, "Korea", E13:E16, ">="&H4, E13:E16, "<="&I4)
Is there a way to achieve this?
When the times cross midnight for Korea, you'll need to do an OR condition rather than an and condition. You could do this by making two countifs functions or use Sumproduct as shown below:
=SUMPRODUCT((D13:D16="Korea")*((E13:E16>=H3)+(E13:E16<=I3)))
If you have access to a version of Excel that supports the Lambda function I’d suggest creating a lambda that does the within checking so it’s not done through the formulas on your sheet. Unfortunately I don’t think there are Ifs functions that take a lamdba as a criteria but you might be able to use Map to generate an array of booleans and get the product similar to the other reply.
So I started by creating a lambda for determining if the value is in the range. The formula I used is:
=LAMBDA(s,e,IF(s<e,LAMBDA(x,AND(x>=s,x<e)),LAMBDA(x,OR(x<e,x>s))))
That basically takes 2 parameters - your starting time and the ending time for the range. It will return a lambda that will take the time to compare. And I added that as a namedreference named “IsWithin”
Then I created another lambda that would do the overall count.
=LAMBDA(rangeMatch,textMatch,rangeTime,start,end,SUM(MAP(rangeMatch,LAMBDA(x,ISNUMBER(SEARCH(textMatch,x))))*MAP(rangeTime,IsWithin(start,end))))
The function takes 5 parameters:
the range for which you are searching for the country name
the text to match within the range
the range containing the times to evaluate
the start time for the valid range (e.g. H3)
the end time for the valid range (e.g. I3)
It uses the Map function to evaluate the items in the range using lambdas. The first part of the evaluate creates an array of the items that have the matching text so either TRUE or FALSE. The second part creates an array of items that are within the specified time range - again either TRUE or FALSE. And then it just multiplies those arrays and sums the values essentially getting those where both values are true. Then to use it you just call that named reference:
=CountMatch(D13:D16,"Korea",E13:E16,H4,I4)
You can try this
=SUMPRODUCT(--(LEN(D13:D16)<>LEN(SUBSTITUTE(D13:D16,"Korea","")))*((E13:E16>=H4)+(E13:E16<=I4)))
is there anything i can do to further improve performance of this formula ?
=IF($A3<>"",IF(Jan!$E6<>"",LET(d_patt,IF(Jan!$E6<>"",VLOOKUP(Jan!$E6,SETTINGS!$A$12:$B$27,2,FALSE)&IF(Jan!$B6<>"",Jan!$B6,0)&IF(Jan!$C6<>"",Jan!$C6,0)&IF(Jan!$D6<>"",Jan!$D6,0),""),"ROT"&IF(LEN(Teams!$BHR4)>0,MID(Teams!$BHR4,MOD(NETWORKDAYS.INTL(Teams!$C4,I$2,"0000000")-1,LEN(Teams!$BHR4)/3)*3+1,3),"000")&IF(LEFT(d_patt,3)="OVT",d_patt,"OVT000")&IF(LEFT(d_patt,3)="SSI",d_patt,"SSI000")&IF(LEFT(d_patt,3)="SSO",d_patt,"SSO000")&IF(LEFT(d_patt,3)="SDS",d_patt,"SDS000")&IF(LEFT(d_patt,3)="HOL",d_patt,"HOL000")&IF(LEFT(d_patt,3)="LID",d_patt,"LID000")&IF(LEFT(d_patt,3)="UNP",d_patt,"UNP000")&IF(LEFT(d_patt,3)="FLD",d_patt,"FLD000")&IF(LEFT(d_patt,3)="MAT",d_patt,"MAT000")&IF(LEFT(d_patt,3)="LIS",d_patt,"LIS000")&IF(LEFT(d_patt,3)="CBR",d_patt,"CBR000")&IF(LEFT(d_patt,3)="ABS",d_patt,"ABS000")),"ROT"&IF(LEN(Teams!$BHR4)>0,MID(Teams!$BHR4,MOD(NETWORKDAYS.INTL(Teams!$C4,I$2,"0000000")-1,LEN(Teams!$BHR4)/3)*3+1,3),"000")&"OVT000SSI000SSO000SDS000HOL000LID000UNP000FLD000MAT000LIS000CBR000ABS000"),"")
i have this on a sheet for each day of the year x 400 people so 146k+ times. this is therefor taken up 80% of the sheet load time.
The sheet basically gets shift patters from Teams, check if there is any holidays, overtime etc from the relevant month tab and relevant cell for the day, and then will generate a code like below.
ROT080OVT000SSI000SSO000SDS234HOL000LID000UNP000FLD000MAT000LIS000CBR000ABS000
i have so far managed to make this faster by using the LET function, but not show if its possible to make any further improvements.
if you need an example file i can send this or upload somewhere, not sure if that is possible via stackoverflow or a preferred site to upload to.
Thanks
The following is a shortened version of your formula to reduce the complexity of computations.
Instead of building the 'OVT000SSI000...' string one piece after another while always checking if the first 3 characters of 'd_patt' match the current piece, we can set the whole string with '000's as default and only replace the section that matches 'd_patt' (see highlighted elements in screenshot below)
Which results in the full formula:
=IF(LEN($A3)>0,"ROT"&IF(LEN(Teams!$BHR4)>0,MID(Teams!$BHR4,MOD(NETWORKDAYS.INTL(Teams!$C4,I$2,"0000000")-1,LEN(Teams!$BHR4)/3)*3+1,3),"000")&LET(default,"OVT000SSI000SSO000SDS000HOL000LID000UNP000FLD000MAT000LIS000CBR000ABS000",d_patt,VLOOKUP(Jan!$E6,SETTINGS!$A$12:$B$27,2,FALSE)&IF(LEN(Jan!$B6)>0,Jan!$B6,0)&IF(LEN(Jan!$C6)>0,Jan!$C6,0)&IF(LEN(Jan!$D6)>0,Jan!$D6,0),IF(LEN(d_patt)>0,REPLACE(default,SEARCH(LEFT(d_patt,3),default),6,d_patt),default)),“”)
If $B6, $C6 and $D6 can only be either empty or a numerical number, in other words, if they are never a letter or special character, the 'd_patt' function can be further shortened as follows:
Which results in the full formula:
=IF(LEN($A3)>0,"ROT"&IF(LEN(Teams!$BHR4)>0,MID(Teams!$BHR4,MOD(NETWORKDAYS.INTL(Teams!$C4,I$2,"0000000")-1,LEN(Teams!$BHR4)/3)*3+1,3),"000")&LET(default,"OVT000SSI000SSO000SDS000HOL000LID000UNP000FLD000MAT000LIS000CBR000ABS000",d_patt,VLOOKUP(Jan!$E6,SETTINGS!$A$12:$B$27,2,FALSE)&(Jan!$B6+0)&(Jan!$C6+0)&(Jan!$D6+0),IF(LEN(d_patt)>0,REPLACE(default,SEARCH(LEFT(d_patt,3),default),6,d_patt),default)),“”)
First question here, thanks in advance for your patience and assistance!
I have a spreadsheet that contains course types (column A, e.g. "Lec" or "Dis"), enrollment numbers (column B, as integers), and session times (column C, string time interval e.g. "10:00AM - 01:00PM").
I need to sum the enrollment numbers for all classes of a certain type (say "Lec") that end before a certain time (say 3:00 PM). The following code accomplishes that:
=SUMPRODUCT(--((A2:A8="Lec")), --(TIMEVALUE(MID(B2:B8,11,5)&" "&MID(B2:B8,16,2))<=TIMEVALUE("03:00 PM")), C2:C8)
The problem is that some of the session times may be blank, which renders a "#VALUE!" error. As best I can tell this is because TIMEVALUE is unable to accept an empty cell as input, so whenever that occurs it breaks the whole thing. I therefore need in this case for the formula to ignore the row and not progress to the various other evaluations.
I have attempted to protect the TIMEVALUE content behind various conditional statements, e.g. only considering that row if the time session length is correct (length=17). I have not been able to do this successfully, however. Nor have my internet searches found a similar-enough situation to use for help.
Because of the circumstances around this project, I am strongly interested in formula solutions before considering things like changing the overall spreadsheet format or adding dummy columns for computations. That said, I welcome any and all suggestions!
Unfortunately, using AGGREGATE as SUM does not skip errors if there is a Calculation in the formula. Similarly, IFERROR and ISERROR only work properly with Ranges/Arrays when in an Array Formula, not when in SUMPRODUCT. That's the easiest options out unless you want a calculation column.
However, all is not lost! First, we reduce your SUMPRODUCT to a single argument with * in place of ,:
=SUMPRODUCT(--(A2:A8="Lec")*--(TIMEVALUE(MID(B2:B8,11,5)&" "&MID(B2:B8,16,2))<=TIMEVALUE("03:00 PM"))*C2:C8)
Next, we change this from =SUMPRODUCT(X) to =SUM(IFERROR(X,0)):
=SUM(IFERROR(--(A2:A8="Lec")*--(TIMEVALUE(MID(B2:B8,11,5)&" "&MID(B2:B8,16,2))<=TIMEVALUE("03:00 PM"))*C2:C8),0)
Just remember to press [Ctrl]+[Shift]+[Enter] instead of just [Enter] to convert to an Array Formula - the formula will display in {Curly brackets}
I have a formula that builds a string with If statements, CONCATENATE, and text formulas.
My problem is that the formula's getting extremely larger than I ever wanted it.
My formula first looks to see if a cell if blank
=IF(I3="","",Else)
The Second part is to check if the letters "DKB" is in the H cell
=IF(ISNUMBER(SEARCH("*DKB*",$H3)),True,False)
The Third is if the duration (Cell F) has 0 hrs do not include (HH)
=IF(TEXT(F3,"HH")<>"00",CONCATENATE(TEXT(F3,"hh\h\r mm\m\i\n"),CONCATENATE(TEXT(F3,"mm\m\i\n"))
The Fourth one is if the are 0 min don't include min selection
=IF(TEXT(F3,"MM")<>"00",CONCATENATE(Text(F3,"HH:MM")),CONCATENATE(Text(F3,"HH"))
If I were to write all the ways this could get played out I would have a total of 10 IF's. I want a simple way to write for each option without having to write out each answer. I have a partial code but doesn't include the minute portion. Is there a better way to do this? as you can see me using only if statements I'm not an expert.
Here's a picture to demonstrate my sample data and sample output
If we could have a variable for the first part ie:10-17 to 9:10 PM
2nd variable for duration
3rd variable for DKB
Would this be possible
Perhaps something like this is what you're looking for:
=IF(I3="","",TEXT(A3,"mm-dd-yyyy")&" On-Site "&TEXT(E3,"hh:mm AM/PM")& "- "&TEXT(G3,"hh:mm AM/PM")&" "&TEXT(F3,"hh\h\r mm\m\i\n")&IF(COUNTIF(H3,"*DKB*"),MID(H3,4,20),""))
=IF(I3="","",TEXT(A3,"mm-dd-yyyy")&" On-Site "&TEXT(E3,"hh:mm AM/PM")&"- "&TEXT(G3,"hh:mm AM/PM")&" "&IF(COUNTIF(F3,"*:00:*"),TEXT(F3,"hh\h\r"),IF(COUNTIF(F3,"00:*:*"),TEXT(F3,"mm\m\i\n"),TEXT(F3,"hh\h\r mm\m\i\n"))&IF(COUNTIF(H3,"*DKB*"),MID(H3,4,20),""))))
This Will Make is so It won't show 00hr or 00min
I have this worksheet which lists results oldest to newest dates.
I have these three formulas..
=IFERROR(LARGE(IF([#HomeTeam]=[HomeTeam],IF("H"=[FTR],IF([Date]<[#Date],IF([#Season]=[Season],[Date],"")))),1),"NULL")
=IFERROR(LARGE(IF([#HomeTeam]=[AwayTeam],IF("A"=[FTR],IF([Date]<[#Date],IF([#Season]=[Season],[Date],"")))),1),"NULL")
=IF(AND([#[SLWD_H1]]="NULL",[#[SLWD_H2]]="NULL"),"NULL",MAX(Results[#[SLWD_H1]:[SLWD_H2]]))
Basically the first looks for the last time the home team won a game at home.
The second looks for the last time the home team won a game away from home.
And then the third gives me the latest date of the two mentioned above.
I was wondering if there was a way to combine all three into a single column instead of having to have three?
Thankyou in advance.
**EDIT
To make myself a bit clearer! What I want is to combine the above 3 into one formula which will output the result!
So it will find the date in example 1 and find the date in example 2 and then it will output the latest date.
Use the MAX formula to determine the highest date between the home and away dates.
The formula would look like this:
=MAX(Number1,Number2)
The MAX formula will ignore the NULL text values. However if both values are NULL, it will return a zero value. If formatted as a date it will show as 00/01/1900
=MAX(IFERROR(LARGE(IF([#HomeTeam]=[HomeTeam],IF("H"=[FTR],IF([Date]<[#Date],IF([#Season]=[Season],[Date],"")))),1),"NULL"),IFERROR(LARGE(IF([#HomeTeam]=[AwayTeam],IF("A"=[FTR],IF([Date]<[#Date],IF([#Season]=[Season],[Date],"")))),1),"NULL"))
If I understand correctly, would an OR("A"=[FTR],"H"=[FTR]) work? This would work like your first formula except using both "A" and "H" games.
=IFERROR(LARGE(IF([#HomeTeam]=[AwayTeam],IF(OR("A"=[FTR],"H"=[FTR]),IF([Date]<[#Date],IF([#Season]=[Season],[Date],"")))),1),"NULL")
Are these the only two values for [FTR]? If so you could just get rid of that IF statement entirely requiring either H or A:
=IFERROR(LARGE(IF([#HomeTeam]=[AwayTeam],IF([Date]<[#Date],IF([#Season]=[Season],[Date],""))),1),"NULL")