Calculating days between two oldest dates on varying amount of date values - excel

I'm trying to calculate a number of days between two oldest days. The task would be easy, if it were only two dates, however - there could be 3 or 4 dates - I need to take the oldest and the earliest and just subtract them, however the challenge is varying amount of dates per ID.
I've got a pivot table where on the A column I have the ID and on the B column I have multiple rows of sorted dates for that ID. Example of Table (also adding a picture for reference):
Column A
Column B
ID 1
Date 1
Date 2
ID 2
Date 3
Date 4
Date 5
ID 3
Date 6
Date 7
Example: For ID 1 (in Column A) - to get the result that I need - I would do Date 2 - Date 1
Example: for ID 2 (in Column A) - to get the result that I need - I would have to do Date 5 - Date 3
Is there an easy way to do it in Excel? Or would I have to result to a programming language - putting IDs into Objects and storing all the dates into arrays and then manipulating it in arrays?
I've tried finding suitable functions in Excel and reading more about Pivot tables, but with no luck. Maybe someone can put in me on the right path.

If you are using Excel 365 you can use the following formulas.
If not, you have to replace the formula in D4 with a unique list of your IDs. And you will have to drag down the formulas for column E and F.
Using MINIFS/MAXIFS then retrieves the min/max dates of a single ID

"=(MAX(FILTER(B:B;A:A=A1)))-MIN(FILTER(B:B;A:A=A1))"
This solution works with Excel 365.
Filter function acts as a VLOOKUP function, but it can actually store multiple values and you can find Minimum and Maximum values for each ID and subtract them .

Related

Count on how many tickets are logged this month - per series

I have two columns - one with ID's in and one with the date it was created on.
Is there a way which will do a count on how many ID's were created in the current month - and will automatically reset itself when it falls into the next month.
E.g.
ID Creation Date
8.88 01/01/2019
8.89 01/01/2019
8.9 01/07/2019
1.1 01/07/2019
1.2 01/06/2019
1.3 01/05/2019
1.4 01/04/2019
5 01/07/2019
5.1 01/07/2019
5.2 01/06/2019
5.3 01/06/2019
If i use the current month (July 2019) - i would hope to see - ID which begin with 8, there was 1 created this month. ID'w which begin with 1 - 1 was created this month & ID's which begin with 5 - there were two created this month
Thank you
Assuming your data starts in A1 it would come down to:
"Is there a way which will do a count on how many ID's were created in the current month - and will automatically reset itself when it falls into the next month."
To get the total of entered ID's:
=SUMPRODUCT(--(MONTH(B2:B12)=MONTH(TODAY())))
You could also use a COUNTIFS formula like so:
=COUNTIFS(B2:B12,">="&EOMONTH(TODAY(),-1)+1,B2:B12,"<="&EOMONTH(TODAY(),0))
"Is there a way that it can be broken down into each ID. E,g, Taking the LEFT 1st number - e.g. Just reference against the 5 series numbers and returning the results."
To get the total of unique series numbers entered:
=SUM(--(FREQUENCY(IF(MONTH(B2:B12)=MONTH(TODAY()),MATCH(LEFT(A2:A12,1),LEFT(A2:A12,1),0)),ROW(A2:A12)-1)>0))
Entered as array formula through CtrlShiftEnter
If the dates are true dates then you can make a pivot table.
First we need to split the ID data on the "dot".
Insert a new column between ID and creation date.
Select the ID column and click Data -> text to columns.
Split the column on ..
The new column (B) needs to have a header. Just write whatever you want as header.
Go to insert -> pivot table
Then just drag creation date to Rows field (the months will be added automatically) then and ID to also to Rows field.
Then drag ID to the values field.
EDIT. I see now that my image shows the dates also. You can remove that from the rows field by just dragging it up again to the list.

Sum of specific number of rows for a id in excel

I am pretty new to excel formulas. I want to calculate the sum of prices for every unique id. Using SUMIF I was able to do that for every unique id but I only want to calculate the sum of a number of rows for that id.
=SumIF(A:A;C2;B:B)
Sample data is attached. Actual data set is quite large. For Example, For Id 1, I only want to calculate the sum of first 3 rows (Column price) corressponding to that id, for id 2 the sum of first 4 rows and so on.
Sample data:
This formula works for sorted and non sorted data:
=SUMIF($A$2:INDEX(A:A,AGGREGATE(15,6,ROW($A$2:$A$20)/($A$2:$A$20=C2),D2)),C2,$B$2:INDEX(B:B,AGGREGATE(15,6,ROW($A$2:$A$20)/($A$2:$A$20=C2),D2)))
Enter this as an array formula (ctrl+shift+enter):
=IFERROR(SUMPRODUCT(IF(ROW($A$2:$A$20)>SMALL(IF($A$2:$A$20=C2,ROW($A$2:$A$20),FALSE),MIN(D2,COUNTIF($A$2:$A$20,C2))),0,1),IF($A$2:$A$20=C2,1,0),$B$2:$B$20),0)

Calculate Occurrence Number - Excel

I have simple problem, but I've not be able to get an answer from searching. I require a column to calculate the number of the nth occurrence of a value. It's best explained in this picture
I require a method to calculate column B.
I'd be very grateful for any help.
Are you looking to merely provide a count of the distinct entries of column A in column B? Or merely add a formula to come up with the table in your link?
If the latter, then the formula to write in cell B2 is:
=COUNTIF(A$2:A2,A2)
then copy/paste it down column B. Note - if your data is both a Date and Time, but the cell is formatted to only display a date, you may not get the results you want. You'd need to interject a new column with a "floor" calculation to round the date/time value to a date (Excel date times are decimal, with integer part dictating the date, and remaining 0.0 -> 1.0 dictating the time of day)
If you just want to derive a table of the counts of distinct entries in column A, then a pivot table will do this for you - simple add a pivot table to cover the data in column A, then select column A into the rows category, and then also drag it into the values category, ensuring the field is set to "Count of". You should then have a table with the distinct entries in your data set in one column, and the count of their occurrences in the other column.
You can use the COUNTIF worksheet function, with a relative address.
Eg. In cell B2, enter this formula:
=COUNTIF(A$2:A2,A2)
And then fill-down.
Use the following formula to generate the required series:
=COUNTIF($A$1:A1,A1) and strech(copy) it in all the cells
This will generate result like this:
A 1 COUNTIF($A$1:A1,A1)
A 2 COUNTIF($A$1:A2,A2)
C 1 COUNTIF($A$1:A3,A3)
C 2 COUNTIF($A$1:A4,A4)
B 1 COUNTIF($A$1:A5,A5)
B 2 COUNTIF($A$1:A6,A6)
A 3 COUNTIF($A$1:A7,A7)
C 3 COUNTIF($A$1:A8,A8)
D 1 COUNTIF($A$1:A9,A9)
D 2 COUNTIF($A$1:A10,A10)
D 3 COUNTIF($A$1:A11,A11)
D 4 COUNTIF($A$1:A12,A12)

SUM values based on date in date range in array

i'm realy newbie in excel and i need to make advanced functions
I have excel (from Google Calendar) with booking system
A B C
12-01-2012 14-01-2012 8
13-01-2012 17-01-2012 11
15-01-2012 21-01-2012 3
A - start date
B - end date
C - number of guests
Now I need to SUM number of guest for all days in year and find every days where was more than 10 reservations.
For example, I need to return
12-01-2012 - 08 guests
13-01-2012 - 19 guests
14-01-2012 - 19 guests
15-01-2012 - 14 guests
May I do it without creating large excel file with all days combinations? And how?
I'm working on excel 2013.
This can be done quite simply by using the SUMIFS function. First you need to put each date in column D (set the first date you care about manually, then in D2 below, just say =D1+1 and copy down). Then to count the people for each of those days, put this in E1 and drag down:
=SUMIFS(C:C, A:A, ">="&D1, B:B,"<="&D1)
This will Sum the passengers listed in column C (must be formatted as numbers, not text - it looks like you might have some text values in there), if that row in column D (each day in the year) is within the range of Column A & Column B.
To find days larger than 10 people, simply have column F (in F1 and dragged down) say
=E1>=10
This will say TRUE if column E shows more than 10 people for that day.

Microsoft Access Query - Finding Data Based On Date

I have an excel table in which there are multiple date columns. Each date column has another column next to it that has the total number of items for that day. So, for example, the table has Date 1, then Number of Items 1, then Date 2 and Number of Items 2 and so on and so forth up until 10.
Example:
Date 1 --| Number of Items 1| Date 2-----| Number of Items 2
9/10/13 -| -------2---------| 9/11/13----|-------3---------
9/9/13 --| -------2---------| 9/10/13----|-------3---------
I need a way in Microsoft Access to design a query that can grab the total number of items for a specified date in each row. The issue is that the dates that are entered into each date column aren't going to be uniform, meaning that the first row entry for Date 1 and Date 2 might be 9/10/13 and 9/11/13 but the entry into the next row for Date 1 and Date 2 might be 9/09/13 and 9/10/13 respectively (see the example above).
The purpose of this is to be able to determine the total number of items people have entered into the table based on the date I specify. As you can see, this presents an issue because if I needed to find the number of items for 9/10/13, I would need to somehow pull in the data in the first row from the Number of Items 1 column and from row two in the Number of Items 2 column. Although the structure of the table isn't ideal for what I'm trying to accomplish, I have no control over its design.
Is this possible, and if so how can it be accomplished?
You can pull the first pair of columns in one SELECT query, then union that with a SELECT of the second pair, and so forth ...
SELECT [Date 1] As the_date, [Number of Items 1] AS number_of_items
FROM YourTable
UNION ALL
SELECT [Date 2] As the_date, [Number of Items 2] AS number_of_items
FROM YourTable
You can later use that big union query as the input for another where you do a GROUP BY date and sum the number of items for each date.

Resources