Count consecutive instances in column - excel

I am tracking my days on duty and want excel to count the number of consecutive days on duty and post the totals next to the current date. I managed to insert a formula that does this but it counts in reverse order. In the attached image of the file note that on 6/13/2018 it shows 28 continuous days on duty. But that is counted from 7/10/2018 back. I want that 28 to show up on 7/10/2018. So that it counts from the previous days to the current day. Make sense????
What do I need to change in the formula to do this? Formula can be seen in the image.
Any suggestions would be appreciated

You need to build your formula the other way around:
If row r-1 has the same status as row r, then Counter_r should be Counter_(r-1) + 1. Otherwise, restart the counter - and Counter_r = 1
So, for example, in cell E3 the formula should be:
=IF(D3=D2, E2+1, 1)

I guess the picture helps a bit, but I would have preferred to see the data, even though this is simple enough to reproduce.
You probably want the formula:
=IF(AND(D2="On Duty",D2=D1),E1+1,1)
Starting in Cell E2 and copied down from there.

Related

Sum Multiple Rows Sharing A Common Index Value

I can't seem to find any examples for this exact Index-Match function problem on this site.
The green boxes have the value of "x". What I'd like to achieve is to find every instance of "x" in column G (this will be dragged for all columns onwards), and essentially look-up in Column D for it's hours equivalent and sum them in a one cell calculation for each week.
e.g. in this section of the spreadsheet, it will sum: 3.75 + 7.5 + 3.75 + 15 = 30 hours
I started with: =INDEX($D$3:$D$157,MATCH("x",G3:G157,0)) which returns the right answer, i.e. 3.75 hours, so I attempted to loop the function using the following:
=AGGREGATE(9,0,INDEX($D$3:$D$157,,MATCH("x",G3:G157,0)))
Though this returns an #REF! error message.
This is a link to a screenshot of the spreadsheet for reference. (I don't have the necessary reputation to post the image with the question).
Any help on this problem would be appreciated. I would prefer an in-cell function solution, as I'm not confident with VBA.
G2: =SUMIF(G$3:G$157,"x",$D$3:$D$157)
and fill right as far as required.
It would be easier if you could add an hidden column with a formula "=IF(G7="x";D7;0)" and calculate the respective hours based on the presence of "x" in column G. Then you can just simply get the total for this hidden column. It is more readable and easy to maintain.

Extend time depending on working days per week

I am trying to build dynamic time schedule with function, that will take in consideration how many days/week will be working days.
All lighter green cells are changeable, user inputs data in there. White color cell with header END is calculated. My current formula is located in Column END (it is affecting bar) and result should be:
As it is 5 working days/week bar should be until Mo 18
As it is 6 working days/week bar should be until We 13
As it is 7 working days/week bar should be until Su 10
I don't think this is much help, but as rules are requiring to post what has been tried yet, here it is:
IF(G10>6;D10+F10-1;IF(G10<=5;(D10+F10-1)+CEILING((F10/7);1)*2;(D10+F10)+CEILING((F10/7);1)
G10 = WD/W
D10 = START
E10 = END
F10 = DAYS
How it should be edited to work correct?
Assuming no holidays, you can use the following formula in E10 and copy down:
=(D10+IF(WEEKDAY(D10,2)>G10,8-WEEKDAY(D10,2),0))+F10+((ROUNDUP((F10+((WEEKDAY((D10+IF(WEEKDAY(D10,2)>G10,8-WEEKDAY(D10,2),0)),2))-1))/G10,0)-1)*(7-G10))-1
In column H I used a COUNTIF function to count the number X's in order to verify the right number of days were represented.

How to filter out long term events that fall between two dates in Excel 2010?

I'm trying to filter out events that may fall between a certain time period. These events are more than one day, so they have start dates and end dates.
I think the closest example to what I'm looking for is from this link: https://www.extendoffice.com/documents/excel/4647-excel-extract-records-between-two-dates.html. The only difference is that the data in Sheet 1 also have a start and end date that are greater than a day in difference, rather than existing for a singular day.
=IF(ROWS(A$5:A5)>$C$2,"",INDEX(Sheet1!A$2:A$22,SMALL(IF((Sheet1!$A$2:$A$22>=$A$2)*(Sheet1!$A$2:$A$22<=$B$2),ROW(Sheet1!A$2:A$22)-ROW(Sheet1!$A$2)+1),ROWS(A$5:A5))))
The issue is that currently the start dates may not coincide with the bounds of the study dates, but that the end dates of the data in Sheet 1 do fall within these bounds.
An example of what I'm hoping to do is this:
Example:
However, instead of having the date just be a single day, I'm hoping for a way to sort through data that have a start and end date.
This solution seems to work:
Assuming in Sheet1, columnA and columnB contain Start and End dates respectively.
Change the formula in C1 of Sheet2 to this, and follow the other instructions as given in your example.
=SUMPRODUCT((Sheet1!$A$2:$A$22>=A2)*(Sheet1!$A$2:$A$22<=B2)*(Sheet1!$B$2:$B$22>=A2)*(Sheet1!$B$2:$B$22<=B2))
Note: If this is not the output you expect then please share your expected input and output instead of from the sample.
Edit:
Based on your sample image I have updated the formulas. Hope this helps.
Formula for cell H2:
=SUMPRODUCT((($B$2:$B$16>=F2)*($B$2:$B$16<=G2)*($C$2:$C$16>=F2)*($C$2:$C$16<=G2))+((B2:B16<F2)*(C2:C16>=F2)*(C2:C16<=G2))+((B2:B16>=F2)*(B2:B16<=G2)*(C2:C16>G2))+((B2:B16<F2)*(C2:C16)>G2))
Formula for cell F5:
=IF(ROWS(F$5:F5)>$H$2,"",INDEX(B$2:B$16,SMALL(IF((($B$2:$B$16>=$F$2)*($B$2:$B$16<=$G$2)*($C$2:$C$16>=$F$2)*($C$2:$C$16<=$G$2))+(($B$2:$B$16<$F$2)*($C$2:$C$16>=$F$2)*($C$2:$C$16<=$G$2))+(($B$2:$B$16>=$F$2)*($B$2:$B$16<=$G$2)*($C$2:$C$16>$G$2))+(($B$2:$B$16<$F$2)*($C$2:$C$16)>$G$2),ROW(B$2:B$16)-ROW($B$2)+1),ROWS(F$5:F5))))
Don't forget to press Shift + Ctrl + Enter when using formula in F5.
And then extend to other cells.
Output:

Row a Trend Switches Up or Down

Not sure which functions or combination of possibly vlookup, index, match, or aggregate will work best for this. So far I have spent more than two weeks and can't seem to determine what works. SO, thank you greatly for the one who can figure this puzzle out.
My goal is to determine how to write a formula that will show these results. My guess is that second formula etc. will be different from the initial as it will start with the row specified from the initial formula as we are interested in knowing what row a trend begins moving up or down based on the given change value.
Based on change of value .15
Results need to be:
13 Up (initial formula)
23 Down (continuing from row 13 ???)
Etc.
Based on change of value .10
Results need to be:
13 Up (initial formula)
17 Down (continuing from row 13 ???)
19 Up (continuing from row 17 ???)
Etc.
Hopefully I am explaining this well. Thank you, thank you, thank you to the person who can figure this out.
1 277.54
2 277.50
3 277.43
4 277.47
5 277.49
6 277.50
7 277.40
8 277.39
9 277.44
10 277.42
11 277.36
12 277.28
13 277.23
14 277.50
15 277.54
16 277.55
17 277.58
18 277.56
19 277.46
20 277.57
21 277.60
22 277.67
23 277.71
24 277.67
25 277.43
26 277.35
Here is one of my many attempts. =AGGREGATE(15,6,ROW(1:26)/(($A$1-A2:A26)>=$I$1),1)+1
First row of >= to .15 difference (row 8) is not adequate
Image showing inadequate result
Because the uptrend based on a change of .15 actually started up at row 13.
Correct example
Image of what it should look like:
What it should look like image
Well finally I have an answer. You will need two more columns to do it on my way (which I think you can hide).
First step - To know when a new trend starts, put this formula in your B2 and pull down till B26
=IF(A1-A2)(A2-A3)<0,IF(A2-A3<0,"Up","Down"),"")
Now you have on B exacly when started a new trend and which trend*
EDIT: Now use this formula on B2. After, you need to pull it also to B1 to generate data, and pull down until B26). After pull to B1, don't pull down directly from B1, because there will be an error in the formula, always pull from mid rows formulas. You need to close it with ctrl+shift+enter
=IF(OR(ROW(A2)=SMALL(ROW($A$1:$A$26),1),ROW(A2)=LARGE(ROW($A$1:$A$26),1)),"tail",
IF((A1-A2)*(A2-A3)<0,
IF(ABS(A2-INDIRECT("A"&LARGE(IF(LEN($B$1:B1)>0,ROW($B$1:B1),""),1)))>$K$1,
IF(A2-INDIRECT("A"&LARGE(IF(LEN($B$1:B1)>0,ROW($B$1:B1),""),1))<0,"Up","Down"),
""),
"")
)
Second step - To know when your value jumped >= than the value you input in cell K1 (e.g 0.15), put this formula in your C2 and pull down till C26 (close it with ctrl+shift+enter, it's an array formula)
=IF(ABS(A2-A1)>=$K$1,LARGE((1(LEN($B$1:$B$26)>0))*((1*ROW($B$1:$B$26)0,IF(ABS(A2-INDIRECT("A"&LARGE(IF((1*(LEN($B$1:$B$26)>0))ROW($B$1:$B$26)>0,(ROW($B$1:$B$26)=$K$1,ROW(A2),""),"")
ANOTHER EDIT: Instead, close this formula with ctrl+shift+enter in C2 cell and pull down till the last
=IF(B2<>"",IF(INDIRECT("B"&SMALL(IFERROR(IF(LEN(B3:$B$26)>0,ROW(B3:$B$26),""),""),1))<>B2,B2,""),"")
Third step - Arrange data in a list. This is what in your image is in columns D and E. Use these formulas in the first row of any column you want, and pull down as you wish since non utilized cells will just be blank
=IFERROR(SMALL($C$1:$C$26,ROW(C1)),"")
and
=IFERROR(INDEX($C$1:$C$26,E1),"")
EDIT: now use these formulas below to have the ordered list of changes
=IFERROR(SMALL(IF(LEN($C$1:$C$26)>0,ROW($C$1:$C$26),""),ROW(A1)),"")
and
=IFERROR(INDEX(C:C, F1),"")
As I've put the first of these two formulas on F1 (and pulled down), the second is using F1 as a parameter, but you can put any column you want, just don't forget to change in the index. The first of these two formulas also need to be closed with ctrl+shift+enter, the second doesn't.
This is how my sheet looks right now (with last changes)
OBS: Italic parts are "deprecated" in this answer. Only maintaining the text for "log" purposes.
The first of these two formulas use ROW() as a scapegoat for the number of SMALL's "K" parameter, so you pull down and it will return the first, the second, third, etc, trend changer rows. The other one will pull the matching "up" or "down" information.
OBS: since my Excel is in portuguese and I translated the functions to english using some web dictionary, I may have made some mistakes such as letting semicolon as parameter separators rather than commas. If something goes wrong please let me know and I'll try to fix it.

Getting minutes between different dates in excel

I'm trying to calculate the time between the dates , at the beginning the formula
was working fine but I've noticed that it does not work when the date is different
For example , I have the following information on cell A1: 09/15/2016 10:00 AM
On Cell B2 I have: 09/16/2016 10:00 AM
The formula is just B2-A1 but instead of giving me a result of 24 hours is just giving me 0 . I believe the formula is not recognizing that these are 2 different days and is just doing 10-10
Any idea how to fix this ?
I was able to get the result 24 by setting a custom format of [h] (you will have to type it into the 'Type:' box) on cell C1 while using the formula =B1-A1
Excel Reference
'Format Cells' view
The problem with just using =B1-A1 is that if either or both of those cells is not populated then you will get weird numbers in C1. You may want to make C1 display as a blank cell unless both boxes are populated, try something like this =IF(OR(ISBLANK(A1),ISBLANK(B1)),"",B1-A1)
The reason for the weird numbers is that Excel calculates time based on a predefined decimal system that indexes time starting at like 1/1/1900 or something like that. So when manipulating or calculating time, that is something that you always have to keep in the back of your mind.
Hope this helps.
Formation the destination cell to will do but since you have date and time combined it will show as 1 calendar day difference 0 only means that 12 am after the 1 day difference, I know it does not make any sense but its Excel...
If I was you, on column A, I would add the date, and on Column B, the time.
then just work with the time, as both combined can be tricky
Don't forget to format your cells!! (right click>Format Cells>Time>3/14/12 1:30 PM)

Resources