MAX date value within a range with 2 conditions - excel

To make it easy
+---+----+-------------+
| | A | B |
+---+----+-------------+
| 1 | xx | 12-05-2015 |
| 2 | xx | 15-05-2015 |
| 3 | yy | 13-05-2015 |
| 4 | yy | 16-05-2015 |
+---+----+-------------+
(today is 14-05-2015)
I need to get the MAX date value for each "A" value only if it is before today.
In case it's not, move to the 2nd biggest value. Case it does not find, empty cell.
What I've done so far:
=MAX($A$1:$A$4='xx';$B$1:$B$4<TODAY();$B$1:$B$4)
and confirm with SHIFT+CTRL+ENTER
The error I get is that it yields 13-05-2015 as max value for xx, which is obviously wrong (as if it does not take into account the $A$1:$A$4='xx'

You need to use nested if-functions. I.e. change your formula into:
{=MAX(IF($A$1:$A$4="xx", IF($B$1:$B$4<TODAY(), $B$1:$B$4)))}
And end it with Ctrl+Shift+Enter

A standard (non-array) formula alternative.
=MAX(INDEX((B:B)*(A:A="xx")*(B:B<TODAY()), , ))
      
This formula would benefits from having its cell ranges cut down from full columns to something closer to the usable data range.

If your dates are sorted ascending as shown in the example then you can use LOOKUP like this:
=LOOKUP(2,1/(A$1:A$100="xx")/(B$1:B$100<TODAY()),B$1:B$100)
Doesn't require "array entry"

Related

Using CountIfs to check if cells have dates or are empty

I have written a formula to check if a small range has a date in the cells. My data looks like this:
+----------+------------+
| Proposed | Dates Used |
+----------+------------+
| 0 | 9/23/2019 |
| 0 | 9/24/2019 |
| 0 | 9/25/2019 |
| 0 | 9/26/2019 |
| 0 | 9/27/2019 |
| 0 | 9/29/2019 |
| 0 | 9/30/2019 |
| 1 | 10/2/2019 |
| 1 | |
| 0 | |
+----------+------------+
My current formula looks like this: =COUNTIFS(Propsed_Days,0,Dates_Used,"<>0")
This returns an error. I have also tried =COUNTIFS(Propsed_Days,0, Dates_Used,"<>"), which also returns an error. (I am using defined names to cover the ranges, right now Propsed_Days covers both columns and Dates_Used covers just the date column)
Basically what I want is to get a count of dates that have the Proposed column = 0, but don't want to count when there is no date but proposed is = 0. My table above should = 7 because there are 7 dates that have a proposed = 0 the date with the proposed = 1 should be excluded and the 2 lines (one with Proposed = 0 and one with Proposed = 1) should be excluded because there are no dates in the Dates Used column.
I have tried searching for a solution and tried answers from Using COUNTIFS to count blank when cell has a formula and How do I get countifs to select all non-blank cells in Excel?, but neither questions answers have worked for me.
The named range "Proposed Days" will cause the issue since this is for both columns, you need to adjust this to only cover the first column.
Once you've done that you need to concatenate the condition like so.
=COUNTIFS(Proposed_Days,0,Dates_Used,"<>"&0)
The following formula will work ONLY IF the last two cells in your Dates_Used column is completely blank but not a blank returned by a formula.
=COUNTIFS(Propsed_Days,0,Dates_Used,"<>")
I suspect the dates in your Dates_Used column are returned by a formula so the blank cells are not really blank. If that's the case, the following SUMPRODUCT formula will do the job:
=SUMPRODUCT((Propsed_Days=0)*(LEN(Dates_Used)>0))
Cheers :)

Google Spreadsheet - Sum cell value if another cell contain one of N strings

As shown on this Google Spreadsheet I would like to SUM a list of currency values from a column only if in the row of the value I have one of the selected strings from a list.
| Tag | Value |
| : | : |
| Goo | 12$ | <= SUM value because I have Goo or Boo
| Dee | 3$ |
| Boo | 4$ | <= SUM value because I have Goo or Boo
| Yoo | 7$ |
| : | : |
| Result | 16$ |
I didn't found a way to do that, is that possible?
You can just sum two SUMIF() functions together.
=SUMIF(A:A,"Goo",B:B) + SUMIF(A:A,"Boo",B:B)
Assuming that A:A contains the words to match and B:B contains the values to sum.
To be more specific to your issue, you will actually have to modify your range so you are not getting any circular reference errors (since the cell is in the same column as your sum range)
So, if the cell that contains your formula is in row 25 (for example), then something like this should work:
=SUMIF(A1:A24,"Goo",B1:B24) + SUMIF(A1:A24,"Boo",B1:B24)
=ArrayFormula(SUMPRODUCT((A2:A5=({"Goo","Boo"}))*(B2:B5))) - SUMIF has a lot of inherent limitations, you would do well to read something about array formulas.

How to use Index to find all values greater than

I've been researching my situation quite a bit, both on this site and others, with this being the closest to my problem/solution:
Find all values greater or equal than a certain value
However, using that solution in my situation does not give me the correct results. I have a list of 83 names with penalties being given to each name. On a separate tab, I'd like to display the output of all names that have any penalty (>0).
I only have four possible penalties, so if I need to reference them in the formula (match or lookup), that would be fine also. Shortening and dummying the data, here is an example of what I have:
+----------+---------+
| Name | Penalty |
+----------+---------+
| Name 1 | 0 |
| Name 2 | 0 |
| Name 3 | 5 |
| Name 4 | 0 |
| Name 5 | 0 |
| Name 6 | 10 |
| Name 7 | 0 |
| Name 8 | 0 |
| Name 9 | 0 |
| Name 10 | 20 |
+----------+---------+
Using this formula, then CSE and drag down:
=INDEX($R$4:$R$13,SMALL(IF($S$4:$S$13>0,ROW($S$4:$S$13)),ROW(1:1)))
It gives me these results:
+---------+
| Name 6 |
| Name 9 |
| #REF! |
| #NUM! |
| #NUM! |
| #NUM! |
| #NUM! |
| #NUM! |
| #NUM! |
| #NUM! |
+---------+
I'll be taking care of the errors by using an IFERROR and making them blank, but it's still not finding the correct names of those with penalty points >0
edit: Changing the last "ROW" part gives me different answers, so I think my problem lies there somehow, but I still don't know what to do with it. That's supposed to be the "k" value of the "SMALL" function.
Any help is much appreciated. Thanks!
I prefer using MATCH() instead of SMALL():
=INDEX($R$4:$R$13,MATCH(1,($S$4:$S$13>0)*(COUNTIF($U$3:U3,$R$4:$R$13)=0),0))
It is an Array formula so use Ctrl-Shift-Enter.
Also this formula requires that it start in at least the second row as the countif needs to refer to the cell above to avoid a circular reference.
If you really want to use SMALL() then you need to make an adjustment for the starting row:
=INDEX($R$4:$R$13,SMALL(IF($S$4:$S$13>0,ROW($S$4:$S$13)-ROW($S$4)+1),ROW(1:1)))
Or as #dirk pointed out the array part is the SMALL() not the INDEX, so it is okay to use the full column in the INDEX part and use your SMALL as is as it will return the actual row number:
=INDEX($R:$R$,SMALL(IF($S$4:$S$13>0,ROW($S$4:$S$13)),ROW(1:1)))
Also an array formula so confirm with Ctrl-Shift-Enter.
Another method is to use the AGGREGATE which is entered without the CSE as a normal formula:
=INDEX($R:$R,AGGREGATE(15,6,ROW($R$4:$R$13)/($S$4:$S$13>0),ROW(1:1))
This gets entered in as a regular formula. It is still an array type formula so one still needs to use only the dataset as a reference and avoid full column references in the array part of the formula.
The last two are particularly helpful when first returned result is desired in the first row, as they do not require the COUNTIF() to maintain the Unique return.

Excel: retrieve data based on a column

I have an excel document with a checklist like this one:
| number | yes/no | notes |
| 1 | yes | blablabla |
| 2 | yes | twinkle twinkle |
| 3 | no | little star |
I'd like to "echo" the fields which are set as "no" (in the second column) in another sheet, echoing the columns "number" and "notes". The result of my example would be:
| number | notes |
| 3 | little star |
How could I do it? Thanks!
Assuming your Main Table is in Sheet2, range A2:A4 (row 1 being headers). Use this formula, as an array (enter with CTRL+SHIFT+ENTER) in your sheet 2:
=INDEX(Sheet2!A$2:A$4,SMALL(IF(Sheet2!$B$2:$B$4="No",ROW(Sheet2!A$2:A$4)-ROW(Sheet2!A$2)+1),ROWS(Sheet2!A$2:A2)))
This will return all the Numbers. To get the Notes, change the very first index range to Sheet2!C$2:C$4. Obviously adjust your range down as necessary (I doubt you only have 4 of these).
Finally, just wrap an IfError() around that, so it looks nice when you use it. As you add data to your table, your table of only "no" values will update.
=IfError(INDEX(Sheet2!A$2:A$4,SMALL(IF(Sheet2!$B$2:$B$4="No",ROW(Sheet2!A$2:A$4)-ROW(Sheet2!A$2)+1),ROWS(Sheet2!A$2:A2))),"").
edit:
Screenshots:
(Using the IfError([above formula],"") wrapper hides the #NUM results when there's no match.)

EXCEL find the last relative maximum in a array (formula, not VBA)

I have a range containing values such as:
169.7978
168.633
168.5479
168.7819
167.7407
165.4146
165.1232
I don't need the maximum value of the range, i.e., the first cell in this example), but the last relative maximum, which in this case is the fourth cell. Is there a way to get this value without having to write a VBA macro? The formula must be general enough to work with a multiple number of maxima.
It may be a bit limited, but you may start somewhere as below.
Stated array in the OP is:
+----------+---+
| y | x |
+----------+---+
| 169.7978 | 1 |
| 168.633 | 2 |
| 168.5479 | 3 |
| 168.7819 | 4 |
| 167.7407 | 5 |
| 165.4146 | 6 |
| 165.1232 | 7 |
+----------+---+
Given this, you can find direct adjacency relative min/max with the following helper columns
Assign a Global_Rank helper column and look for y distro identical trend on both adjacent f(x) with the following formulas ( assuming your data is sorted by the x index )( formulas from Row 2 and filled down ).
RelativeMax:
=IF(AND(D2<=D1,D2<=D3),"RelativeMax","")
RelativeMin:
=IF(AND(D2>=D1,D2>=D3),"RelativeMin","")
Modify as needed. Hope this helps.
Edit:
Although...
If you're going to assume the data is ordered properly, you could also just use =IF(AND(B2>=B1,B2>=B3),"RelativeMin",IF(AND(B2<=B1,B2<=B3),"RelativeMax","")) and skip all the malarkey. This should work with multiple maxima/minima. Please report back with results from your dataset!

Resources