Microsoft Excel Array Formula with dates - excel

I need the following array for a Date type:
=IF(OR(A2:C2="Mar 12"),1,0)
Sample Data
https://docs.google.com/spreadsheet/ccc?key=0AhoDU0OTM87sdHR3RGw3NTJacEV1OEt5OWZTWTBYUFE&usp=sharing
Looking at the sample data, in Column E I want an array formula that would look into columns B to D and search for results that contain 'May 12' and display true or false (1 or 0) in column E.

I think this will meet your needs - type in D2:
=IF(SUM((MONTH(A2:C2)=5)*(YEAR(A2:C2)=2013))>0,1,0)
but press CTRL+SHIFT+ENTER instead of usual ENTER - this will define an ARRAY formula and will result in {} brackets around it (but do NOT type them manually!).
Specify month and year as you wish)

I think this is what you're looking for (noticed the date format was dd/mm/yyyy so I adjusted):
=IF(COUNTIF(A1:C1,"12/5/2013")>0,TRUE,FALSE)
Edit:
For just month and day:
=IF(SUMPRODUCT((MONTH(A1:C1)=5)*(DAY(A1:C1)=12))>0,TRUE,FALSE)
Month and year:
=IF(SUMPRODUCT((MONTH(A1:C1)=5)*(YEAR(A1:C1)=2012))>0,TRUE,FALSE)

Related

WRAPCOLS and WRAPROWS functions to change table array

In EXCEL, I would like to change the array of a two columns table (A1:A91;B1:B91) to a 13 X 7 table as follows, by removing the "Turnover" text and replacing the cells with the turnover quantity.
I would like to use some functions such as WRAPCOLS, CHOOSEROWS and TOROW
You can use this formula:
=LET(d,A1:B26,
dOnly,FILTER(d,INDEX(d,,2)<>"Turnover"),
years,UNIQUE(FILTER(INDEX(d,,1),INDEX(d,,2) = "Turnover")),
months,UNIQUE(INDEX(dOnly,,1)),
HSTACK(VSTACK({""},years),VSTACK(TRANSPOSE(months),WRAPROWS(INDEX(dOnly,,2),ROWS(months)))))
In cell D1 put the following formula:
=LET(rng, A1:B26, colA, INDEX(rng,,1), colB, INDEX(rng,,2),
values, FILTER(colB, colB<>"Turnover"),
codes, FILTER(colA, colB="Turnover"),
months, TEXT(EDATE(1, SEQUENCE(1,12,0)),"mmm"),
matrix, WRAPROWS(values, 12),
VSTACK(HSTACK("",months), HSTACK(codes, matrix))
)
and here is the output:
It is just to select conveniently the information we need from the input data to generate it in the format we want. The months since they are all the same we took: 1, i.e. 1/1/1900 and format it via TEXT as mmm. If you need the months for a given year as dates data type and format in Excel as mmmm. Then you can use one of the following options:
Use the formula: EDATE(x, SEQUENCE(1,12,0)), where x represents any date corresponding to January of a given year or use A2 if it is a date in previous formula.
Use the formula: TOROW(UNIQUE(FILTER(colA, colB<>"Turnover"))).

Excel countifs on date table column

I have a excel table, with various columns,
Date, Name, LE, and so on. In LE column values are either L or E.
Date, Name, LE
4/4/2018, Jan, L
4/3/2018, Jed, L
4/1/2018, Jan, L
3/25/2018, Jan, E
Note actual date is like 4/4/2018 but formatted so it display like 4-April-18
Now I want to count how many times L appears for a particular name in a particular month. For example in month of March, ABC has XXX L.
At this time I am adding additional column after date column which display month's number from date column. But I don't like to have additional column and finding ways to directly check month from date column.
My formula is like this:
=COUNTIFS(tblXYZ[Name],"ABC", tblXYZ[LE],"L", tblXYZ[Month],"Mar")
It work fine and give required result.
But when I try
=COUNTIFS(tblXYZ[Name],"ABC", tblXYZ[LE],"L", tblXYZ[Date],"Mar")
it don't work,
when I use MONTH() with table column it don't work and generate error
=COUNTIFS(tblXYZ[Name],"ABC", tblXYZ[LE],"L", Month(tblXYZ[Date]),3)
so I have to extract month from Date column directly in the formula but I am unable to find a way.
I am using Excel 2013.
In general the first parameter of CountIfS() is a range, and pretty much you are trying not to give a range, but an array of months, thus SUMPRODUCT() suits you way better:
COUNIFS support.office.com
This is for a single condition:
=SUMPRODUCT(--MONTH(tblXYZ[Date]=3))
This is for two conditions:
=SUMPRODUCT(--MONTH(tblXYZ[Date]=3)*(tblXYZ[LE]="L"))
The --MONTH(tblXYZ[Date]=3) is a trick, converting boolean data to 0 and 1. You can see how it works with Ribbon>Formulas>Evaluate Formulas in Excel.
Try this -
=COUNTIFS(tblXYZ[Name],"ABC", tblXYZ[LE],"L", tblXYZ[Month(Date)],"3")

SUMIFS in Excel with cell reference

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.

How to find minimum and maximum values in Column B based on a specific string in column A?

I have a list of items in Column A and have corresponding year and month values in Column B and C respectively. I am looking to find the minimum and maximum year in Column B (based on specific value in Column A), then find the corresponding month in Column C (only for max and min value) and then generate and fill in a Start and End date in Column E and F respectively.
E.g. IF #Item = Laptop THEN FIND MIN,MAX of #YEAR and THEN FIND adjacent value in #Month. Finally formulate and display a date accordingly.
Could i achieve this using a formula or is it out of scope and is better achieved using a macro?
For the Start date, in E2:
=IF(A2<>A1,DATE(AGGREGATE(15,6,$B$1:$B$1000/($A$1:$A$1000=A2),1),AGGREGATE(15,6,$C$1:$C$1000/(($A$1:$A$1000=A2)*($B$1:$B$1000 = AGGREGATE(15,6,$B$1:$B$1000/($A$1:$A$1000=A2),1))),1),1),"")
And for the end date in F2:
=IF(A2<>A1,EOMONTH(DATE(AGGREGATE(14,6,$B$1:$B$1000/($A$1:$A$1000=A2),1),AGGREGATE(14,6,$C$1:$C$1000/(($A$1:$A$1000=A2)*($B$1:$B$1000 = AGGREGATE(14,6,$B$1:$B$1000/($A$1:$A$1000=A2),1))),1),1),0),"")
Then copy down the desired rows.
The aggregate function was introduced in 2010 so it will not work in excel 2007 or earlier.
I over thought they can be simplified to:
=IF(A2<>A1,AGGREGATE(15,6,DATE($B$1:$B$1000,$C$1:$C$1000,1)/($A$1:$A$1000=A2),1),"")
And:
=IF(A2<>A1,AGGREGATE(14,6,EOMONTH(DATE($B$1:$B$1000,$C$1:$C$1000,1),0)/($A$1:$A$1000=A2),1),"")
Thanks to #Jerry for showing a more succinct method.
Here is something that I think should work for any version of Excel, and thanks to the comment from #ScottCarver you can now copy it down and it will put the dates on the first row of each Item:
Enter this in E2 as an array formula and then copy down:
=IF(A2<>A1,MIN(IF(A:A=A2,DATE(B:B,C:C,1))),"")
Enter this in F2 as an array formula and then copy down:
=IF(A2<>A1,MAX(IF(A:A=A2,DATE(B:B,C:C+1,0))),"")
Because these are array formulas you need to press control-shift-enter instead of just enter. After they are entered they will be surrounded by { } to indicate that they are array formulas.
Original Answer:
Here is something that I think should work for any version of Excel, but you can't copy it down - you have to enter one separately for every Item. If you really want them spread out so that the dates are on the row of the first occurance of the Item (like in your screenshot) then this won't really work for you.
For the start date of the Laptop Item:
=MIN(IF(A:A="Laptop",DATE(B:B,C:C,1)))
For the end date of the Laptop Item:
=MAX(IF(A:A="Laptop",DATE(B:B,C:C+1,0)))
These are array formulas so you need to press control-shift-enter instead of just enter. After they are entered they will be surrounded by { } to indicate that they are array formulas.

Using month qualification in SUMIFS statment

Here's what I'm looking for....
Trying to Sum the count of worksheet 'Results 2013' column G items
IF Cell A matches "Canada"
IF Cell E (date) is July
Having trouble with the date portion of the SUMIFS statement below.
SUMIFS('Results 2013'!$G$2:$G$510,'Results 2013'!$A2:$A$510
,"=Canada",'Results 2013'!$E2:$E510,MONTH('Results 2013'!$E2:$E510)=7)
Example value of "Results 2013"$E$480 is
I try this formula, and it provides back "January" which is obviously incorrect.
=TEXT(MONTH('Results 2013'!$E$480),"mmmm")
However, this formula, results in TRUE or 1
=IF(MONTH('Results 2013'!$E$480)=7,1,0)
The simplest solution is to add a column Month using the MONTH function to compute values, and then refer to this new column in SUMIFS.
This tests whether the date values in column E fall within the range 7/1/2013 and 7/31/2013. If your dates all fall within 2013, it will work.
SUMIFS('Results 2013'!$G$2:$G$510,'Results 2013'!$A2:$A$510,"=Canada",
'Results 2013'!$E2:$E510,">="&DATE(2013,7,1),
'Results 2013'!$E2:$E510,"<="&DATE(2013,7,31))
This array formula will work with the more general case of dates falling within any year:
=SUM(G2:G510*(A2:A510="Canada")*(MONTH(E2:E510)=7))
You could use an array formula , then you can use month on the entire column:
{SUM(if('Results 2013'!$A2:$A$510="Canada",1,0)*if(MONTH('Results 2013'!$E2:$E510)=7,'Results 2013'!$G$2:$G$510,0))}
just remember to use ctrl+shift+enter rather than the usual enter to finish the formula

Resources