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.
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):
I'm trying to sum the values in sheet GLTB column D where the value in column A starts with 2.21 and the value in column E is equal to the date in the cell A1. I tried this formula:
=SUMIFS(GLTB!$D$3:$D$26522,GLTB!$A$3:$A$26522,"2.21*",GLTB!$E$3:$E$26522,GLTB!$A$1)*-1
The problems:
The date in A1 doesn't appear anywhere else on the GLTB sheet, so I should get 0 for a sum, but I don't. I get some number that doesn't correspond to anything I can find.
I can make all the values in column D where column A starts with 2.21 equal to 0 (or any other number) and it has no effect on the result of the formula.
I tried this formula based on answers to other questions:
=SUMIFS(GLTB!$D$3:$D$26522,GLTB!$A$3:$A$26522,"2.21*",GLTB!$E$3:$E$26522,GLTB!"="&$A$1)*-1
This just changes the last criterion reference. However, Excel gives me a formula error response.
Any ideas?
This should get you a little closer:
=SUMIFS(GLTB!$D$3:$D$26522,GLTB!$A$3:$A$26522,">=2/21/16",GLTB!$E$3:$E$26522,GLTB!$A$1)*-1
This assumes that column A contains date values which are formatted as string. If these values are not date values, then please give some example of what cell contents in column A.
Note: I'm not clear on why you're searching for "2.21*" so I used the >= operator. That can be changed, or we could add additional criteria to the SumIfs based on your needs.
Other things to be careful of:
Ensure that column E and cell A1 both contain the same type of data (either date formatted as string, or string data representing dates. If you have inconsistent data types, the equivalence test in your Criteria2 (GLTB!$E$3:$E$26522,GLTB!$A$1) will not return the desired results.
To start with, you should format your data as table. To do this, use "Start > Format as table". This will also give you the option of giving your table a name, e.g. data. Basically this makes performing the following steps easier.
From then on, you don't need to reference with GLTB!$A3:$A26522anymore, but can use data[ColumnA].
I'm assuming you have a column ValueA with something in there that might start with 2.21, then ValueD which you want to sum and DateE which should be equal to a certain date.
The formula you are looking for is not SUMIF, but the much better SUMPRODUCT, as this allows you to check multiple conditions.
The final formula will look like this:
=SUMPRODUCT((data[DateE]=A1)*(LEFT(data[ValueA],4)="2.21")*data[ValueD])
Now what does this do. SUMPRODUCT first builds a product and then sums that up. Let's assume the following values:
A1 = 2016-03-01
DateE = 2016-03-01
ValueA = 2.213454
ValueD = 3
The formula will then do the following:
(2016-03-01=2016-03-01) is 1
("2.21" = "2.21) is 1
3 is 3
1*1*3 = 3
Now if you change the date in A1, the value of your SUMPRODUCT cell should change accordingly.
As a starter I recommend using Tables - it's much easier to read and maintain your data: Insert-->Table.
e.g.
Here I have "Table1", with the Date column formatted as a Short Date.
Name Date Quantity
Alpha 17-Mar-16 1
Beta 15-Feb-16 2
Charlie 11-Mar-16 3
Dog 11-Feb-16 4
Echo 9-Feb-16 4
Foo 6-Jan-16 5
Then in a separate row/cell, you can input a formula to sum the quantity column where the data is from 1st Feb onwards.
Here I've used a different date format, but Excel is fine with it.
Feb Onwards Total: 14 =SUMIFS(Table1[Quantity],Table1[Date],">=01-Feb-16")
Feb Only Total: 10 =SUMIFS(Table1[Quantity],Table1[Date],">=01-Feb-16", Table1[Date],"<29-Feb-16")
Try something like this:
=SUMPRODUCT((INT(GLTB!$E$3:$E$26522)=INT(GLTB!$A$1))*(ROUNDDOWN(GLTB!$A$3:$A$26522,2)=2.21)*(GLTB!$D$3:$D$26522))
If this Returns and error, then one of two things:
your dates are not true dates but text that look like dates.
your have errors in your cells in some of the columns.