I have the following table and I'm trying to get a formula so that I can get the sum of a center's result between two dates i.e. Sum all numbers for Bunbury between dates 08-05-17 and 06-05-17 (Result: 950). I've used the following formula but it gives me #VALUE!
My formula:
=SUMIFS(INDEX(B:G,MATCH("Bunbury",$A15:$BC15,0),0),$A$16:$A$21,"<=" & $J3,$A$16:$A$21,">=" & $I3)
enter image description here
Your match should match the column, not the row in B:G.
=SUMIFS(INDEX($B$16:$G$21, 0, MATCH("Bunbury", $B$15:$G$15, 0)), $A$16:$A$21,"<="&$J3, $A$16:$A$21,">="&$I3)
'alternate
=SUMIFS(INDEX($B:$G, 0, MATCH("Bunbury", $B$15:$G$15, 0)), $A:$A,"<="&$J3, $A:$A,">="&$I3)
There's also no need to look further than column G for a match and you should start looking in column B; e.g. $B15:$G15. J3 should be the end date and I3 the start date (not evident from your sample image).
I missed one problem the first time around. INDEX cannot reference all of the rows in B:G; it can only reference the same number of rows as $A$16:$A$21 (the date comparison range). Alternately, if there is no rogue data that would skew results, the date comparison ranges could be made full column. They have to be comparable ranges.
Related
I have a table of data in excel which has Time, Name, and Result columns.
My goal is to use formulas to generate a different, new table which shows the results for each Time (column) and Name (row) combination. This will later be used to generate a heatmap (the results are real numbers).
I am doing this by using a formula on each cell of the new table. An example from cell K5 in the new table is below:
=INDEX($AE$2:$AE$999, MATCH(1, INDEX(($A5=$X$2:$X$999)*(K$4=$V$2:$V$999),0,1),0))
Where $AE$2:$AE$999 is the Result column, $A5 is a name row in the new table, $X$2:$X$999 is the Name column, K$4 is a time column in the new table, and $V$2:$V$999 is the Time column.
The problem is that my table of data has multiple entries that have identical Name and Time combinations, but differing Result values. For these combinations, I would like for the formula to return the average of all nonzero results.
I think the current formula only returns the first match it runs into. I would like for this process to be autmated as possible as the original table of data will be changed frequently.
Screenshot showing the two tables.
The new table. The formula shown in G6 returns 0. I would like for it to return the average of 3.1 and 2.6.
One note: The text of your question is different from the images. I'm going to use the columns mentioned in the text of your message rather than the columns in the images.
It looks like what you're doing is calculating an average but only under certain conditions. Since you're working with multiple conditions, you would start by looking at the formula AVERAGEIFS().
In your case, for Cell G5, You want the average if any row in column X is India (A5) and that same row in column V is 6 (G4) and that same row in column AE is not zero.
So, at its base, the formula in G5 would look like this:
= AVERAGEIFS( $AE$2:$AE$999
, $X$2:$X999, "=India"
, $V$2:$V$999, "=6"
, $AE$2:$AE$999, "<>0" )
However, you want it to be both dynamic and flexible, to do that and keep Excel from messing with things as I move cells around, I make extensive use of the ROW() AND COLUMN() functions.
I think the final might look something like this
= AVERAGEIFS( $AE$2:$AE$999
, $X$2:$X$999, "=" & INDEX( $A:$A, ROW() )
, $V$2:$V$999, "=" & INDEX( $4:$4, 1, COLUMN() )
, $AE$2:$AE$999, "<>0" )
This can be pasted as is in any of the cells from B5 the the right and down, and should give you want you want in each cell. The formula will give you an error if the combination in the axes doesn't exist in the results table. So, you should wrap the whole thing in an error function and display what you want when that happens.
For reference
INDEX( $A:$A, ROW() ) Gives you the label in column A for the row in which the formula resides. So, for any cell in Row 5, this is "India".
INDEX( $4:$4, 1, COLUMN() ) gives you the label in row 4 for the column in which the formula resides. So, for any cell in column G, this will be "6".
If you hace Excel Version 365, the Dynamic Array functions make this simple
Times formula
=TRANSPOSE(SORT(UNIQUE(FILTER(U:U,(ROW(U:U)>1)*(U:U<>"")))))
Names Formula
=SORT(UNIQUE(FILTER(W:W,(ROW(W:W)>1)*(W:W<>""))))
Table formula
=IFERROR(AVERAGEIFS(AD:AD,AD:AD,">0",U:U,C4#,W:W,B5#),"")
If you don't have 365, then the table formula can be
=IFERROR(AVERAGEIFS($AD:$AD,$AD:$AD,">0",$U:$U,C$29,$W:$W,$B30),"")
and copied to the extents of the table. Create the header row/column by any means you choose
I am trying to lookup a part number in a separate table array, the same value could be in multiple rows. The formula should find each instance of the value in the other table, move to a date column and determine which months the value exists in and which row it belongs to. The entire table B3:F15 should be automated. I have attached an image with proper explanation of what I am trying to accomplish if at all possible.
The formulas would be entered into B3:F15. These are the cells where the data will get pulled into. Each row will search for its corresponding Part Number in column A. I.e, B3 to F3 is only looking for A3 data. The rows are used to determine if a Part number in L2:P4 matches their row value in Column A and if was used in that month belonging to months B2:F2. If the Part number was used in the corresponding month then it will output the Plant # from Column I. In some cases the Part numbers in L2:P4 can exist in multiple rows, but they are unique to each column.
As an example I have manually filled in data for PN1001 and PN1021. For PN1001, this belongs to B3:F3. Each cell in B3:F3 will search the array L2:P4 and realize it is found only once and in M4, so it will look at the dates from its row, J4 and K4, and determine which months it was used in. Since it was used in Jan, Feb, and Mar, it will output the Plant # into D3, E3, F3. In the example of PN1021 it is the same but in this case PN1021 exists in L2 and L4, so it will take the date of J2,K2, and J4,K4.
Some Part numbers can be a combination of letters and numbers, some may just be numbers.
In terms of how to build the formula I am not sure what combination of Index/Match/Lookup I should be using. My theory is that each cell in B3:F15 would include a formula that be =MATCH(Lookup(columnA with L3:P4)) (but how do you get it to lookup multiple instances??) Some research lead me to use this concept to find multiple instances and point to the row #.
SMALL(IF(Lookup Range = Lookup Value, Row(Lookup Range),Row ()-# of rows below start row of Lookup Range)
Once I can find each instance, then Index the row and compare if the cell in B3 is greater than J3 and less than K3 to determine the months which should have a value entered. IFYES, then output column I from the row number.
If you have any better solutions or ideas to perform this action then please provide feedback. Thanks in advance for the support.
I think the formula below will do what you want. I created a table out of your I1:P4 data, and used structured references, as I find it easier to follow.
B3: =IFERROR(
INDEX(partsTbl,
MAX(
($A3=partsTbl)*
(B$2>DATE(YEAR(partsTbl[[Test Start Date]:[Test Start Date]]),MONTH(partsTbl[[Test Start Date]:[Test Start Date]]),0))*
(B$2<DATE(YEAR(partsTbl[[Test Finish Date]:[Test Finish Date]]),MONTH(partsTbl[[Test Finish Date]:[Test Finish Date]])+1,1))*
ROW(partsTbl)-ROW(partsTbl[#Headers])),
1),
"")
$A3=partsTbl returns a 2D array like {FALSE,FALSE,TRUE,FALSE;FALSE,FALSE, …} to find the part number in the table
Since your start/finish dates in the partsTbl are not always at the beginning/end of the month, we need to convert them to such before we compare the dates in B2:F2
(B$2>DATE(YEAR(partsTbl[[Test Start Date]:[Test Start Date]]),MONTH(partsTbl[[Test Start Date]:[Test Start Date]]),0))
And similar for the end of the month.
We now have a 2D-array of {FALSE,FALSE,TRUE,FALSE...} where the TRUE matches the part number as filtered by the dates.
ROW(partsTbl) returns a matching array of the row numbers in the table (and we subtract the row number of the Header row to determine the row within the data).
When we do our multiplication, we then get an array where the largest value will be the desired row
INDEX, referencing column 1, will then return the appropriate Plant #
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))
I have a requirement to sum all the cells in a column from a sheet called Raw Data. But only if a few conditions exist.
The value in Raw Data column B matches the value of a offset from the current cell
The Month of the date in Raw Data Column C is less than or equal to H2
The Year of the date in Raw Data Column C is less than or equal to H2
Here is the formula I have assembled thus far:
=SUMIFS('Raw Data'!$D:$D,'Raw Data'!$B:$B,OFFSET(INDIRECT(ADDRESS(ROW(), COLUMN())),0,-4),MONTH('Raw Data'!$C:$C),<=MONTH($H$2),YEAR('Raw Data'!$C:$C),<=YEAR($H$2))
It could be a simple syntax error, but I don;t think it is. I keep getting a generic "There is a problem with the formula" error.
Can I get some help?
With SUMIFS the range expects a range not an array so MONTH('Raw Data'!$C:$C) and YEAR('Raw Data'!$C:$C) will not work.
Also when the others are expecting a string so you must use quotes and concatenate the criteria: "<=" & value
In this case we want everything less than the 1st of the next month:
"<" & EOMONTH($H$2,0)+1
Use this:
=SUMIFS('Raw Data'!$D:$D,'Raw Data'!$B:$B,OFFSET(INDIRECT(ADDRESS(ROW(), COLUMN())),0,-4),'Raw Data'!$C:$C,"<" & EOMONTH($H$2,0)+1)
I have a master data spreadsheet and a summary cover. The master contains a list of names as the rows and dates as the columns. The data in the cell is sales.
On the summary, I have the names as the rows, then this week and last weeks ending date as columns. These are calculated using =TODAY() and =TODAY()-7.
I would like the cover sheet to do some kind of look up to the master data, to look up by name, then return last weeks and this weeks values. I know these two values would be different formulas.
Is there a lookup that can use the two week formulas to return values from the master data, using the name as well? I have tried VLOOKUP and HLOOKUP to no avail.
You just need an INDEX function while providing both the row_num and column_num parameters with two MATCH function's.
Note that the column headings in H1:I1 match the row headings in A4:A5. These will be used to match which row to return. Similarly, the names in G2:G3 will be matched against the names in B3:E3.
The INDEX function formula in H2 (your summary) would be,
=IFERROR(INDEX($B$4:$E$5, MATCH(H$1, $A$4:$A$5, 0), MATCH($G2, $B$3:$E$3, 0)), "")
Fill both right and down as necessary.
Alternate VLOOKUP function equivalent for H2:
=VLOOKUP(H$1, $A$3:$E$5, MATCH($G2, $A$3:$E$3, 0), FALSE)
This time MATCH is used only for the column to return. Fill both right and down.
Alternate HLOOKUP function equivalent for H2:
=IFERROR(HLOOKUP($G2, $B$3:$E$5, MATCH(H$1, $A$3:$A$5, 0), FALSE), "")
This time MATCH is used only for the row to return. Fill both right and down.
Note that I've used the IFERROR function as an error control wrapper for each of these. If the value(s) cannot be located, a zero-length string (e.g. "") is returned rather than an #N/A error.