I'm trying to write a formula and I can get it to work in parts, but not all together. I think I might need an array formula, with which I have no experience.
The formula should pull data from worksheet "2017". I want it to sum any numbers located in column R IF the value in column F or G of that row is "Name" AND the date in column N is in the month of January.
SUMIFS() do not like the OR when looking two different ranges so you will need to use SUMPRODUCT and limit the range to only the dataset:
=SUMPRODUCT(R1:R100,((G1:G100 = "Name")+(F1:F100="Name")>0)*(MONTH(N1:N100) = 1))
as per your comments your formula should be:
=SUMPRODUCT('2017'!R1:R100,(('2017'!G1:G100 = "Allison Jones")+('2017'!F1:F100="Allison Jones")>0)*(MONTH('2017'!N1:N100) = 1))
Avoid full column references as this is an array type formula and it will slow down the calculations.
I seriously misread the Q at my first attempt. What I ought to have suggested is:
=SUMIFS(R:R,F:F,"Name",N:N,">=42736",N:N,"<42767")+SUMIFS(R:R,G:G,"Name",N:N,">=42736",N:N,"<42767")-SUMIFS(R:R,F:F,"Name",G:G,"Name",N:N,">=42736",N:N,"<42767")
Not elegant but uses just the SUMIFS function to get to the result by adding all the cases where the "F" criterion applies to all the cases where the "G" criterion applies and subtracting the cases where both "F" and "G" criteria apply.
42736 and 42767 are the serial numbers in the 1900 date system for the start of January 2017 and the start of February 2017. The 'or equals' is to allow for the possibility that column N might include times.
Related
I want to count number of values (N/D) in the array (below:table: list) for criteria 1 is date range( from date and through Date) and criteria 2 is Shift A, b acros ( as shown in below table-output). I want to fill column D/N with how many times D/N occur for a date range and shift A,B,C,D?
output
From Date Through Date Shift D/N
25-May-19 26-May-19 A ?
25-May-19 26-May-19 B ?
Table- list
Dates A B C D
25-May-19 N D - -
26-May-19 N D - -
27-May-19 - D N -
INDEX(A:E,MATCH(H7:I7,A:E,0),MATCH(J7,A:E,0))
Value -?
Part of the problem you may be having is dates. Make sure your dates are excel dates and not string/text that looks like a date. Simply changing the formatting of a cell does not make it a date, it simply tells excel how to try and display the information in a cell.
Dates in excel are stored as integers and they represent the days since 1900/1/1 with that date being day 1. One of the easiest ways to test if a cell contains a date or a string is:
=ISTEXT(A1)
or
=ISNUMBER(A1)
Where A1 is the cell with the date to be tested.
If it returns TRUE for the first formula it is a string/text. FALSE means it is a number. The opposite TRUE and FALSE results apply for the second formula.
In your formula's when you have something between quotes "", it will be interpreted as a string. SO something like "<=19/05/26" mean its looking for a string less than that, not a date less than that. For doing a date comparison, either concatenate the text comparison with with a cell containing a date to compare to "<="&B2 where B2 has the date or if you want to hard code it use something like "<="&Date(19,05,26)
In order to make the following solution work, your dates all need to be stored as a number. AKA Excel serial date format.
Based on the data being layed out as per the image below, you can use COUNTIFS, INDEX, and MATCH to get the date your are looking for. I recommend find your count of D and N separately and adding them together after for a total. However if you want it in a single cell formula solution it can be achieved as well as demonstrated by the results in column N. however the formula starts to get long and can be difficult potentially read/maintain at a later date.
The core of the solution will be the COUNTIFS functions. The format of the COUNTIFS function is as follows:
COUNTIFS(Range to count 1, Criteria 1, Range to count 2, Criteria 2,...,Range to count n, Criteria n)
Let start building your formula one criteria at a time. The first Criteria will be all dates that are greater than or equal to the from date. If you only want the dates after the from date, drop the equal sign or the criteria.
=COUNTIFS($A$2:$A$4,">="&$G2,
Note the $ to lock the cell references. This is done so that when the formula gets copied, the column or row references beside the $ does not change.
Then second criteria is similar to the first except you want to grab all the dates less than or equal to the through date. Again include/drop the equal sign to suit your needs.
=COUNTIFS($A$2:$A$4,">="&$G2,$A$2:$A$4,"<="&$H2,
The next criteria will be to get all the cells that match D or N the column header. Lets just focus on D for now. The tricky part is to define which column to look in. For now lets call the column to look in XXX which will make the formula become:
=COUNTIFS($A$2:$A$4,">="&$G2,$A$2:$A$4,"<="&$H2,XXX,J$1)
OR
=COUNTIFS($A$2:$A$4,">="&$G2,$A$2:$A$4,"<="&$H2,XXX,"="&J$1)
NOTE: both formulas are the same. When no comparison operator is provided
it is taken as "=" by default.
Now in order to define XXX, INDEX and MATCH will be your friends. An important side note about INDEX is that it does not directly return the value of a cell but instead returns a cell address which in turn pulls a cell value. The basic format of INDEX is:
INDEX(Range to look in, Range's ROW to look in, Range's COLUMN to look in)
That is for a 2 dimensional range. If your range is 1 dimensional, either just a column or just a row, then only the second argument "Range's Row..." need to be provided and it represents how far down the list to go.
What gets interesting about a 2D INDEX is that when 0 is provided for ROW to look in or the Column to look in, instead of throwing an error, it instead returns all rows or columns. THIS IS IMPORTANT because you want all rows of just 1 specific column. That mean your INDEX formula is going to start to look like:
INDEX($B$2:$E$4,0,SPECIFIC COLUMN NUMBER)
So now you need to find a specific column number. That is where MATCH will be your friend. MATCH takes the following format:
MATCH(Value to find, 1D range to look in, what type of search)
You already know you are going to try and match your shift column so that will be your look up value, and the range to look in will be your column headers. The type of search you will want in this case is an exact match which is represented by 0. That means your MATCH formula will look like:
MATCH($I2,$B$1:$E$1,0)
Now to combine the various pieces, throw the MATCH formula into your INDEX and replace the "SPECIFIC COLUMN...". Your INDEX will now look like:
INDEX($B$2:$E$4,0,MATCH($I2,$B$1:$E$1,0))
And the formula above can now replace the XXX in your COUNTIFS formula and you will get:
=COUNTIFS($A$2:$A$4,">="&$G2,$A$2:$A$4,"<="&$H2,INDEX($B$2:$E$4,0,MATCH($I2,$B$1:$E$1,0)),J$1)
Place the above formula in J2 and copy the cell down and to the right.
In L2 use one of the two formulas to get the total of D and N in the date range:
=SUM(J2:K2)
OR
=J2+K2
Now to get your formula all in one cell, look at the second formula above. You can simply go to the contents of cell J2 and copy the entire formula. Then edit cell L2 and replace the cell reference for for J2 with the copied formula. Repeat the process by copy formula in K2 and replacing the reference to K2 in L2. You will wind up with a formula that looks like:
=COUNTIFS($A$2:$A$4,">="&$G2,$A$2:$A$4,"<="&$H2,INDEX($B$2:$E$4,0,MATCH($I2,$B$1:$E$1,0)),J$1)+COUNTIFS($A$2:$A$4,">="&$G2,$A$2:$A$4,"<="&$H2,INDEX($B$2:$E$4,0,MATCH($I2,$B$1:$E$1,0)),K$1)
Much longer and harder to read which is why I recommend breaking the formula down into its parts for D and N separately.
Now as an alternate method you could use SUMPRODUCT and get into array operations. Your SUMPRODUCT formula to place in I2 and copy down and right could be:
=SUMPRODUCT(($A$2:$A$4>=$G2)*($A$2:$A$4<=$H2)*(INDEX($B$2:$E$4,0,MATCH($I2,$B$1:$E$1,0))=J$1))
Currently have an AVERAGEIFS formula where:
Col A is Arrival to Last Lab Results (POC Glu, POC INR) with the data being numbers
Col B is Activation Type in this case being "EMS (pre-hospital)"
Col C is poc_inr not needed which is either "Yes" or "No"
The formula is applied for a date range of 1 month.
The formula is pasted below:
=AVERAGEIFS(MM[Arrival to Last Lab Results (POC Glu, POC INR)], MM[Arrival Date/Time],">="&A30,MM[Arrival Date/Time],"<="&B30,MM[Activation Type],"EMS (pre-hospital)", MM[poc_inr not needed], "Yes")
Currently, the formula is only looking at cases where [poc_inr not needed] is a "Yes."I wanted a way to incorporate an OR statement where if the [poc_inr not needed] was a "Yes", then the formula would continue to take the values in Col A but if [poc_inr not needed]was a "No" the formula would instead take a look at the values in another column altogether (let's name it Col D for simplicity's sake) and provide me the average of all the numerical values taken from Col A and Col D. All the other criteria and criteria range stay as is.
I have heard that AVERAGEIFS does not allow for OR functions, so I was wondering if anyone had a solution/alternative way of approaching this?
Don't use OR, specify different criteria for each case and just add them together. You will be better off using SUMPRODUCT and named ranges/tables to make your formula easier to read:
You should be able to adjust it without many problems:
=(SUMPRODUCT((Table1[poc_inr]="Yes")*(Table1[Arrival]>=G2)*(Table1[Arrival]<=H2)*Table1[Last Lab Results])+SUMPRODUCT((Table1[poc_inr]="No")*(Table1[Arrival]>=G2)*(Table1[Arrival]<=H2)*Table1[Other result]))
/(SUMPRODUCT((Table1[poc_inr]="Yes")*(Table1[Arrival]>=G2)*(Table1[Arrival]<=H2))+SUMPRODUCT((Table1[poc_inr]="No")*(Table1[Arrival]>=G2)*(Table1[Arrival]<=H2)))
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.
InExcel 2010, I need to sum one column if another column is equal to a month and another colums is equal to "N" I have part of the answer, I just need to add the second criteria and the normal Sumifs does not seem to work with this because of the month issue.
The month is part of a full date format. eg 12 January 2014
This is what I ahve so far and it works :)
=SUM(IF(MONTH('MBR Tracker'!$AJ:$AJ)=1,'MBR Tracker'!$AO:$AO,0))
Regards
Pat J
You can use SUMPRODUCT which will work without array entry:
=SUMPRODUCT('MBR Tracker'!$AO:$AO * (MONTH('MBR Tracker'!$AJ:$AJ) = 1) * ('MBR Tracker'!$AK:$AK = "N"))
Assuming that AK is the other column which should contain N.
You can use following array formula:
=SUM(IF((MONTH('MBR Tracker'!$AJ:$AJ)=1)*('MBR Tracker'!$AK:$AK="N"),'MBR Tracker'!$AO:$AO,0))
Note, since it's array formula, you need to press CTRL+SHIFT+ENTER to evaluate it.
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