excel formula, if, and, or? - excel

I am making an Excel form to use in housing. I want to be able to enter a date in one cell (tenancy end date) and calculate the number of days empty in the next cell (void days). I then have another column with date re-let.
I have managed to get it so that the void days column will stop calculating when a date is entered in the re-let column. Every week, I have to report on the number of void days for all the properties - this will be easy if I have a tenancy end date on each line, however, I don't. This means that when I copy the formula =IF(ISBLANK(J6),TODAY()-H6) onto the next line, excel inputs 42995 - not good when I want to add up that column.
I found a formula =IF(OR(ISBLANK(J11),ISBLANK(H11)),0,TODAY()-H11) to put a zero in the void days column, HOWEVER, I need it to calculate the number of void days still if there is a date in the tenancy ended column BUT, to stop calculating the number of void days when a date is entered in re-let date. I use excel by googling a lot, so, I am not an expert, just a good googler!

Assuming your data is layed out as above, place the following formula in B2 and copy down.
=IF(A2="","",IF(C2="",TODAY()-A2,IF(C2>=A2,C2-A2,"Re-Let While occupied")))
It will calculate compared to the current date when the the cell in C
is empty
It will calculate compared to the rel-let date when there is
a value in C
It will leave a blank when the cell in column A is empty
It will toss and error message to you when the end date is larger
then the relet date.
E2 was simply:
=SUM(B:B)

Assuming the only cases are:
A2=empty & C2=empty
A2=date & C2=empty
A2=date & C2=date & C2 >= A2 (so no negative void-days can occur)
=IF(A2,IF(C2,C2,TODAY())-A2,"")
Having the same as before but C2 can be smaller than A2 and you want to count as 0 days:
=IF(A2,MAX(IF(C2,C2,TODAY())-A2,0),"")

Related

Find End & Start Date Double Vlookup Excel

I have thousands of cells of data formated with the headers of
UID, Date, Mass, Start / End, Float Days, Days from Start
I have a simple version of what the sheet looks like below:
Each new data entry is entered as a row.
The data for each UID ( unique ID) is taken on non-consistent days over the length of its float life. (ex: wood floats and I take its mass on different days until it sinks).
I want to Identify a "Float Days" by taking the Sink date and subtracting it by the first reference of the ID.
#simple:
When the row has "1" in the D column, Find the ID on that row, then find that ID when that row has "0".
Take the date from that row and subtract by sink date to give me float days
#complex:
=IF(D16="1", (vlookup(A16 & "0",$A$1:$F$999,2,0)-B16, "")
If possible, I would like to use the framework of the formula to also calculate each data-inputs date in days from its Start Date as shown below:
#simple: in row E
Take the date from current row (row 10 for example), find that ID's start date,
subtract from one another to give me days from time=0
#complex:
=B10-vlookup(A10 & "0",$A$1:$F$999,B,0)
I am confused as to whether I am typing the formula incorrectly or if there is another and easier way to do this.
Thank you!
SUMFIS is the better choice here. In cell E2 and copied down:
=IF(D2=1,B2-SUMIFS(B:B,A:A,A2,D:D,0),"")
If you want a same day start/end pair to be equal to 1 instead of 0, just add a +1 to the end of the SUMIFS.

How to filter out partial match in an Excel row?

I have an Excel sheet with dates in the rows. A given month should be used only once in a row. How can I filter out, if there are two dates in the same row from the same month?
For example I have the following array, and I would like to have as a result, that there is a match in this row (2012-03).
2012-03-04 2012-02-05 2012-04-06 2012-03-07 2012-10-08 2012-11-09 2012-12-10
I have tried to combine aggregate and match functions, but I cannot find out how to do it properly.
One of my codes, of course it gave an error:
=aggregate(9,6,(MATCH("*"&LEFT(A8,7)&"*","*"&LEFT(b8,7)&"*",0), MATCH("*"&LEFT(b8,7)&"*","*"&LEFT(c8,7)&"*",0)))
Ok, now I have tried another way, and I could get a solution, but with a code which is like a km long...I have first created a new dataset, cutting down the days by using: =""&LEFT(A8,7)&""
Then I have compared all the cells in a given row of my new dataset. Could someone help me how to shorten the exact( ) parts? The aim is to compare all.
=if((or(exact(A2, B2), exact(A2,C2),exact(A2,D2),exact(A2,E2),exact(A2,F2),exact(A2,G2),exact(A2,H2),exact(A2,I2),exact(A2,J2),exact(A2,K2),exact(A2,L2),exact(A2,M2),exact(A2,N2),exact(A2,O2),exact(A2,P2),exact(A2,Q2),exact(A2,R2),exact(B2,C2),exact(B2,D2),exact(B2,E2),exact(B2,F2),exact(B2,G2),exact(B2,H2),exact(B2,I2),exact(B2,J2),exact(B2,K2),exact(B2,L2),exact(B2,M2),exact(B2,N2),exact(B2,O2),exact(B2,P2),exact(B2,Q2),exact(B2,R2),exact(C2,D2),exact(C2,E2),exact(C2,F2),exact(C2,G2),exact(C2,H2),exact(C2,I2),exact(C2,J2),exact(C2,K2),exact(C2,K2),exact(C2,L2),exact(C2,M2),exact(C2,N2),exact(C2,O2),exact(C2,P2),exact(C2,Q2),exact(C2,R2),exact(D2,E2),exact(D2,F2),exact(D2,G2),exact(D2,H2),exact(D2,I2),exact(D2,J2),exact(D2,K2),exact(D2,L2),exact(D2,M2),exact(D2,N2),exact(D2,O2),exact(D2,P2),exact(D2,Q2),exact(D2,R2),exact(E2,F2),exact(E2,G2),exact(E2,H2),exact(E2,I2),exact(E2,J2),exact(E2,K2),exact(E2,L2),exact(E2,M2),exact(E2,N2),exact(E2,O2),exact(E2,P2),exact(E2,Q2),exact(E2,R2),exact(F2,G2),exact(F2,H2),exact(F2,I2),exact(F2,J2),exact(F2,K2),exact(F2,L2),exact(F2,M2),exact(F2,N2),exact(F2,O2),exact(F2,P2),exact(F2,Q2),exact(F2,R2),exact(G2,H2),exact(G2,I2),exact(G2,J2),exact(G2,K2),exact(G2,L2),exact(G2,M2),exact(G2,N2),exact(G2,O2),exact(G2,P2),exact(G2,Q2),exact(G2,R2),exact(H2,I2),exact(H2,J2),exact(H2,K2),exact(H2,L2),exact(H2,M2),exact(H2,N2),exact(H2,O2),exact(H2,P2),exact(H2,Q2),exact(H2,R2),exact(I2,J2),exact(I2,K2),exact(I2,L2),exact(I2,M2),exact(I2,N2),exact(I2,O2),exact(I2,P2),exact(I2,Q2),exact(I2,R2),exact(J2,K2),exact(J2,L2),exact(J2,M2),exact(J2,N2),exact(J2,O2),exact(J2,P2),exact(J2,Q2),exact(J2,R2),exact(K2,L2),exact(K2,M2),exact(K2,N2),exact(K2,O2),exact(K2,P2),exact(K2,Q2),exact(K2,R2),exact(L2,M2),exact(L2,N2),exact(L2,O2),exact(L2,P2),exact(L2,Q2),exact(L2,R2),exact(M2,N2),exact(M2,O2),exact(M2,P2),exact(M2,Q2),exact(M2,R2),exact(N2,O2),exact(N2,P2),exact(N2,Q2),exact(N2,R2),exact(O2,P2),exact(O2,Q2),exact(O2,R2),exact(P2,Q2),exact(P2,R2),exact(Q2,R2))),"same month","ok")
Thank you in advance.
I am not sure if there is a better way, but this is how I'd tackle the problem based on my Excel knowledge:
Add data of dates above in cells A1-G1
On row below date add formulas for dates: A2=DATE(A1) ..... G2=DATE(G1)
At the end of the original row of dates add the numbers 1 thru 12:
using formula cell H1=1, I1=H1+1 ..... S1=R1+1
After the months on row 2:H2=COUNTIF($A2:$G2,H1) ..... S2=COUNTIF($A2:$G2,S1)Counting frequency for each of the 12 months
T2=MAX(H2:S2)
Then select on cell T2being more than 1.
Here it is as a Google sheet (you can download it and open in Excel if you want)
Maybe this will help. Assume that the range of dates is in $A$1:$G$1. Also assume that the entries are numerical dates; if they are instead text you can handle this by using the DATEVALUE function. Then we can get the years and months of the range with:
{=YEAR($A$1:$G$1)}
{=MONTH($A$1:$G$1))
This and all other formulas must be entered as array formulas (CrtlShiftEnter).
We next convert back to a date, but use 1 for the day, so that all dates get shifted to the first day of the month (this means that any dates from the same month are shifted to the same date):
{=DATE(YEARS,MONTHS,1)}
We can produce an NxN comparison of the shifted dates by:
{=TRANSPOSE(SHIFTED_DATES)=SHIFTED_DATES}
We can count the number of True's in this array by:
{=SUM(--(ARRAY))}
If there we no dates from the same month we'd expect this to sum to N because this method compare each date to itself as well as the other dates. The causes the N elements on the main diagonal of this array to be True. If any dates are in the same month off-diagonal elements will also be True. So to detect if there are dates from the same month we make the comparison:
{=SUM(--(ARRAY)) > N}
or more generally:
{=SUM(--(ARRAY)) > COUNT($A$1:$G$1)}
Rolling all of these up into one formula:
=IF(SUM(--(TRANSPOSE(DATE(YEAR($A$1:$G$1),MONTH($A$1:$G$1),1))=DATE(YEAR($A$1:$G$1),MONTH($A$1:$G$1),1)))>COUNT(DATE(YEAR($A$1:$G$1),MONTH($A$1:$G$1),1)),"same month","ok")
If your dates are in a range other than $A$1:$G$1 then make the appropriate substitutions.
Hope that helps.

forumla automatcally filled when another cell value is added - Excel

I have: =NETWORKDAYS(N25, AJ25-1) in Column O to calculate the number of busines days since an item has gone out of the building. right now I am manually duplicating it each time a new item goes out.
But is there a way to put a formula that when Column N is filled out, it will automatically added in the formula above in Column O respective to the row?
On that note, it seems my formula is a bit wonky. It works perfectly when it gets to the day AFTER it was sent out (day 1), but if it's sent out today, it will come back with the value -1 or -2 instead of "0" indicating that today's date (AJ25) is the same as the value I entered in on Column N.
I can understand why it does that but not sure how to calculate it so it doens't count today's date but starts the day after.
It seems #Jeeped's formula met the requirement:
=if(isblank($N25), "", NETWORKDAYS(N25, MAX(N25, AJ25))-1)

Count ifs based on multiple criteria and date

I need help creating a countifs formula (maybe I need a sumifs, not sure) with multiple criterias.
I have an absentee spreadsheet where I track the following: "vacation" day (V), "sick" day (S) and "other" (O) daily on a monthly basis. I have my formula to add the monthly total count of all "V", "S" and "O" but want it to add only to "today's date."
My dates are on cell B1:AF1
The data are on cells B2:AF2, B3:AF3 and so forth
My total cell are on AG2,AG3 and so forth
So far I have the following formula:
=COUNTIF(B2:AF2,"=O")+COUNTIF(B2:AF2,"=S")+COUNTIF(B2:AF2,"=V")
I need to add the TODAY function and that is where I am having the issue.
I do not work much with the count if formulas or the today function.
Try this standard (non-array) formula,
=SUM(COUNTIFS(B2:AF2, {"S","V","O"}, B$1:AF$1, "<"&TODAY()))
Fill down as necessary. I'm not entirely sure from your narrative whether that < should be a <= or not.
In the following image, the S, V and O are counted from the left portion of the matrix (date in row 1 less than today) while the save notations on the right hal are discarded.
  

Given a date range, count # of workdays per pay period the range falls in

I have a list of roughly 6500+ rows in Excel2007. Each row represents the time that a person was on disability leave with a start date and an end date. If there is no end date, then the end date is set to 12/31/9999. A sample of some values is below:
Workers Compensation 4/7/2009 12/31/9999
Workers Compensation 5/21/2009 12/31/9999
Short Term Disability 8/27/2009 10/7/2009
Short Term Disability 6/22/2009 7/15/2009
Short Term Disability 1/21/2009 10/4/2009
Short Term Disability 4/8/2009 6/14/2009
Short Term Disability 6/19/2009 10/5/2009
Short Term Disability 8/19/2009 12/31/9999
Short Term Disability 5/30/2009 6/18/2009
Short Term Disability 7/9/2009 7/20/2009
The first date is the date they went on leave; the second date is the date they returned from leave.
I am trying to break out each row so that I can get a count of the number of days per pay period that the person was on leave. We pay bi-weekly with the first pay of 2009 covering the period between 12/14/08 and 12/27/08 and incrementing bi-weekly thereafter (pay #2 covers 12/28/08 thru 1/10/09 etc).
So, as an example, I know that the first row of data covers pay periods 200909 thru the current pay period (we are currently on pay period 200924). I also know that periods 200910 thru 200924 should have 10 days as the calculated figure (since there are 10 workdays per pay), and that the count for pay period 200909 should be 2 (since there are 2 workdays in that payperiod that overlap with when the employee was on leave.
I'd like to use a formula to evaluate this, rather than writing code. Any ideas? Thanks in advance.
Pivot table method. Enter these formula
G1:12/26/2008
G2:=G1+14
and fill down to row 28. Then
A14: Date
A15: 1/21/2009
A16: =A15+1
B14: Count
B15: {=SUM(($B$1:$B$10<=A15)*(WEEKDAY(A15)<7)*(WEEKDAY(A15)>1)*($D$1:$D$10>=A15))}
C14: Week
C15: =INDEX($G$1:$G$28,MATCH(A15+13,$G$1:$G$28))
Fill A, B, and C formulas down to row 321 to stop on 11/23/09 (or farther if you want).
Select A14:C321 and create a pivot table. Put 'Week' in row area and 'Count' in the data area.
Enter the following formulas
G1:12/26/2008
G2:=G1+14
and fill down to row 28. Then
D1:=IF(C1=DATE(9999,12,31),TODAY(),C1)
E1:=NETWORKDAYS(B1,INDEX($G$1:$G$28,MATCH(B1+13,$G$1:$G$28)))
F1:=10-NETWORKDAYS(D1+1,INDEX($G$1:$G$28,MATCH(D1+14,$G$1:$G$28)))
and fill down as necessary. Then
H1:{=SUM(($B$1:$B$10<=G1-14)*($D$1:$D$10>G1))}
I1:{=SUM(($B$1:$B$10<G1)*($B$1:$B$10>=G1-14)*($E$1:$E$10))}
J1:{=SUM(($D$1:$D$10>G1-14)*($D$1:$D$10<=G1)*($F$1:$F$10))}
K1:=SUM(H1*10,I1,J1)
Note that formulas surrounded by brackets need to be array entered - do not enter the brackets, rather commit the formula with control+shift+enter instead of just enter.
Obviously you can combine a bunch of columns for brevity if you like.
Here, I am making a couple of assumptions:
The type of leave is under column A. The start and end dates are under columns B and C.
The rows start at row 1.
You are only concerned about pay periods starting December 14, 2008.
You are not taking bank/public holidays into account (although taking them into
account is not that big a deal).
The worker's leave includes the end date.
I used several cells to solve this problem:
In cell D1: =IF(C1=DATE(9999,12,31),TODAY(),C1)
In cell E1: =B1 - MOD(B1-DATE(2008,12,14),14) - 1
In cell F1: =D1 - MOD(D1-DATE(2008,12,14),14) - 1
In cell G1: =(F1-E1)/14 - 1
In cell H1: =(NETWORKDAYS(E1,B1) + NETWORKDAYS(F1,D1) + (G1 - 2) * 10)/ G1
Cell D1 determines whether the leave is ongoing. Cell G1 counts the number of pay periods between the start and end pay period. Cell H1 contains the answer you seek.
You can copy these cells for the other rows. Also, I would consider substituting TODAY() for 12/31/9999 for column C, if that's feasible.
UPDATED
I noticed that if no end date is specified, the value for the column corresponding with the pay period today's date belongs to should be 10. Also, I didn't ensure that for the first pay period the leave falls under, I should return the number of days the person is on leave for that period. Taking the above into account, as well as the clarifications provided, I came up with the following solution.
I make the same assumptions as above except that assumption 2 is replaced with the assumption that the rows start at row 2.
I defined the following names:
FirstPayPeriod: =DATE(2008, 12,14)
PayPeriodLength: =14
MaxDaysPerPeriod: =NETWORKDAYS(FirstPayPeriod, FirstPayPeriod + PayPeriodLength)
NoEndDate: =DATE(9999, 12, 31)
I defined the following cells and copied down the desired number of rows:
Cell D2: =IF(C2 = NoEndDate, FirstPayPeriod + PayPeriodLength * ROUNDUP((TODAY() - FirstPayPeriod)/PayPeriodLength, 0) - 1, C2)
Cell E2: =NETWORKDAYS(B2,D2)
I then defined the following cells for the top row:
Cell F1: =FirstPayPeriod
Cell G1: =F1 + PayPeriodLength
I then copied cell G1 across columns for as many pay periods I would like to represent. Of course, cell F1 and each subsequent cell to the right specify the start date of the pay period that the column represents.
I finally defined the following cell and copied to as many columns to the right as there are pay periods (EXCEPT FOR THE LAST PAY PERIOD - SEE BELOW), as well as copied down to as many rows as there is data:
Cell F2: =IF(OR(G$1 <= $B2, F$1 > $D2), 0, MIN($E2, NETWORKDAYS(F$1, G$1 - 1), NETWORKDAYS($B2, G$1), NETWORKDAYS(F$1, $D2)))
For the last pay period, I did the following. Assuming that column AD holds data for the last pay period:
Cell AD2: =IF(AC$1 > $D2, 0, MIN($E2, NETWORKDAYS(AD$1, AD$1 + PayPeriodLength - 1), NETWORKDAYS(AC$1, $D2)))
I then copied down as many rows as there is data.

Resources