Excel formula to calculate intersected dates? - excel

I searched through internet and came up with nothing. I have two tables. one includes work dates and the other has vacation dates. I have to find the intersected dates.
Let me give an example;
Work Table
1| A | B | C | D
2|Person | Work Start Date | work finish Date |Intersected Vacations
3|Mike | 01.08.2013 | 10.08.2013 |1 (Needed to find)
4|John | 16.08.2013 | 25.10.2013 |3 (Needed to find)
Vacations Table
1|A |B |C
2|Person |Vacation Start Date |Vacation End Date
3|Mike | 05.08.2013 | 05.08.2013
4|John | 20.09.2013 | 21.09.2013
5|John | 01.10.2013 | 01.10.2013
So, I need an excel formula to calculate the vacations between the work days.

Assuming you are counting all days within the periods, including Saturdays and Sundays you can use this "array formula" as per my screenshot below:
Formula is as follows in D3:
=SUM(IF(A$8:A$10=A3,IF(C$8:C$10>=B3,IF(B$8:B$10<=C3,IF(C$8:C$10>C3,C3,C$8:C$10)-IF(B$8:B$10<B3,B3,B$8:B$10)+1))))
confirmed with CTRL+SHIFT+ENTER and copied down to D4
This may look like overkill for your small example but I'm assuming your real data is larger - this solution can be extended as required, even for multiple unsorted vacation periods

Related

Find in which columns lies the text?

Thanks for reading this!
Lets say we have 2 columns in this workbook called "Data":
| Column A | Column B |
| -------- | -------------- |
| Joshua | Noah |
| Daniel | Joshua |
In another workbook, I want the user to input some random name in a cell.
Below that cell, I want to be able to show him/her, in which column that name lies. E.g. if he types "Joshua", I want to be shown below:
||
|--|
|Column A|
|Column B|
I prefer using a formula, instead of VBA, as it would mess with my not-so-experienced end-user!
Notes: See below my attempt if you find it useful:
(1) I tried that using a nested IF + FILTER functions inside, but the IF returns only the first TRUE column, like this:
| |
|------|
| Column A |
| Column A |
Here is my actual formula, where I'm referring to split ranges in sheet "6", where I have 4 columns:
IF(NOT(ISERROR(FILTER('6'!B4#,ISNUMBER(SEARCH($F$4,'6'!B4#))))),'6'!$B$1,
IF(NOT(ISERROR(FILTER('6'!D4#,ISNUMBER(SEARCH($F$4,'6'!D4#))))),'6'!$D$1,
IF(NOT(ISERROR(FILTER('6'!F4#,ISNUMBER(SEARCH($F$4,'6'!F4#))))),'6'!$F$1,
IF(NOT(ISERROR(FILTER('6'!H4#,ISNUMBER(SEARCH($F$4,'6'!H4#))))),'6'!$H$1,""))))
You could use:
Formula in D2:
=FILTER(TRANSPOSE(A1:B1),MMULT(--(TRANSPOSE(A2:B3)=D1),SEQUENCE(ROWS(A2:B3),,,0)),"")
You can get the column numbers with this formula (original data on worksheet "10")
=AGGREGATE(15,6,1/('10'!A:D="Joshua")*COLUMN('10'!A:D),SEQUENCE(COUNTIF('10'!A:D,"Joshua")))
Although I suggest reducing the range references from full columns to something shorter to reduce calculation times.
With Office 365, you can convert the column number to the letter with this:
=LET(col,AGGREGATE(15,6,1/('10'!A:D="Joshua")*COLUMN('10'!A:D),SEQUENCE(COUNTIF('10'!A:D,"Joshua"))),
adr,ADDRESS(1,col,2),
"Column " & LEFT(adr,FIND("$",adr)-1))

How to dynamically create or populate a worksheet with multiple rows, from a date range in a single row in another table

Given an existing excel TABLE with two date columns, representing the start date and end date. I would like to expand that table into a second excel TABLE in a different worksheet, so that there is one row for each of the dates between start and end. So for each row in the source table, add one row (in the target worksheet) for each date between start and end.
SOURCE TABLE:
|------------|------------|------------|------------|
|Person |Fruit |Start |End |
|------------|------------|------------|------------|
|Bob |Apple | 01/07/2019 | 04/07/2019 |
|Anna |Orange | 03/07/2019 | 05/07/2019 |
|------------|------------|------------|------------|
TARGET TABLE:
|------------|------------|------------|
|Date |Person |Fruit |
|------------|------------|------------|
| 01/04/2019 | Bob | Apple |
| 02/04/2019 | Bob | Apple |
| 03/04/2019 | Bob | Apple |
| 04/04/2019 | Bob | Apple |
| 03/04/2019 | Anna | Orange |
| 04/04/2019 | Anna | Orange |
| 05/04/2019 | Anna | Orange |
|------------|------------|------------|
A simple solution would create (or select) the target worksheet and generate all the rows required based on the data in the source.
An advanced solution would check the target worksheet to see if the rows already exist, and delete any that are not in the range. Note - I am adding this for the excel enthusiasts that really like to nail a solution. This is actually what I require, but I can build on the simple solution myself if required.
My motivation to do this is that Excel pivots and charting work best when there is a line of data in an excel TABLE for each item being analysed, much like how you would model the solution in a database.
For example, to chart the demand for oranges over time, a good pivot chart needs a single row for each date, rather than two dates expressing the start and end of the demand period (if that makes sense). Sure, you can do it with some indexing and cruel pivoting, but the user story for this spreadsheet makes that technique impossible. It must be generated automatically.
EDIT: Just adding that I appreciate that I can achieve this by adding a column for each date into the source table, and using Transform Data to generate the dataset. However, the design of the real world source table (rather than this example) has limitations set by the user that prevent me from doing so. I do also have a working method where I copy the source table to a temporary sheet, and then run a transform on that, but the user would like me to try to avoid doing that (ho-hum!)

Excel: Average of parts of a column based on another column

Using Excel 2011 for mac, I have three columns: ID, Start date, end date and time to completion. (Date format: dd/mm/yyyy)
ID | Start | End | Time
1 | 01/01/2016 | 05/01/2016 | 4
2 | 04/01/2016 | 08/01/2016 | 4
3 | 01/02/2016 | 14/02/2016 | 13
4 | 02/02/2016 | 20/02/2016 | 18
5 | 01/03/2016 | 05/03/2016 | 4
6 | 06/03/2016 | 08/03/2016 | 2
7 | 12/03/2016 | 15/03/2016 | 3
Column D is basically the difference between column C and column B.
Now I have the total average, which is easy to calculate but I'd also like to have the averages for the different months.
And this is where my knowledge falls apart. I've tried several things but I can't seem to figure out how to calculate an average using only the cells in a column that match a certain value in another column. I could sort the tickets by date and do it manually by doing the average for only a certain range but as this list constantly changes this is definitely not a nice option.
Check out the AVERAGEIF function
AVERAGEIF(selection_range, criteria, averaging_range)
It uses the values in the selection_range to filter which values in the averaging_range will be averaged.
In your case you could say AVERAGEIF(B1:B8, "01/01/2016", D1:D8)
There are multiple ways. I would personally use an array formula, but that may be a bit advanced and overly complicated.
I suggest adding a column E "Month" - into E2 add:
=MONTH(B2)
Then copy cell E2 to E3:E8.
Now you can easily get a monthly average by applying the AVERAGEIF command:
=AVERAGEIF(E2:E8,2,D2:D8)
The second argument, 2, indicates February, but may be exchanged with any number from 1-12.

Excel SUMIF variable date range

"main" is a worksheet with a "Week ending" column in it.
"expenses" is a worksheet with expense figure in column B and specific dates in column A.
I want to sum the expenses that occur on or up to 7 days before the main Week ending date.
Following the examples here: https://www.ablebits.com/office-addins-blog/2014/11/04/excel-sumif-function-formula-examples/
I came up with this
=SUMIF(expenses!A2:expenses!A1024,main!$A$2&"<="&expenses!$A$2,expenses!B2:expenses!B1024)
But it gives me zero.
EDIT
The worksheets look like this:
Main
|A |B |C |D |E |F |
|Week Ending| | | | |Expenses |
|16/11/2014 | | | | |formula goes here = should total 100|
|23/11/2014 | | | | |formula goes here = should total 25|
Expenses
|A |B |
|Date |Value|
|10/11/2014 |5.00|
|11/11/2014 |20.00|
|12/11/2014 |15.00|
|12/11/2014 |10.00|
|10/11/2014 |50.00|
|17/11/2014 |5.00|
|18/11/2014 |20.00|
This works if I just put the week ending date in the expenses sheet:
=SUMIF(expenses!A2:expenses!A1024, main!a2, expenses!b2:expenses!b1024)
But I can't change the dates because they have to match the receipts. So I tried using AND:
=SUMIF(expenses!A2:A1024, AND("<="&main!A2, ">"&main!A2-7), expenses!A2:expenses!A1024)
Still zero.
#pnuts
I tried your SUMIFS suggestion but I still get zero.
You could also try:
=SUMPRODUCT((expenses!$A$1:$A$1024>=main!$A$2-7)*(expenses!$B$1:$B$1024))
Because I think you need two conditions (one for each end of each week) I suggest SUMIFS:
=SUMIFS(Expenses!A2:A1024,Expenses!B2:B1024,"<="&Main!C2,Expenses!B2:B1024,">"&Main!C2-7)
This might be simplified if the results are in Main (eg next to the Week ending values, assumed to be in ColumnC) by not specifying that sheet.
If obliged to resort to SUMIF you might add up to the week ending date with one part of the formula and deduct up to the previous weekending date with the other part.

MS Excel - finding the first row after a certain date

Say I have a spreadsheet with the following, and for convenience say all of this starts from cell A1.
---------------------------------------
| Date | Item | Account |
---------------------------------------
| 01/09/2011 | Testing 1 | USD |
| 03/09/2011 | Testing 2 | USD |
| 11/09/2011 | Testing 3 | USD |
| 20/10/2011 | Testing 4 | JD |
| 22/10/2011 | Testing 5 | JD |
| 25/10/2011 | Testing 6 | USD |
| 03/11/2011 | Testing 7 | USD |
| 05/11/2011 | Testing 8 | JD |
---------------------------------------
Now, I want to run a report for a month, starting on 1/10/2011 and ending on 31/10/2011. I need to find the first row on or after the starting date, and then get every subsequent row until the end date. If I can figure out how to get the row reference for the first and end dates, then I can figure out the rows in between (obviously!).
I have only been able do these sorts of matches on exact matches ie. no idea how to do 'greater/less than' matches.
How would I go about matching on both the date and the account columns?
Needless to say, this needs to be in a formula.
=match(date(2011,10,1),a2:a9,1)+1
=match(date(2011,10,31),a2:a9,1)
First formula shows row for the first record for October, second formula for the last day. Data must be sorted in ascending order.
Use the following Array Formula for finding the Row containing the earliest date, which is equal to or greater than the date mentioned in cell C1 (in your case this is 1 October).
=MATCH(MIN(IF($A$1:$A$30>=C1,1,9999)*$A$1:$A$30),$A$1:$A$30,0)
Date list is in cells A1 to A30. Change the references as required.
Data need not be sorted in ascending or descending order.
Use the following Array Formula for finding the Row containing the latest date which is equal to or less than the date mentioned in cell D1 (in your case this is 31 October). Data need not be sorted in ascending or descending order.
=MATCH(MAX(IF($A$1:$A$30<=D1,1,0)*$A$1:$A$30),$A$1:$A$30,0)
If you want the earliest and latest dates, use the following Array Formulas.
=MIN(IF($A$1:$A$30>=C1,1,9999)*$A$1:$A$30)
=MAX(IF($A$1:$A$30<=D1,1,0)*$A$1:$A$30)
All the formulas used above are Array Formulas. To enter an array formula, use Control+Shift+Enter instead of Enter.
Vijaykumar Shetye, Goa, India
I would recommend using a pivot table for this. Look at the second link on in the "Excel Templates - Pivot Table" section on this page on the Contextures site.

Resources