Excel - Time Intersection - excel

I want Excel to check whether two time intervals intersects or not.
For example, I3-J3 and I5-J5 intersects.
How can I make Excel to show this intersection in another cell?

The following formula will reveal any interference for the last row. Just copy this formula into cell K3 and copy it down:
=IF(OR(AND(OR(I3>(I$2:I2)),OR(I3<(J$2:J2))),AND(OR(I3>(I$2:I2)),OR(I3<(J$2:J2)))),"interference","OK")
Note that this is an array formula which will have to be entered using Ctrl+ Shift + Enter. For more information on array formulas you might want to read the following article: https://support.office.com/en-us/article/Guidelines-and-examples-of-array-formulas-7D94A64E-3FF3-4686-9372-ECFD5CAA57C7
If you want to show interference for both rows then you'd have to expand upon I$2:I2 and J$2:J2 to include the entire list. So, this might be (for example) I$2:I$500 and J$2:J$500 respectively. Yet, you cannot include the row itself. Otherwise, you'd always get interference because the formula would check against itself. So, you'd have to generate individual formulas for each row and you cannot enter a generic formula and copy it down.
I am not sure how to show (with formulas only) the interfering entry. This is mostly due to the fact that there might be more than one interfering entry which would then have to be listed and separated by ,. I don't think that can be done with formulas only.
Note: the above solution is based on the basic principle that all dates and times in Excel are (essentially) just numbers formatted as dates or time. For more information you might want to read the following: Change date format using substitute or replace
So, the above formula is just checking if the date in column I is between any prior date in column I and column J. If the date in column I is > and prior date in column I and also < compared to the date in column J then this is an interference. The same has to be checked for the date in column K and then both have to be combined with an OR. That's the entire formula above.
Update:
Based on the comment provided by #Gordon the formula can be improved with the COUNTIFS function. Just enter the following formula into cell C2 and copy it down:
=SUM(COUNTIFS(A:A,"<"&A2,B:B,">"&A2),COUNTIFS(A:A,"<"&B2,B:B,">"&B2))
Any number greater than 0 means that there is at least one interference. With this formula it is now counting / showing multiple interferences as you can see in the following screenshot:
Note, that the improved formula does not require anymore for you to know the range of the table. Instead you can search the entire column A:A and B:B for interferences.

Related

How can I automatically formulate a column while adding values ​to another? EXCEL

I have a column formulated in excel that returns all the business days from date X to today and it is automatically filled in, and there is a column to its right in which a COUNTIF formula is applied based on this first column , but the cells are not filled automatically as it happened before, but you have to drag down to complete the formulas, and I want this to be automatic too.
The first column is fulfilled with the following formula: =WORKDAY(MIN(Data\[Fecha_Completa\]-1);SEQUENCE(NETWORKDAYS(MIN(Data\[Fecha_Completa\]-1);MAX(Data\[Fecha_Completa\]-1)))), and the second one (which doesn´t fulfill automatically): =IF(COUNTIFS(Data\[Fecha_Completa\];A2)=0;A2;""); in which it is explained that, if the date of the first column is found in the database (Data[fechacompleta]), I want excel to return me nothing, but if it isn´t found, I want excel to return me the same date. Then the problem is that the second column isn´t fulfilled automatically at the same time as the first does.
As you may appreciate in the first image, the formula exists for that value, but once more dates are included in the database (as you may see in the second picture when we come to February) formula stop working and obliges me to drag it down.
I have tried to applicate the formula to the whole column but that isn´t what we are looking for as the file would be heavier.
To base a formula on a dynamically-spilled array, use a # in your range references. Therefore using A2# instead of A2 will automatically spill the formula to the same size as the formula in A2.
=IF(COUNTIFS(Data\[Fecha_Completa\];A2#)=0;A2#;"")

Excel formula to find last non blank cell in a column starting on a certain row

So I've got a column of data that I want to count the non blank cells after a certain row.
Here's an example of what I have:
So, in this example, I would like to start counting non blank cells in column A starting on row 13 (which would be a total of 4). If you look at the formula I have entered into cell D12 I can get the value I'm looking for with this formula:
=COUNTA(A:A)-11
I could use this formula:
=COUNTA(A13:A16)
but the point is the last cell with data in it can change due to entering different amounts of data in the column.
But I'm wondering if there is a different formula I could use that would count non blank cells from a certain row down regardless of the amount of data I enter into the column from a certain row down using an open ended range, kind of like this:
=COUNTA(A13:A)
This formula doesn't work but it kind of illustrates what I tried to do that didn't work.
from my comment above:
Well, you could always get the last used row dynamically and incorporate that, not sure what your benefit is over using the last row:
=COUNTA(A13:INDEX(A:A,LOOKUP(2,1/(A:A<>""),ROW(A:A))))
This makes it somewhat "open" ended I guess. Unfortunately it isn't GS =)

How to find last number in row minus second to last number in row

I have a spreadsheet that I'm using to try and keep track of google keyword rankings, but I can't figure out how to track the last change in keyword ranking, meaning the last cell in the row MINUS the second to last cell in the row. I've included a picture on what I'm trying to accomplish. The formula would take, for example, in J3-I3 to get the last change of 4 shown in D3.
Right now I have this code:
=(LOOKUP(2,1/(3:3>0),3:3))-LOOKUP(9E+300,B3:INDEX(B3:J3,MATCH(9E+300,B3:J3)-1))
Which is fine, but I need to keep changing the cell references is. Is there any easier way to accomplish this?
You can use just INDEX(MATCH()) and refer to the full row.
=INDEX(3:3,MATCH(1E+99,3:3))-INDEX(3:3,MATCH(1E+99,3:3)-1)
If you have, say, 12 columns B="Jan" to M="Dec" with a formula in each, and you need to calculate the difference between the latest month's value and the previous month's value, the formula above does not work if any columns are blank but with formulas, or until you have a value for each of the 12 months.
If you want to calculate, say, Jun minus May when Jul to Dec are blank except for their formulas, this formula (for row 4) will do it for whatever the latest month with a numerical value is:
=INDEX(4:4,MAX(IF(ISNUMBER(B4:M4),COLUMN(B4:M4))))-OFFSET(B4,0,SUM(IF(ISNUMBER(B4:M4),1))-2,1,1)
It must be entered with Ctrl+Shift+Enter.
#ScottCraner has provided an answer with the right logic, which is to
locate the second last and last number in each row, and then perform a
simple subtraction between the two.
INDEX+MATCH is one way of solving the question, but in this case, given that all data are stored in a table, and to add the flexibility of
1) moving the table around or across worksheets;
2) entering numeric value in the same row outside of the table;
without incurring errors, I've used OFFSET+COLUMNS instead.
Please note in my example I have given a name to the table, called it Tbl_WordRk, and I have added some data (in the gray area) for testing purpose.
Basically, OFFSET works in similar logic as INDEX, with a known starting point (such as B3 in my example), it will find the value (or even a range of values) in another row or column as long as you know the relative position of the value compared to the starting point. For example, if your starting point is cell A1, the following OFFSET function will return the value in cell D8.
=OFFSET(A1,7,3) which is interpreted as 7 rows down and 3 columns to the right of cell A1
COLUMNS finds the total number of columns of a given range, which is perfect for finding a column position within a table. The following formula will return number 7 which is the total number of columns of the table in my example, but please note it is NOT the relative column position of the last column to cell B3.
=COLUMNS(Tbl_WordRk)
You need to add -1 to the above formula to find the relative column number of the last column from B3. And therefore, adding -2 will return the relative column position of the second last column from B3.
So the final formula in cell B3 in my example is
=OFFSET(B3,,(COLUMNS(Tbl_WordRk)-2))-OFFSET(B3,,(COLUMNS(Tbl_WordRk)-1))
Then you just drag it down to the last row.
Just one more advice on the conditional format of your example, I would prefer not to show a green upward arrow if there is no change in the word ranking. If you know how to edit an existing conditional formatting, here is how to set it:
Cheers :)

Expanding an Excel formula without referencing the previous cell

I am attempting to use an IF statement to check whether the sum of two cells from another Excel sheet is greater than or equal to 1.
For a sheet called Test1 with the values of interest in column C, this is what I have so far, which works fine:
=IF((Test1!C1+Test1!C2>=1),1,0)
In column B on a second sheet that I'll call Test2, I want to copy this formula down 200,000 rows. However, if the aforementioned formula is in cell B1, for the formula in B2 I would like the formula to read:
=IF((Test1!C3+Test1!C4>=1),1,0)
I want to copy the formula down the column so that the second cell reference in the formula in the first row does not become the first cell reference in the formula in the second row (eg. it would go C1+C2, then C3+C4, C5+C6, etc.).
I have tried manually entering the formula for a few rows, highlighting those, and copying them down but can't get the desired cell reference pattern. If I highlight and drag these first three formulae down another three rows, C4 and C5 are repeated and not in the correct pair.
=IF((Test1!C1+Test1!C2>=1),1,0)
=IF((Test1!C3+Test1!C4>=1),1,0)
=IF((Test1!C5+Test1!C6>=1),1,0)
=IF((Test1!C4+Test1!C5>=1),1,0)
=IF((Test1!C6+Test1!C7>=1),1,0)
=IF((Test1!C8+Test1!C9>=1),1,0)
I have tried using OFFSET() within this formula but couldn't get it to work. I am basically just wanting to add 1 to each of the cell references in the formula, as compared to the previous row (but not to actually add 1 to the value of that cell, as would happen with C1+1 for example).
Any insight would be greatly appreciated!
If you plan on copying this down 200K rows then you will want the absolute simplest formula that accomplishes the stagger. Avoid the volatile OFFSET function or be prepared to spend a lot of time waiting for random calculation cycles to complete. A volatile function will recalculate whenever anything in the workbook changes; not just when something changes that involved the formula in the cell.
=--(SUM(INDEX(Test1!C:C, (ROW(1:1)-1)*2+1), INDEX(Test1!C:C, (ROW(1:1)-1)*2+2))>=1)
The following formula should do the trick:
=(SUM(INDIRECT("C"&ROW()*2-1);INDIRECT("C"&ROW()*2))>=1)*1
And that's the version using IF:
=IF(SUM(INDIRECT("C"&ZEILE()*2-1);INDIRECT("C"&ROW()*2))>=1;1;0)
You say I am basically just wanting to add '1' to each of the cell references in the formula but appear to be incrementing by 2, so I am confused but an option might be to apply you existing formula to 400,000 rows, together with =ISODD(ROW()) in another column, then filter on that other column to select and delete those showing FALSE.
Excel's autofill won't do the 2-cell shift that you're looking for. You can use the functionality that is there.
Put =IF((Test1!C1+Test1!C2>=1),1,0) in the top cell and drag a copy to the second row (it will be =IF((Test1!C2+Test1!C3>=1),1,0) but that's okay). Now, put 'A' and 'B' in the next column. Select all 4 cells and copy them down 400k rows.
Use filter to delete rows flagged with 'B' and delete the blank rows.
(Select blank rows with [F5] click Special and select Blanks, then right-click and delete)
Here is all you need. It's fast and nonvolatile.
=--(SUM(INDEX(Test1!C:C,ROW(1:1)*2-2):INDEX(Test1!C:C,ROW(2:2)*2-2))>=1)
Copy it down as far as you like.

Excel: Calculate the frequency of a particular month in a column of date cells

I have a column with dates of events. ( let's say: A1:A100 )
Now I want to use a formula to find or display the number of events that occurred in January 2013.
Any ideas ?
What you need is an array formula, sometimes called "CSE" formulas because of the way you have to enter them:
Pick your destination cell and select it.
Then, in the formula bar, enter:
=SUM(IF((A1:A100>=DATEVALUE("1/1/2013"))*(A1:A100<=DATEVALUE("31/1/2013")),1,0))
And instead of [enter], press [ctrl]+[shift]+[enter]
I really don't understand why MS make you do the CSE thing- surely it's clear from the format that it's an array formula?
How about using Countifs to find records between a start and end date? You can either type the dates or point it to two cells containing the dates. Not sure which version of Excel you are using, but CountIfs is not supported in 2003 but beyond.
=COUNTIFS(A2:A100,">="&C2,A2:A100,"<="&C3)
or
=COUNTIFS(A2:A100,">=1/1/2013",A2:A100,"<=31/1/2013")
Use the FREQUENCY formula together with an auxiliary MONTH function:
Enter the number 1-12 in your results table (e.g. in D1:D12)
Select the the twelve adjacent cells (in the example it would be E1:E12) and enter =FREQUENCY(MONTH(A1:A1000),D1:D12) - enter the formula as array formula (i.e. press Ctrl-Shift-Enter instead of Enter)
In case you want to also separate by years, you need to modify your keys in column D and your formula to derive the key, e.g. instead of MONTH(A1:A1000) you could use MONTH(A1:A1000)&"-"&YEAR(A1:A1000) - or (if purely used in an one Locale environment TEXT(A1:A1000,"MM-YY").
A couple of ideas:
Use the SUMPRODUCT formula to summarize by month. See example: http://www.contextures.com/xlFunctions04.html#SumProduct
Use a Pivot table:
Add a column B =month(a1). Fill down.
Add a column C of all 1s.
Give A, B, C header names: Date, Month, Count.
Insert a Pivot table based on A,B,C. Now you can easily Sum by Month.
A formula (if you know exactly which month you are looking for):
Perhaps do a fill down in column B with a formula like this:
=if(and(month(a1)=1,year(a1)=2013),1,0), then sum() column B?
Use Consolidate functionality. Take a look at: http://www.techrepublic.com/blog/window-on-windows/use-consolidate-to-summarize-excel-data-without-sorting/6521

Resources