Excel: Value from one cell based on max value with multiple criteria in other column - excel

I am trying to get value in column 8, based on MAX value (column Range4) with multiple criteria (Range1, Range2, Range3), but excel gives me an error "#N/A". Where is the mistake?
VLOOKUP(MAX(IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4))));Range5;8;FALSE)
The part
{MAX(IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4))))}
works right alone (it gives me the right value), but not inside the VLOOKUP function.
Thanks!
Sample data set for testing:
First_day Last_day Week_Num Week_Range Month Year Rank_name Rank_value
01/04/2013 07/04/2013 14 1-7 april april 2013 Alexa 10122
08/04/2013 14/04/2013 15 8-14 april april 2013 Alexa 9670
15/04/2013 21/04/2013 16 15-21 april april 2013 Alexa 9130
22/04/2013 28/04/2013 17 22-28 april april 2013 Alexa 8340
29/04/2013 05/05/2013 18 29-5 april april 2013 Alexa 7543
31/03/2014 06/04/2014 14 31-06 april april 2014 Alexa 11428
07/04/2014 13/04/2014 15 07-13 april april 2014 Alexa 7159
14/04/2014 20/04/2014 16 14-20 april april 2014 Alexa 7027
21/04/2014 27/04/2014 17 21-27 april april 2014 Alexa 6675
28/04/2014 04/05/2014 18 28-04 april april 2014 Alexa 5379
Equivalence between ranges and columns:
Range1 = Column "Year"
Range2 = Column "Month"
Range3 = Column "Rank_name"
Range4 = Column "Week_Num"
Range5 = Column "Rank_value"

Please try:
=INDEX(Range8;MATCH(MAX(IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4))));Range4;0))
with Control+Shift+Enter.

The problem with the existing formula (from pnuts, Jun 10 2014) is this:
The formula first narrows the list down by the nested if's, and then picks the maximum Week_Num from those rows that match your criteria. But having located that maximum, the MATCH function then ignores the criteria (they were only used to find the max from Range4). If you have other rows (even though they don't match the criteria) that have the same Week_Num, MATCH will locate the first row out of the whole list that has the same Week_Num in Range4. One solution is to add the same criteria to the MATCH's "lookup_array" that were used in the "lookup_value".
=INDEX(Range8;MATCH(MAX(IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4))));IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4)));0))
Again, using Control-Shift-Enter.
I think I entered the above formula correctly, but I didn't build a sheet to test it, so...
Also, be aware, this formula still has a problem in the case where no rows in the list meet the criteria. In that case you get an error. The solution to that is to add an IFERROR at the front of the whole thing.
=IFERROR(INDEX(Range8;MATCH(MAX(IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4))));IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4)));0)),"")

Related

How to grab the running total of the first day of the month?

I'm trying to write an Excel function to grab the value of the Running Total in rows that are on the first of the month in the Date column. Where there are more rows with the same date, I want to grab the last value. (The dates are in ascending order.)
This is an example of the kind of table I'm using:
Income
Running Total
Date
$1,000.00
$1,000.00
Jun 30, 22
-$60.00
$940.00
Jul 01, 22
-$42.00
$898.00
Jul 20, 22
-$55.00
$843.00
Aug 01, 22
-$200.00
$643.00
Aug 01, 22
-$60.00
$583.00
Aug 19, 22
-$20.00
$563.00
Sep 01, 22
$334.00
$897.00
Sep 10, 22
-$610.00
$287.00
Oct 01, 22
-$50.00
$237.00
Oct 02, 22
I have a formula for calculating the running total and the date is created with the DATE() function.
I'm planing to use the function in a new table on the same sheet. In each row is the running total of the first of that month.
Month
Amount
Jul
Aug
Sep
Oct
The problem is that I'm expecting this table to grow and I don't want to manually search each row. I would like to have a function that goes through the Date column and identifies if it contains the date of the first day of the month, if it does, get the running total.
I have attempted something like this:
=CONCAT("$B",MATCH(”Jul 01, 22”,$C1:$C100,1))
But I don't know how to create the function or whether or not this works.
How can I write a function that grabs the Running Total on the first of the month?
You can use either INDEX() & MATCH() or XLOOKUP()
• Formula used in cell F2
=INDEX($B$2:$B$11,MATCH(DATE(2022,MONTH(E2&1),1),$C$2:$C$11,1))
Or,
• Formula used in cell H2
=XLOOKUP(DATE(2022,MONTH(E2:E5&1),1),C2:C11,B2:B11,,1,-1)
or, can exclude the 5th parameter, of XLOOKUP() as well
• Formula used in cell H2
=XLOOKUP(DATE(2022,MONTH(E2:E5&1),1),C2:C11,B2:B11,,,-1)

Excel - Sum QTD values based on selected month

Desired end state: The QTD field sums the quarterly values to date so as an example for October it would return just the October value (1st month in Q4) but when November is selected as the driver the QTD field would sum Oct + Nov values (ignoring the value for Dec).
I have a spreadsheet with drivers and the current date will be updated daily. This date drives the "Current Month" field from which I want the QTD values to recalculate.
See example linked below. Expected results - Cat 1 QTD for Nov would be 3,387,280; Cat13 QTD for April would be 1,121,021 and so on
Thanks in advance!
In O6:
=SUMIFS(C6:N6,$C$4:$N$4,"<="&MONTH("1 "&A2),$C$4:$N$4,">="&MATCH(INDEX($1:$1,MATCH(MONTH("1 "&A2),$4:$4,0)),$C1:$N1,0))
Alternative approach using SUMPRODUCT:
=SUMPRODUCT(C6:N6,--(("Q"&ROUNDUP(MONTH(1&$A$2)/3,0))=$C$1:$N$1),--($C$4:$N$4<=MONTH(1&$A$2)))
Result:

MS Excel - Extract Unique Text Patterns Keyword from Substring

I would like through the use of a MS Excel Formula to extract text/year from a substring of text containing a unique search pattern. I have a column (Cell A2:A19) of unique dates, in some instances there is surrounding text before and after the text, that I would like to extract only the year that all uniquely begin with the number "1" (i.e., 17??, 18??, 19??, etc.)
Current Formula
DATE
April 1 1799
April 11 1867
February 12 1806
February 21 1798
February 28 1844 as Delaware Township
February 5 1798
February 7 1892 Verona Township
February 9 1797
January 19 1748
July 10 1721 as Upper Penns Neck Township
March 15 1860
March 17 1870 (as Raritan Township)
March 17 1874
March 23 1864
March 5 1867
April 28th 1828
1840s
1878 as Lehigh Township
CURRENT RESULTS (from formula used above)
DESIRABLE RESULTS:
This formula will get you every one except the 1840s
=TRIM(MID(A2,MIN(IFERROR(SEARCH({"17?? ","18?? ","19?? "},A2 & " "),1E+99)),4))
It is an array formula and must be confirmed with Ctrl-Shift-Enter on exiting edit mode. If done correctly then Excel will put {} around the formula.
If macros are allowed you can create a code module and put this code in it:
Public Function GetYear(text As String)
Dim regex
Set regex = CreateObject("VBScript.RegExp")
regex.Pattern = ".*(\d{4}).*"
Set matches = regex.Execute(text)
GetYear = matches(0).Submatches(0)
End Function
Then, you can use a formula like "=GetYear(A1)" to get all years, including 1840s and other similar formats. It basically searches for a group of four digits next to each other in the given string. Not the best date matching algorithm, but sounds like it'll be enough for your use case.
Using the MS Excel formula provided by Scott, I was able to make a minor tweek that resolved the issue of also capturing/extracting only dates and other similar. This was achieved by only adding the wildcard Asterisk symbol to represent any series of characters, following the question marks "??". Thanks Scott... =IFERROR(TRIM(MID(A2,MIN(IFERROR(SEARCH({"16??* ","17??* ","18??* ","19??* "},A2 & " "),1E+99)),4)),"")

List all the corresponding numbers which fall within a month

I have a table which looks something like this
Month Item Haul
June Gravel 23
July Asphalt 45
June Asphalt 5
June Asphalt 7
September Asphalt 26
October Gravel 17
June Asphalt 21
September Gravel 25
I want to create a function that will list all of the different "Asphalt" hauls which happen within a given month in another sheet so that I can calculate the tonnages of each haul. The result should look something like this
June
5
7
21
Is this even possible?
With a PivotTable (Month for ROWS , Item for COLUMNS and Haul for Σ VALUES) you can set Σ VALUES to calculate the average for you and if you want the detail for Asphalt and June just double click on that row/column intersect. The drill down will automatically open in another sheet and the PT will default to a separate sheet unless you choose otherwise.

How do i add year (date) criteria to DSUM?

I have a database that looks like this:
(A1)Client (B1) Date (C1) debts
(A2)1 (B2) Mon 2 november 2008 (C2) 1500$
(A3)2 (B3) Thu 7 february 2008 (C3) 1000$
(A4)3 (B4) Sat 28 March 2009 (C4) 800$
(A5)4 (B5) Mon 16 March 2009 (C5) 1200$
The date format is 24/11/2008.
I have to use DSUM to get the sum of the debts clients had in 2008.
I already did a table that looks like this:
(A7)Client (A7) Date (C7) debts
(A9) 2008
and the function =DSUM(A1:C5,3,A7:C8) but it seems I can't extract the value of 2008 from the date 24/11/2008.
It is generally not a good idea to store dates as text, change your 2008 to 1/1/2008 and format as "YYYY"
To use DSUM to sum entries that fall in a calendar year you will have to define the start and end date, so your filter data will look like this:
Client Date Date
debts =">=1/1/2008" ="<1/1/2009"

Resources