Formula how to add the two quantity from the earliest date - excel-formula

I want to look for the nearest exp date 'Cell G" and quantity 'Cell H' from the left data.
With refer to the sample screenshot,
to fine the nearest exp date: I using xlookup to return earliest date by matching with the material. Return value 04-Mar-22.
to find the nearest exp quantity: if using xlookup will only return the first quantity which is 7. But, actually there are two line with same batch D261205L and same exp date 04-Mar-22, is there any formula can get the result of adding that two quantity?

First, lookup the earliest date for the material
=XLOOKUP(F2,A2:A9,D2:D9,"")
which looks up the value F2 (in this case m2) in the range A2:A9 and returns the corresponding value from the range D2:D9. This goes into cell G2.
In cell H2, write
=SUM(INDEX(FILTER(A2:D9,(D2:D9=G2)*(A2:A9=F2),""),,3))
which filters the range A2:D9 for multiple conditions, the date and then the material. The INDEX function slices the returned array for the qty column (which is column 3 in A2:D9), and the SUM function then sums the filtered column.
Then wrap the whole thing up with IFERROR
=IFERROR(SUM(INDEX(FILTER(A2:D9,(D2:D9=G2)*(A2:A9=F2),""),,3)),"")
which returns the empty string if any of the criteria aren't present.

Related

VLOOKUP formula... is this the right formula for what I am trying to accomplish?

I want to lookup a specific date from cell E2 within a list of dates (column A) and return the corresponding value in column B from the matching date values IF column D does not equal "NA". I want the column of revised dates (RevDate column) to coincide with the specific Q measurement when the tss data was <> "NA". This will give me the specific Q value when tss was measured on a specific date.
Formulas I have tried in Excel:
=IF(D2<>"NA",VLOOKUP(E2,$A$2:$D$445196,4,FALSE),0)
=IF(VLOOKUP(E2,A$2:D$445196,2,FALSE)="NA","",)
I feel I am close.... maybe????
If you are going to have per date in A column just a single value in column D that is not NA(as per your sample), then you can use FILTER. VLOKUP will return the first match, and this is not what you want.
=FILTER($B$2:$B$445196, ($D$2:$D$445196<>"NA") * ($A$2:$A$445196=E2))
In case FILTER returns multiple rows, you would need to concatenate the result as follow:
=TEXTJOIN(",",,FILTER($B$2:$B$445196, ($D$2:$D$445196<>"NA")
* ($A$2:$A$445196=E2), "Not Found"))
Added also not found condition (if not it returns #N/A), that covers the case of 10/3/2010 for example. You can replace with an empty string as per in your second formula.

Return value in a specific column based on array formula result

I am using an array formula to find the largest value within a given month. Photo below ('Range of values') shows the values for each month, and I am selecting September as the criteria ("K5" in the formula below). Cell K5 will change based on the specific month I am looking for:
Formula:
{=MAX(IF(E8:P8=K5,E12:P21,""))}
Result:
63,490
Requirement:
I need to have a cell with the result, and a cell next to it with the corresponding 'Location', which in this case would be 6.
What would be the best formula to use in the case where you are not confined to a single column for the value lookup?
Typical Vlookup and Index/Match as I understand are limited as they require a single column to look up a value. The array is outside of that scope, but I feel I may be overthinking it, but I don't know.
if you have Excel 365 current channel you can use this formula to return both values:
=LET(data,A1:D5,
selectMonth,B7,
dataMonth,CHOOSECOLS(data,1,MATCH(selectMonth,CHOOSEROWS(data,1),0)),
TAKE(SORT(dataMonth,2,-1),2))
The basic idea is to first reduce the data range to the first column and the month that should be evaluated.
Then sort that "range" descending by the months values (= column 2 of new range) and take the first 2 rows (including header) - as this is the max value.

Excel formula to return value of cell in column A based off the relative cell value in column B

I'm working on a spreadsheet that has order number's in column A and the associated dates in column B. I can seem to get a correctly functioning formula that will find the earliest date in column B and return the associated order number from column A.
I've tried using INDEX and VLOOKUP formulas and managed to get it to return a date using =MIN(IF(B$1:B$99,A$1:A$99,"")) but when reversed it only returns the lowest order number.
=MIN(IF(B$1:B$99,A$1:A$99,""))Returns lowest date or lowest order number.
I need the order number associated with the earliest date
This should do it:
=INDEX(A1:A10,MATCH(MIN(B1:B10),B1:B10,0))
Used sample range for orders A1:A10 and dates B1:B10. Just change accordingly.

How can I select a specific cell value filtering with the nearest date (in a column) to select a specific row?

I am very new in Excel and I have to implement this pretty complex task (at least for me it is complex).
I put what I am doing here: https://drive.google.com/open?id=1sWHbyl-Y-GgSiX7JJ3bJ9_y8DUts-E0e
I will try to explain exactly what I have to do:
For each rows I have to "calculate" the value of the L column in this way.
Each cell into the L column is "calculated" using the following steps:
Considers the date into the H column of this row.
Search the nearest date in the past into the A column to select a specific row.
Take the E column value of this row and use it to populate the current L cell.
So doing a practical example, I want to populate the L3 cell, I have to do:
Considers the date into the H column of this row: so I obtain the value of the H3 row that is this date: 16/12/2017.
Then, into the whole A column I search the nearest date in the past in this column (in this case it is 15/12/2017), so I select the row number 4.
Take the value of E4 cell value (598,05 €) and write it into my L3 cell.
How can I do something like this?
Thank you
This is a simple INDEX(...,MATCH()) situation.
=INDEX(E:E,MATCH(H3,A:A,1))
This will return the value in column E such that the date in column A is the greatest date less than or equal to the value in H3.
Note: This assumes the dates in column A are sorted in ascending order.
VLOOKUP:
=VLOOKUP(H3,A:E,5,TRUE)
This requires the dates in Column A to be sorted.

Use ADDRESS function to define range in MIN

I'm a newby to this forum. I have a spreadsheet which predicts bank balance based on future events. I want to know the minimum balance in the future, to ensure I don't overspend.
I can find the minimum in the account over whole range of dates by using MIN, but this includes past dates. I want to vary the range in the MIN argument based on the TODAY function.
I can return the cell reference I need to use for today's date using =ADDRESS(MATCH(DATEVALUE(TEXT(TODAY(),"dd mmm yy")),C:C,0),COLUMN(E2),4), where Column C contains dates, and Column E the bank balance. However, I cannot then use the value of the cell in the MIN formula.
So, at present, MIN(E10-E121) works for past and future levels, but if the ADDRESS routine for todays date returns E90 in cell A1, I cannot reference A1 within the MIN function to get the range E90:E121.
I have tried INDIRECT, but this gives the value of the cell at E90.
Assuming your data is in rows 2 to 100, this will give you the smallest amount anywhere in column E where the date in column C is today or later. It's an array formula, so must be entered with Ctrl-Shift-Enter:
=MIN(IF(C2:C100>=TODAY(),E2:E100))
EDIT:
In response to your comment about how to do it using one cell in a range, this uses Match to find the last cell in column C that is less than or equal to Today() and then uses that as the Index into the first half of a range specification in column E. It requires the column be sorted, ascending, by date, and if today isn't in column C it will start with the highest row in column C with a date before today. You could fiddle with the last argument in Match - 1, 0, or -1, but if C always contains today's date this will work:
=MIN(INDEX(E2:E100,MATCH(TODAY(),C2:C100,1)):E100)
Another solution that does not involve array formulas (but with a little more involved formula):
=SUMPRODUCT(MIN((C2:C100<TODAY())*(1+MAX(E2:E100))+(E2:E100)*(C2:C100>=TODAY())))

Resources