SUMIFS in Excel with cell reference - excel

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.

Related

Excel Formula to Calculate Text within a date range

I am trying to calculate values within a specific date range. The data I want to split between each month and the values: Successful, Incomplete and Failed.
I've tried pivot tables with this data but it doesn't work for me, also lacking pivot table excel experience. Formulas I'm more comfortable with.
I am using the following statement to at least get the total number of a value I add into it;
=COUNTIF('Jan 19'!$C$2:$C$1159,"Value")
Ex. If I put into the value "Successful" I get the total number of successful records.
I am looking into having a formula that I can input a specific month/date range (Jan, Feb, etc) and a value to get a count.
Ex. =Formula ((RangeOfData, "Value") AND (RangeOfData, (FromDate, ToDate))
I expect to the get the total number of a value(s) within a specific date range. If there isn't any data then the results would be blank or 0.
I'd use the formula COUNTIFS() as #cybernetic.nomad pointed in the comments so you can put more conditions on the COUNT:
=+COUNTIFS('Jan 19'!$B$2:$B$1159,">="&F3,'Jan 19'!$B$2:$B$1159,"<"&G3,'Jan 19'!$C$2:$C$1159,H3)
In the formula above I guessed the dates are in the COLUMN B, if not, you need to change it in the formula above.
To do that we should put the range we want to look at in a couple of cells where you would put the date range, in the example above:
F3 is the start date (if you want February of this year should be 1/2/2019).
G3 is the final date (if you want February of this year should be 1/3/2019).
H3 is where you can write "value", "successful" or any other string you are trying to count.

i want to find count of text for a date range as criteria 1 and criteria 2 in the array

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

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

EXCEL - SUM column if date matches TODAY()

I've tried using SUMIF to obtain my results but it doesn't work properly.
I have a row of dates (XX/XX/XXXX format) and I would like to check this row for the current date.
If the row contains the current date, then I would like to sum the total of that column and row 5-20.
For example - today is 10/13/2016. I would like to search for TODAY() in a certain row (Row 1 for example), and if TODAY() is found, then total this column from row 1 down to row 3.
--A-- --B--
10/13/2016 10/14/16
1 50 10
2 10 4
3 5 6
The result should be 65 only IF the date matches TODAY().
I've also checked on giving the column letter based on the date but with no luck.
Any tips are appeciated! Thank you.
I think you can achieve this with a simple IF and a SUM
i.e. in your example above if you want the result to appear on the bottom row you can just use:
=if(B2=today(), sum(B3:B5), "")
This will display the sum at the bottom of the column for columns where the date = today and a blank in the other columns
You need to use the OFFSET function. You can find the documentation here: https://support.office.com/en-us/article/OFFSET-function-C8DE19AE-DD79-4B9B-A14E-B4D906D11B66
In your particular example the following formula will work:
=SUM(OFFSET(D2, 1, MATCH(B2, $D$2:$F$2, FALSE) - 1, 20))
You can see the formula working below. Assuming you know what the SUM formula is doing, I will explain what the OFFSET formula is doing:
First Parameter: Says start at cell D2
Second Parameter: This is how many row up/down do you want to do. In your case you need start at row below the date so '1' it is.
Third Parameter: This is how many columns to the right do you want to
go. Well the number of columns you want to go is based upon where
your date is. So this uses the match formula to figure out how far
to the right to go.
Fourth Parameter: This is how many row do you want to include. I just picked 20 to include the 20 rows below the selected cell.
You obviously need to modify the parameters a little bit to fit your exact data shape.
So I'll give it a shot:
{=SUM(HLOOKUP(TODAY(),Table_With_Dates_and_Three_Rows_Cell_Reference,{2,3,4}))}
NB: Don't type {} but put the formula inside it and then hit Ctrl+Shift+Enter to create what is called an array formula (it does array calculations element by element then submits the aggregating function value---in this case that is sum).

In Excel 2007, how can I SUMIFS indices of multiple columns from a named range?

I am analysing library statistics relating to loans made by particular user categories. The loan data forms the named range LoansToApril2013. Excel 2007 is quite happy for me to use an index range as the sum range in a SUMIF:
=SUMIF(INDEX(LoansToApril2013,0,3),10,INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6))
Here 10 indicates a specific user category, and this sums loans made to that group from three columns. By "index range" I'm referring to the
INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6)
sum_range value.
However, if I switch to using a SUMIFS to add further criteria, Excel returns a #VALUE error if an index range is used. It will only accept a single index.
=SUMIFS(INDEX(LoansToApril2013,0,4),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL")
works fine
=SUMIFS(INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL")
returns #value, and I'm not sure why.
Interestingly,
=SUMIFS(INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,4),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL")
is also accepted and returns the same as the first one with a single index.
I haven't been able to find any documentation or comments relating to this. Does anyone know if there is an alternative structure that would allow SUMIFS to conditionally sum index values from three columns? I'd rather not use three separate formulae and add them together, though it's possible.
The sumifs formula is modelled after an array formula and comparisons in the sumifs need to be the same size, the last one mimics a single column in the LoansToApril2013 array column 4:4 is column 4.
The second to bottom one is 3 columns wide and the comparison columns are 1 column wide causing the error.
sumifs can't do that, but sumproduct can
Example:
X 1 1 1
Y 2 2 2
Z 3 3 3
starting in A1
the formula =SUMPRODUCT((A1:A3="X")*B1:D3) gives the answer 3, and altering the value X in the formula to Y or Z changes the returned value to the appropriate sum of the lines.
Note that this will not work if you have text in the area - it will return #VALUE!
If you can't avoid the text, then you need an array formula. Using the same example, the formula would be =SUM(IF(A1:A3="X",B1:D3)), and to enter it as an array formula, you need to use CTRL+SHIFT+ENTER to enter the formula - you should notice that excel puts { } around the formula. It treats any text as zero, so it will successfully add up the numbers it finds even if you have text in one of the boxes (e.g. change one of the 1's in the example to be blah and the total will be 2 - the formula will add the two remaining 1s in the line)
The two answers above and a bit of searching allowed me to find a formula that worked. I'll put it here for posterity, because questions with no final outcome are a pain for future readers.
=SUMPRODUCT( (INDEX(LoansToApril2013,0,3)=C4) * (INDEX(LoansToApril2013,0,1)="PTFBL") * INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6))
This totals up values in columns 4-6 of the LoansToApril2013 range, where the value in column 3 equals the value in C4 (a.k.a. "the cell to the left of this one with the formula") AND the value in column 1 is "PTFBL".
Despite appearances, it isn't multiplying anything by anything else. I found an explanation on this page, but basically the asterisks are adding criteria to the function. Note that criteria are enclosed in their own brackets, while the range isn't.
If you want to use names ranges you need to use INDIRECT for the Index commands.
I used that formula to check for conditions in two columns, and then SUM the results in a table which has 12 columns for the months (the column is chosen by a helper cell which is 1 to 12 [L4]).
So you can do if:
Dept (1 column name range [C6]) = Sales [D6];
Region (1 column name range [C3]) = USA [D3];
SUM figures in the 12 column monthly named range table [E7] for that 1 single month [L4] for those people/products/line item
Just copy the formula across your report page which has columns 1-12 for the months and you get a monthly summary report with 2 conditions.
=SUMPRODUCT( (INDEX(INDIRECT($C$6),0,1)=$D$6) * (INDEX(INDIRECT($C$3),0,1)=$D$3) * INDEX(INDIRECT($E7),0,L$4))

Resources