Count ifs based on multiple criteria and date - excel

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.
  

Related

Excel increment cellsand skip weekends or holidays

I had a google sheet that I am trying to translate to an excel file. The original formula is this:
=Arrayformula(if(J2:J<>"", regexreplace(J2:J, "[^A-Z]",), if( (weekday(B2:B) = 1)+(weekday(B2:B) = 7), ,countifs (weekday(B2:B), ">1", weekday(B2:B), "<7", J2:J, "", row(B2:B), "<="&row(B2:B)))))
I am looking to convert this to something in excel. Basically the idea behind this formula was that it would count down a column (A) looking at the next column (B) to see what the date was. If it was a weekend, it would skip the increment. If it was a work day, it would increment. This allowed me to automatically count down 20 work days for a sprint. Then it would look at a 2nd column (J) for any Notes in that column. If anything was in the column, it would skip that increment and put a letter in that row (column A). For example, if I put "Holiday" in column J, it would be an "H" in that row in column A. That way I could still count down to plan out 20 work days easily.
It worked fine in Google Sheets, but the translation to Excel was not as easy as I would have hoped.
You can use WEEKDAY.
For example, based on your description you could try:
=IF(OR(WEEKDAY(G2)=1, WEEKDAY(G2)=7), "",
IF(ISBLANK(H2)=FALSE, H2,
MAX(F$1:F1)+1))
EDIT as suggested by #Marti:
A much cleaner way is to use a second argument in the WEEKDAY function, and then cut down on the number of characters in the second IF.
=IF(WEEKDAY(G2, 3)>=5, "",
IF(ISBLANK(H2), MAX(F$1:F1)+1, H2))

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.

Excel returning multiple values for a date range, with a single date items summed

I have the opposite query for this question:
Excel - Lookup to return multiple values in between date range
The solution is given for the above query in the following link also:
https://www.get-digital-help.com/2009/12/13/formula-for-matching-a-date-within-a-date-range-in-excel/
But my query is that for multiple date ranges, how do I find the total bookings of a single date.
I wish to build a calendar which will allow me to work out how many booking I have for a certain day. All the bookings are for 1 or more items and I want the total items which will be there on a single day, across a date calendar range.
On the calendar on the right side, I wish to add the total items which will be staying over during that specified date.
So, in the example, on the 26th December, a total of 6 items will be there. And for 5th December there is only 1, while for 1st December there are no items.
Would like to have these numbers in the calendar on the right.
I have tried using VLOOKUP, LOOKUP, INDEX and MATCH.
Also, tried the SUMPRODUCT mentioned, but those seem to give a single range and number for that range, but not the multiple values across a date range.
https://chandoo.org/wp/range-lookup-excel/
Formulae I tried are, for the 26th December date are:
=(LOOKUP(H10,((Table1[Date From]):(Table1[Date To])),Table1[Items from]))
=SUMIF(Table1[Item],(LOOKUP(2,1/(Table1[Date From]<=H10)/(Table1[Date To]>=H10))))
=INDEX(Table1[Item from],MATCH(H10,LOOKUP(H10,Table1[[Date From]:[Date To]])))
For Dec 26th (and keeping your original structure)
=SUMIFS(Bookings[[Items]:[Items]],Bookings[[Date From]:[Date From]],"<=" &H10,Bookings[[Date To]:[Date To]],">="&H10)
Note that I used the absolute address structured reference form so you can at least fill/drag across a row, without changing the columns from the table.
If you want to make things even easier, you can replace the H10 reference with a computed reference, but at the cost of using OFFSET which is a volatile function.
=SUMIFS(Bookings[[Items]:[Items]],Bookings[[Date From]:[Date From]],"<=" &OFFSET(H$1,ROW()-2,0),Bookings[[Date To]:[Date To]],">="&OFFSET(H$1,ROW()-2,0))
You might also be able to construct a computed cell reference using the INDEX function, which would be non-volatile.
Updated answer with array formulas
Sorry for not understanding your first request.
You can use the following array formula in a "single cell"
{= SUM( IF( (E2 >=$B$2:$B$8 ) * (E2<=$C$2:$C$8) ; $A$2:$A$8 ; 0 ))}
Where column e contains the target dates, columns a, b and c contain items, from and to.
This formula is expansible and copiable to other cells where e2 will be relatively changed for each target date. This is easily adaptable to your month table. Put the formula below the first date, then expand horizontally and copy/paste to the other rows.
See picture:
Old answer
Create a separate cell with your target date. Suppose $e$1.
Create on e2 this formula: =if( and( $e$1 >= c2 ; $e$1 <= d2 ); a2; 0)
Expand it and sum at the bottom.
Sorry for my formulas in Portuguese in the image (se = if ; e = and):

excel formula, if, and, or?

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),"")

Excel (numbers) formula

this should be simple enough, but numbers (on OSX) keeps throwing an error about the ranges being different sizes.
I have a list of numbers, each with an associated date, and I want a sum of all numbers within a particular month (to give, on a separate sheet, a monthly total).
Here is what I've tried:
SUMIFS(
Sheet1::Table 1::D2:D84,
MONTH(Sheet1::Table 1::A2:A84), "=04",
YEAR(Sheet1::Table 1::A2:A84), "=2014"
)
Sorry if this is a stupid question, but I've tried fiddling with it and it just won't accept it.
Thanks in advance.
You cannot put a function inside the range:
=SUMIFS(C1:C25;Month(A1:A25);"=3")
than you need to add two (hidden?) columns with Month & year function.
After you build SUMIFS based on the new columns
=SUMIFS(C1:C25;D1:D25;"=4";E1:E25;"=2014")
sum all value from C1 to C25 if column of month (D) is equal to 4 and column of year (E) is equal to 2014.
I would suggest considering using a SUMIFS function with an upper\lower limit, and then either referencing a cell with the dates, or using their numerical value in the formula (the former is my preference, to reduce hard coded values = easily updated\reused). So something like:
=SUMIFS(D2:D84, A2:A84, ">="&E1, A2:A84, "<="&E2)
In this example:
column 'D' has the values you want to sum
column 'A' has the date values
columns 'B' and 'C' are treated as irrelevant (for the sake of this formula)
column 'E' has 2 values, in row 1, the lower limit (for this specific question, the first of April) and in row 2 the upper limit (for this specific question, the final day of April)
Then have your lower limit for dates (the first day from when you would like column 'D' to be counted) in cell E1, and your date upper limit in E2.
Easily updated for future months, so might save you some work down the line.
The next easier option would be to update it to be formatted as a table, because your formula would be slightly more legible, add in some named ranges (in this case, E1 = 'lowerlimit' and E2 = 'upperlimit) to once again make it easier to read the formula, in which case you'd end up with something like:
=SUMIFS(table[FigureToBeAccrued], table[dates], ">="&lowerLimit, table[dates], "<="&upperlimit)
Might've overcooked this answer, it's my first, so wanted to make sure I didn't skimp. Let me know if you've got any follow up questions.

Resources