I have a table of dates and a variable date range and need to find all matches for rows and columns where a date in the table lie within the range of my start/end date range.
As a (downscaled) example of my case:
Start date: 01Jan2018
End date: 30Jun2018
Table with dates:
{01Jan2018; 01Feb2018; 01Apr2018}
{17Mar2018; 05Jun2018; 16Aug2018}
{11Apr2018; 01Jul2018; }
Some fields in the table may be blank if no date has been entered yet. I believe I can make a comparison array by running the start/end dates against the date array, e.g. with
=--(array>=start_date)*(array<=end_date)
which would output
{1;1;1}
{1;1;0}
{1;0;0}
But what's the next step to get from here to a vertical list of row-column sets where row and column number is in separate cells? From the example above I would need a list like:
1 1
2 1
3 1
1 2
2 2
1 3
I have other arrays sized like the date array that I need to match the found coordinates against to look up other data using the found coordinates.
Try:
=IF(AND(A4>=$B$1,A4<=$B$2),"In","Out")
Results:
A bit of a long formula, but basically this one formula will:
Get the relevant date using index (based on the row() ) and the matrix (3x3)
Conversion to 1 & 0's based on whether it's between the dates
Return the Column / Row number if 1
For Column:
=IF(--(INDEX($A$4:$C$6,ROUNDUP((ROW()-1)/3,0),IF(MOD((ROW()-1),3)=0,3,MOD((ROW()-1),3)))>=$B$1)*(INDEX($A$4:$C$6,ROUNDUP((ROW()-1)/3,0),IF(MOD((ROW()-1),3)=0,3,MOD((ROW()-1),3)))<=$B$2)<>0,ROUNDUP((ROW()-1)/3,0),"n/a")
For Row:
=IF(--(INDEX($A$4:$C$6,ROUNDUP((ROW()-1)/3,0),IF(MOD((ROW()-1),3)=0,3,MOD((ROW()-1),3)))>=$B$1)*(INDEX($A$4:$C$6,ROUNDUP((ROW()-1)/3,0),IF(MOD((ROW()-1),3)=0,3,MOD((ROW()-1),3)))<=$B$2)<>0,IF(MOD((ROW()-1),3)=0,3,MOD((ROW()-1),3)),"n/a")
Image of the excel solution
Based on the size of you array, you need to create list of all coordinates (formulas to generate it at the end of the post). Then bring the value from this coordinate, check against your condition (column "C") and filter where TRUE (column "D").
And with formulas shown:
Result (highlighted with green):
Here are two formulas generating the list of columns and rows based on data range size:
A9: =IF(B9="end";"end";MOD(ROW(C1)-1+COLUMNS($A$1:$C$3);COLUMNS($A$1:$C$3))+1)
B9: =IF(1+INT((ROW(C1)-1)/COLUMNS($A$1:$C$3))>COLUMNS($A$1:$C$3);"end";1+INT((ROW(C1)-1)/COLUMNS($A$1:$C$3)))
Related
I have a spreadsheet (Gantt chart) with dates in a column. Refer to the table below. The "Row" column is the row number in Excel, not a real column.
Row
Depends on Row(s) (Col F)
Start (Col G)
End (Col H)
Notes
9
7/24/21
7/26/21
10
9
7/27/21
7/30/21
Starts 1 day after row 9 ends.
11
7/25/21
7/27/21
12
9,11
7/28/21
7/29/21
Starts 1 day after MAX(row 9 end, row 11 end).
How do I automatically set cells "Start10" and "Start12" to read from cell "DependsOnRows" in their row to get the max of any numbers in the "DependsOnRows" column using a formula or other method?
Currently, I'm using this formula in cells "Start10" and "Start12", which includes a manually typed "max" function:
Start10:
=WORKDAY(MAX(H9), 1, Holidays!A$2:A$99)
Start12:
=WORKDAY(MAX(H9,H11), 1, Holidays!A$2:A$99)
I want to automate the reading of the row numbers inside the max function so they are read from the "DependsOnRows" column.
I can use any format in the "DependsOnRows" column. I can use braces, brackets, commas, spaces, whatever. The list just ideally needs to be in 1 cell, not multiple.
You can use the FILTERXML function to change the string of row numbers into a dynamic array. From there, you can INDEX the position of each row along with a fixed column number (in this case 8, or column H) to get test values for the MAX function.
Something like the below works for me:
=WORKDAY(MAX(
INDEX($A$1:$I$13,
FILTERXML("<t><s>" &SUBSTITUTE($F13, ",", "</s><s>")&"</s></t>", "//s"),8)),
1, Holidays!A$2:A$99)
I have a table in Excel that looks like this:
Name QuestionID Answer
A 1 Shoes
B 1 Coats
A 2 1983
B 2 1978
I want to create a table that Looks like this:
Name 1 2
A Shoes 1983
B Coats 1978
I've tried creating a pivot table, where "Name" is the row, "QuestionID" is a column, and "Answer" is the value. But values need to be aggregated, so I wind up with something numerical, instead of just the text or numbers in "Answers." I'm not clear on how to just display just the values, and not some processed version of the values.
Any help would be really appreciated!
This is why I never use Pivot Tables...they never seem to do what I need them to do.
Assuming that you can create a unique distinct list for the Header row & Name column manually, or auto-magically (see unique distinct list)
You could just use the following formula inside the table to do a lookup:
=INDEX($C$2:$C$5,SUMPRODUCT(($A$2:$A$5=$E2)*($B$2:$B$5=F$1)*ROW($C$2:$C$5))-ROW($C$1))
Where
Source Table is in A1:C5
Result Table - Name Column is E1:E3
Headers (for Questions) are in cells F1:G1
If you break it up, it's just an INDEX table lookup
=INDEX($C$2:$C$5,SOME_ROW)
Where SOME_ROW is determined by
SUMPRODUCT(($A$2:$A$5=$E2)*($B$2:$B$5=F$1)*ROW($C$2:$C$5))
Breaking the SUMPRODUCT down, we're just creating set of lists, of 1's & 0's (or True/False) for the search criteria.
The first column to match the Name is determined by ($A$2:$A$5=$E2)
The second column to match the Question is determined by ($B$2:$B$5=F$1)
Multiplying the two lists together, when Name = A & Question =1 you get
(A,B,A,B) * (1,1,2,2)
(1,0,1,0) * (1,1,0,0) = (1,0,0,0)
The third list (that we are going to multiply the above result with) from the SUMPRODUCT, is the actual Row; it's determined by ROW($C$2:$C$5), so we get:
(1,0,0,0) * (2,3,4,5) = (2,0,0,0)
Now we SUM the PRODUCTS of the result:
2 + 0 + 0 + 0 = 2
So the actual result is in Row 2; Yes!
...but we have a problem; in the INDEX function, the the Array starts on Row 2, so if we specify the 2 for the row number, we'll actually get the value from row 3 because of the starting row offset.
This is where -ROW($C$1) comes in; to fix the row offset. It should point to a cell in the header row.
It's much easier then it looks...
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.
In sheet 1, I have a list of dates in Column A in chronological order. There are values corresponding to this list in Column B. There is another list of dates in sheet 2 and I want to add values from sheet 1 to these dates.
Sheet 1.
**Column A Column B
DATE Amount**
1. 10/01/2015 25,60,000
2. 10/02/2015 26,80,000
3. 01/03/2015 21,55,000
4. 30/03/2015 24,60,500
5. 30/04/2015 28,20,000
6. 30/06/2015 19,00,000
Sheet 2.
Column A Column B
1. 21/02/2015 21,55,000
2. 15/01/2015
3. 20/05/2015
4. 25/04/2015
For example: I need to look up 21/02/2015 in sheet 1 and column A and return the value corresponding to the next available date. So for 21/02/2015 I need the value corresponding to the next date available which is 01/03/2015 and the value is 21,55,000. If its 15/01/2015 I need the value of 10/02/2015 i.e. 26,80,000
What formula could I use for this?
You could use VLOOKUP, but it has some issues. So it is better to use INDEX and MATCH combination. In your case try this
=INDEX('Sheet 1'!$B:$B,MATCH(A1,'Sheet 1'!$A:$A,-1))
Sorry, my previous answer works only for descending order. Try this instead
=INDEX('Sheet 1'!$B:$B,MATCH(TRUE,('Sheet 1'!$A:$A-A1)=MIN(IF('Sheet 1'!$A:$A-A1>=0,'Sheet 1'!$A:$A-A1)),0))
Explanation: I hope that INDEX and MATCH are well explained in Office Support.
About the condition:
('Sheet 1'!$A:$A-A1)=MIN(IF('Sheet 1'!$A:$A-A1>=0,'Sheet 1'!$A:$A-A1))
What it means?
'Sheet 1'!$A:$A-A1
results in a difference between the value in the cell A1 and the cell in A column in Sheet 1.
MIN(IF('Sheet 1'!$A:$A-A1>=0,'Sheet 1'!$A:$A-A1))
says that if the difference is non-negative ('Sheet 1'!$A:$A-A1>=0), find the minimum of such numbers (MIN function).
And if these numbers are equal (MATCH function), then pick the corresponding number in column B (INDEX('Sheet 1'!$B:$B,...)).
Apology: In my previous answers I swapped the columns of your example. I hope it is now correct.
You can use vlookup with True rather than the widely used form with False
As ExcelEfendisi said you can use vlookup with range lookup enabled. A simple way to get the value at the next date rather than the prior one would be to push all the amount values down one row, but to avoid that it might be better to repeat the index values - like this
1 10/01/15 25,60,000 1
2 10/02/15 26,80,000 2
3 01/03/15 21,55,000 3
4 30/03/15 24,60,500 4
5 30/04/15 28,20,000 5
6 30/06/15 19,00,000 6
Then you can use two vlookups, the first one to get the index of the row with the date prior to the date you are interested in and a second one to extract the balance value for the subsequent date - not very elegant but it would work
Try this formula (enter in Sheet2 cell B2 then copy till the last record)
=INDEX(Sheet1!$B:$B,1+MATCH($A2,Sheet1!$A:$A,1),1)
As data is sorted in ascending order use MATCH with match type 1 (less than) to obtain the row above the high next item, then add 1 and the result is the high next row, use this row to get the corresponding record from the column B with formula INDEX
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))