Get Value of first Pair - excel

I have this file
Date | Time | Table | Checkin Time | Bill Number ..| .. |
7/1/2018 **18:03:48** **6** **18:03:48** **4332**
7/1/2018 18:11:23 **6** **18:03:48** **4332**
7/1/2018 18:23:10 **6** **18:03:48** **4332**
7/1/2018 19:24:11 8 19:24:11 4333
7/1/2018 19:56:17 8 19:24:11 4333
7/1/2018 20:31:11 *6 20:31:11 4332*
I need to calculate Checkin Time which is 1st time of table number and bill number.
For example See one customer checkin at 18:03:48 with table number 6
His Bill number is 4332 .
So for table number 6 and Bill number 4332 chekin time will be 1st time
which is 18:03:48.
So I applied the formula:
=IF(AND(E3=E2,C3=C2,A3=A2),D2,MIN(OFFSET(E3,0,-3,MATCH(0,(E3:E$35470=E3)*(C3:C$35470=C3)*(A3:A$35470=A3),0)-1,1)))
But the value changes at 6th row .
It's giving 20:31:11 as checkin time .
It should be 18:03:48 because the 6th row table number and bill number is same as 1st one.
So How do I make it possible, to calculate the checkin time as per 1st time who have same bill and table number , no matter which row .
Here is the excel file I have uploaded to Google drive.
Here is the screenshot.
Edit:- Formula by #jeeped work, But as the log is of 30 days
The data keeps repeating the other day too.
Can it be done by giving some unique date value ?

If you don't have the newer MINIFS and MAXIFS, use AGGREGATE to achieve the same result.
=AGGREGATE(15, 7, ((A$2:A$7)+(B$2:B$7))/((C$2:C$7=C2)*(E$2:E$7=E2)), 1)
Format the result any way you want; as date and time, time only, etc.

You can make use of an array formula combining INDEX+MATCH to return the earliest time value that matches your conditions first. In cell D2, enter the following:
=INDEX($B$2:$B$7,MATCH(1,($C$2:$C$7=C2)*($E$2:$E$7=E2),0))
When returning, be sure to press CONTROL+SHIFT+ENTER instead of just ENTER to make sure the formula calculates correctly.

#Jeeped's answer is spot on, here is an adjustment for the formula to work over multiple days that have the same table numbers and bill numbers:
=AGGREGATE(15, 7, ((A$2:A$13)+(B$2:B$13))/((C$2:C$13=C2)*(E$2:E$13=E2)*(A$2:A$13=A2)), 1)
All I did was add this extra conditional argument, that checks if the "Date" is the same:
*(A$2:A$13=A2)

Related

Is there a non-VBA way to calculate the average of the sum of two sets of columns?

I'm creating an excel spreadsheet to track when an item is received as well as when a response to the item having been received has been made (ie: my mail was delivered at 1:00pm (item received) but I didn't check the mail until 5:00pm (response to item having been received)).
I need to track both the date and time of the item being received and want to separate these in two separate columns. At the moment this translates to:
Column A: Date item received
Column B: Time item received
Column L: Date item was responded to having been received
Column M: Time item was responded to having been received
In essence I'm looking to run calculations on the response time between when the item is received and when it has been responded to (ie: average response time, number of responses in less than an hour, and even things like the number of responses that took between 2 and 3 hours where Bob was the person who responded).
The per-line pseudo code would look something like:
(Lr + Mr) - (Ar + Br) ' where L,M,A,B are the columns and 'r' is the row number.
An example, with the following data:
1. A B L M
2. 1/5/19 10:00 1/5/19 12:00
3. 1/5/19 21:00 1/6/19 1:00
4. 1/5/19 22:00 1/5/19 23:00
5. 1/6/19 3:00 1/6/19 4:00
The outcome for the average response time would be 2 hours (average(rows 2-5) = average(2, 4, 1, 1) = 2)
The number of items with an average response times would be as follows:
(<=1 hour) = 2
(>1 & <=2) = 2
(>2 & <=3) = 0
(>3) = 1
I don't know (or can find) a function that will perform this and then let me use it within something like a countifs() or averageifs() function.
While I could do this (fairly easily) in VBA, the practical implementation of this spreadsheet limits me to standard Excel. I suspect that sumproduct() will be fundamental to make this work, but I feel that I need something like a sumsum() function (which doesn't exist) and I'm not familiar with sumproduct() to better understand what to even look for to set something like this up.
If you are not so familiar with SUMPRODUCT() or the likes I would suggest one helper column. Like so:
You can see the formula used is:
=((C2+D2)-(A2+B2))
You can probably do all type of calculations on this helper column. Note, column is formatted hh:mm. However, if you want to look into SUMPRODUCT() you could think about these:
Formula in H2:
=SUMPRODUCT(--(ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)<=1))
Formula in H3:
=SUMPRODUCT((ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)>1)*(ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)<=2))
Formula in H4:
=SUMPRODUCT((ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)>2)*(ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)<3))
Formula in H5:
=SUMPRODUCT(--(ROUND((((A2:A5+B2:B5)-(C2:C5+D2:D5))*-24),2)>3))
The helper column is the easiest approach. It gives you the time differences that you can then easily analyse however you want. Analysis without the helper column is possible, but the approach differs depending on what type of analysis you want to do.
For the example you provided, which is counting the number of time differences grouped into ranges, you would use the FREQUENCY function:
=FREQUENCY(C2:C5+D2:D5-A2:A5-B2:B5,F2:F4)
In F2:F4 (called the "bins"), enter the upper limit of each range you want to count. The Frequency function counts up to and including the first value, then counts from there up to and including the second value, and so on. Enter the bins as times, e.g. 1:00 for 1 hour.
Note that Frequency is an array-entered and an array-returning function. This you means you need to first select the range that will contain all output values, G2:G5 in this example, then enter the function, then press CTRL+SHIFT+ENTER
Also note that Frequency returns an array that is one element larger than the number of bins specified. The extra element is the count of all values greater than the largest bin specified.

Grab minimum time in year

As an athlete I want to keep track of my progression in Excel.
I need a formula that looks for the fastest time ran in a given season. (The lowest value in E for a given year. For 2017, for example, this is 13.32, for 2018 12 and so on.
Can you help me further?
Instead of formula you can use PIVOT
Keep the Year in Report Filter and Time into Value. Then on value field setting select min as summarize value by.
So every you change the year in the Filter the min value will show up.
=AGGREGATE(15,6,E3:E6/(B3:B6=2017),1)
15 tell aggregate to sort the results in ascending order
6 tells aggregate to ignore any errors such as when you divide by 0
E3:E6 is your time range
B3:B6 is you Year as an integer.
B3:B6=2017 when true will be 1 and false will be 0 (provide it goes through a math operation like divide.
1 tells aggregate to return the 1st value in the sorted list of results

How do I write an Excel formula to compare year-to-date to prior years & also account for leap years?

I’m trying to compare a measure as of today through the same day and month for the prior 4 years (e.g. through June 6 of 2016, 2015, 2014, etc.).
For each year, I decided to count the number of days since the beginning of the year, and sum my values through that number of days for each year.
To identify whether a date should be included in the year to date comparison, I used the formula where my date is in cell A1:
=IF((A1-DATE(YEAR(A1),1,1)+1)<=(TODAY()-DATE(YEAR(TODAY()),1,1)+1),1,0)
I’m looking for a way around the issue of the extra day added to leap years. In other words, after February 28th, the day count will always be off by one in a leap year, and trying to use Februrary 29th in a non-leap year will return an error.
I’d like to adjust this formula, but I’m open to using a different function & formula if it gets me the right results.
you can check any information about February, 29th. If an error occurs, you know its no leap year. Catch that error with =IFERROR(;).
Assuming a table structure like this:
A:Date | B:Value
----------------------
01/01/2016 | 0
01/01/2015 | 1
01/01/2014 | 2
01/01/2013 | 3
01/01/2012 | 4
Formula
To - for example - calculate the average of the previous four (excluding the current) years on January 1st (today is 01/01/2016):
=SUMPRODUCT(
(MONTH(A:A)=MONTH(compare))*
(DAY(A:A)=DAY(compare))*
(YEAR(A:A)>YEAR(compare)-5)*
(YEAR(A:A)<YEAR(compare))*
(B:B)
) / (
SUMPRODUCT(
(MONTH(A:A)=MONTH(compare))*
(DAY(A:A)=DAY(compare))*
(YEAR(A:A)>YEAR(compare)-5)*
(YEAR(A:A)<YEAR(compare))*
1
)
)
Result
For the above example, the result is 2.5
Explanation
To select only those rows representing the same month and day:
(MONTH(A:A)=MONTH(compare))*(DAY(A:A)=DAY(compare))
To select only those values from the previous 4 years (excluding the current):
(YEAR(A:A)>YEAR(compare)-5)*(YEAR(A:A)<YEAR(compare))*
The actual values we are interested in:
(B:B)
Divide by 4 for the average over the last four years. This assumes there is no missing data which might be an issue. You could use another SUMPRODUCT (replace B:B with 1) to count the number of resulting rows and divide by that number to handles this case. This seems to be rather slow, but it works.
Note
For performance reason you should not use A:A (a full column) in the formula, just use the actual range you need, which will likely be much faster.

Excel 2010 Dax Onhand Quantity Vs. Last Date Qty

Ive spent the last 2 days trying to get this, and I really just need a few pointers. Im using Excel 2010 w/ Power Pivot and calculating inventories. I am trying to get the amount sold between 2 dates. I recorded the quantity on hand if the item was in stock.
Item # Day Date Qty
Black Thursday 11/6/2014 2
Blue Thursday 11/6/2014 3
Green Thursday 11/6/2014 3
Black Friday 11/7/2014 2
Green Friday 11/7/2014 2
Black Monday 11/10/2014 3
Blue Monday 11/10/2014 4
Green Monday 11/10/2014 3
Is there a way to do this in dax? I may have to go back and calculate the differences for each record in excel, but Id like to avoid that if possible.
Somethings that have made this hard for me.
1) I only record the inventory Mon-Fri. I am not sure this will always be the case so i'd like to avoid a dependency on this being only weekdays.
2) When there is none in stock, I dont have a record for that day
Ive tried, CALCULATE with dateadd and it gave me results nearly right, but it ended up filtering out some of the results. Really was odd, but almost right.
Any Help is appreciated.
Bryan, this may not totally answer your question as there are a couple of things that aren't totally clear to me but it should give you a start and I'm happy to expand my answer if you provide further info.
One 'pattern' you can use involves the TOPN function which when used with the parameter n=1 can return the earliest or latest value from a table that it sorts by dates and can be filtered to be earlier/later than dates specified.
For this example I am using a 'disconnected' date table from which the user would select the two dates required in a slicer or report filter:
=
CALCULATE (
SUM ( inventory[Qty] ),
TOPN (
1,
FILTER ( inventory, inventory[Date] <= MAX ( dates[Date] ) ),
inventory[Date],
0
)
)
In this case the TOPN returns a single row table of the latest date earlier than or equal to the latest date provided. The 1st argument in the TOPN specifies the number of rows, the second the table to use, the 3rd the column to sort on and the 4th says to sort descending.
From here it is straightforward to adapt this for a second measure that finds the value for the latest date before or equal to the earliest date selected (i.e. swap MIN for MAX in MAX(dates[Date])).
Hope this helps.
Jacob
*prettified using daxformatter.com

Calculating the average difference in days within a period

I am trying to calculate the average difference between two columns in excel. The columns contain a planned and an actual date, I would like to get the average difference but only for planned dates within the last three months.
Example:
Planned Start Date | Actual Start Date
21/09/2013 | 25/09/2013
10/07/2014 | 16/07/2014
01/06/2014 | 30/06/2014
The formula should only take line 2 & 3 (line 1 is older than 3 months), look at the difference in days for each applicable line (line 2: 6 days, line 3: 29 days) and then show the average ( 17.5 days) of all applicable lines.
Does anybody have a formula for this? Excel really isn't my strong suit...
Assume your data is in A2:B4 then try this array formula
=AVERAGE(IF(TODAY()-A2:A4<=90,B2:B4-A2:A4))
It assumes each month is 30 days (hence the 90)
Press CTRL + SHIFT + ENTER to enter the formula as an array formula
Based on your example I get a result of 17.5 days.

Resources