EXCEL: Get next value for next highest matches - indexing

I have two input fields: Length and Width. Depending on those two inputs i want to retrieve a price from a price matrix. Preciscley that price should be taken where the length and width are either equal or the first time higher than what was entered. See the screenshot for the example please.
The inputs are 15,5 (length) & 5,5 (width). From the price matrix the price from the last row should be taken. Why? Because only in the last row length and width are both equal or higher than my two inputs.
Any tips are a highly appreciated!
Thank you!
I tried INDEX and MATCH. MATCH with +1,-1 didn't do the trick.

Related

Access- calculate days between first and last fields user entered

I have a form with two columns and two sections (pink-phase 1 and purple-phase 2). For each column within the pink section I want to calculate the total days between the first cell entered and the last cell entered. Same for the purple section.
Right now I have an equation that calculates the total days between the first and last field of each column within the sections, but I want to calculate the total days between the first field a user updated and the last field a user updated. Is this possible if so can someone please help me. Thank you!
For Each ctl in Me.Forms.Controls
If ctl.Tag = “pinkPlanned” Then
Me.PhaseOne = Max(fieldname) - Min(fieldname)
End If
Next ctl
EDIT: I figured out a code that works for me. I created a function that takes in an array and loops through the array to find the max date and min date.
Function dtMinMax (ParamArray arrFields () )
Then within the function I use the DateDiff function to calculate the total days between the max and min date.
DtMinMax = DateDiff(“d”, [dtmMin] , [dtmMax])
Then I call this function in my query design view, using the fields I want to loop through as my arrays.

Change the color of x number of cells based on the numeric value from another cell (in multiple rows)

My question is basically the same as this one (Change the color of x number of cells based on the numeric value from another cell) with one extra condition: for multiple rows.
enter image description here
So on the left side, there's a column "PTO 2018 Total" (range= I3:I80) and I want to color each row (range= J3:S80) based on the number of the column I, like I manually did for the first two rows.
Thank you so much in advance.
Use conditional formatting:
Use a formula rule with the formula:
=AND(COLUMNS($J1:J1)<=$I1,ISNUMBER($I1))
Applied to
=$J:$S

Extracting "hidden" data from expanding/collapsing pivot table - Excel

I'm not sure if this is possible but as you can see I have a pivot table with multiple dependent and expandable fields. I am trying to concatenate the data from columns A:D into one cell which works fine in row 2 but doesn't work with blank parent cells, as you can see in column F.
Any ideas for how to achieve this?
Pivot table
This answer assumes that you don't want to just Repeat All Item Labels in the PivotTable from the "Report Layout" drop-down on the Pivt Table Tools "Design" tab.
A formula to get the first non-blank value on or above the same row as the current cell from Column B can be constructed with a combination of AGGREGATE, SUMPRODUCT and OFFSET, like so:
=OFFSET($B2,SUMPRODUCT(AGGREGATE(14,6,ROW($B$1:$B$100)*--(ROW($B$1:$B$100)<=ROW())*--(LEN($B$1:$B$100)>0),1))-ROW(),0)
How does it work?
Starting with the outermost part, OFFSET($B2, VALUE, 0) - this will start in cell B2, then look up or down by VALUE rows to get the value.
Next we need to know how many rows we will need to look up-or-down. Now, if we can work out the bottom-most row with data, we can subtract the current ROW() from that, giving us OFFSET($B2, NON_BLANK-ROW(),0)
So, to finish up we need to work out which rows are not blank, AND which rows are on-or-above our current row, then take the largest of those. This is going to take an ArrayFormula, but we can use SUMPRODUCT to make that calculate properly. To find the largest number we could use MAX or LARGE - but we get less errors if we pick AGGREGATE(14,6,..,1). (The 14 means "we want the kth largest number", the 6 means "ignore error values", and the 1 is k - so "we want the largest number, ignoring errors")
But, what list of numbers are we going to look at, I don't hear you ask. Well, we want the ROW for output from our range (I'm using $B$1:$B$100, because using the whole column B would take far to long to calculate repeatedly), a comparison against the current ROW(), and check that the LENgth is > 0. Those last two are comparisons, so let's write them out first:
ROW($B$1:$B100)<=ROW()
and
LEN($B$1:$B$100)>0
We want to use -- to convert TRUE and FALSE to 1 and 0 - this means that any "bad" values become 0, and any "good" values are larger than 0:
ROW($B$1:$B$100)*--(ROW($B$1:$B$100)<=ROW())*--(LEN($B$1:$B$100)>0)
This gives us the Row number when the Row is on-or-before the current row AND Column B is not blank - if either of those are False, then we get 0 instead. Stick that in the AGGREGATE to find the largest number:
AGGREGATE(14, 6, ROW($B$1:$B$100)*--(ROW($B$1:$B$100)<=ROW())*--(LEN($B$1:$B$100)>0), 1)
Then put it in a SUMPRODUCT to force Excel to treat it as an ArrayFormula, and that's your NON_BLANK. This then gives you that first formula right at the top of the post

How to pull out corresponding column and row figures from a two dimensional data table?

peeps.
I currently have a two dimensional data table, which measures the sensitivity of two inputs, with regards to profit.
The whole data table, is (D183:AI234). I take the max profit one can gain from taking a max() value, and I was wondering what formula could I create, so I can get the corresponding values in the data table (two of them) which create the profit judged by max() from the whole data table.
Things I've tried: hlookup, vlookup to get both the inputs from row and column, but get N/A from both.
For example, to get the input from the row, based on look_up value, I used this formula: =HLOOKUP(E237,D183:AI234,1,0)
Kind Regards
Data Table:
Here's a hacky way to do it using array functions. I assume there is something cleaner.
Edit I misread the original question.
I am assuming that the data itself is in the range D183:AI234--the labels for the y-category are in C183:C234 and the labels for the x-category are in D182:AI182.
To find the row of the maximum value: MAX((D183:AI234 = MaxVal)*ROW(D183:D234))
With the row number there are a variety of options for actually accessing the value in your y-labels:
You can OFFSET from the upper left of the table (assumed to be
C182). OFFSET(C182, MAX((D183:AI234 = MaxVal)*ROW(D183:D234)) - ROW(C182), 0).
You can access the labeled cell using INDIRECT and ADDRESS, the row number, and a column identifier for the labels. INDIRECT(ADDRESS(MAX((D183:AI234 = MaxVal)*ROW(D183:D234)), COLUMN(C182)))
You can determine the relative position among the labels and use INDEX and the row number to retrieve the value. INDEX(C183:C234,MAX((D183:AI234 = MaxVal)*ROW(D183:D234)), COLUMN(C182)) - ROW(C182))
Note that these are all array functions and must be entered with CTRL + SHIFT + ENTER.
I'd prefer the INDEX approach as it is non-volatile (both OFFSET and INDIRECT are volatile functions and will recalculate every time a change is made to the sheet/excel recalculates) and I generally consider it to be better practice.
To get the x-value you identify the column of the maximum with MAX((D183:AI234 = MaxVal)*COLUMN(D183:AI183)) and adapt whichever of the three methods you choose.
Original answer to find the address of the max (but not the associated category values) below:
To find the row of the maximum entry you want to multiply a boolean array where your values match the maximum, so, that is (D183:AI234 = MaxVal) by the row numbers, so ROW(D183:D234). The result of that multiplication is a vector of (0,0,..,Row of Maximum Val,...), so you take the MAX of that to find the row number.
The same is true for the column, but you would use COLUMN(D183:AI183). Then you can get a cell address using the ADDRESS function.
Putting it all together...
=ADDRESS(MAX((D183:AI234 = MaxVal)*ROW(D183:D234)),MAX((D183:AI234 = MaxVal)*COLUMN(D183:AI183)))
This must be entered as an array function (CTRL + SHIFT + ENTER)

AVG of Cells Next to Cells used in Another Formula

I am new to asking questions here so I hope I get this correct. I am helping my dad with a spreadsheet and I'm having issues with figuring out how to do one formula. Dont know if it can be done with a formula or if it has to be done with macros.
This is a scoring sheet with multiple matches. For each match there is a total score and the cell next to the score is an X count (number of bulleyes). In the same row (column K) I calculate the top 6 total scores and average them:
=AVERAGE(LARGE((N15,Q15,T15,W15,Z15,AC15,AF15,AI15,AL15,AO15,AR15,AU15,AX15,BA15,BD15,BG15,BJ15),{1,2,3,4,5,6}))
Now I need to take the AVG of the X counts that are next to the total scores that are used in the formula above and put solution in column L.
For example, if the cells that are used for AVG score in that row are:
N15,Q15,T15,W15,Z15,AC15
then the cells that would need to be used for the X count AVG would be:
O15,R15,U15,X15,AA15,AD15
This result would be put into L15
Please help. If any clarification is needed just let me know.
Screen Shot:
Please try the following formula:
=SUMPRODUCT(O15:BM15,
--(MOD(COLUMN(N15:BL15)-COLUMN($N15),3)=0),
--(N15:BL15+O15:BM15/10^3+COLUMN(N15:BL15)/10^6>=
LARGE(N15:BL15+O15:BM15/10^3+COLUMN(N15:BL15)/10^6,6))
)/6
How does it work?
SUMPRODUCT has 3 parameters - first is the array to sum, next 2 parameters return an array of 0 and 1 to choose only interesting elements of the first array.
MOD(COLUMN(N15:BL15)-COLUMN($N15),3)=0)
This part is included to avoid listing every single cell. If the score is in every third column of the input range, we can calculate column number relative to first column, and function MOD(column,3) returns: {1,0,0,1,0,0...}. So only every third column of input array will be included in sum.
(N15:BL15+O15:BM15/10^3+COLUMN(N15:BL15)/10^6>=
LARGE(N15:BL15+O15:BM15/10^3+COLUMN(N15:BL15)/10^6,6)
This part is to decide which 6 of the scores should be included in the final sum. The trickiest part is to decide what to do with ties. My approach is to take:
if two scores are the same, take the one with higher number of bulleyes
if it is still tied, take the one from first columns
This means that instead of N15 value we calculate:
N15+O15/10^3+COLUMN(N15)/10^6
With your sample data it evaluates to: 566.017014. First three decimal places is the number of bulleyes, next 3 is column number.
You can use the same formula to calculate average of top 6 scores by changing the first parameter:
=SUMPRODUCT(N15:BL15,
--(MOD(COLUMN(N15:BL15)-COLUMN($N15),3)=0),
--(N15:BL15+O15:BM15/10^3+COLUMN(N15:BL15)/10^6>=
LARGE(N15:BL15+O15:BM15/10^3+COLUMN(N15:BL15)/10^6,6))
)/6
You can try this not so elegant solution:
=SUMPRODUCT(INDEX(N15:BK15,MATCH(LARGE((N15,Q15,T15,W15,Z15,AC15,AF15,AI15,AL15,AO15,AR15,AU15,AX15,BA15,BD15,BG15,BJ15),{1,2,3,4,5,6}),N15:BK15,0)+1))/6
Entered as array formula by Ctr+Shift+Enter in Cell L15:M15 (2 cells) which should look like this:
{=SUMPRODUCT(INDEX(N15:BK15,MATCH(LARGE((N15,Q15,T15,W15,Z15,AC15,AF15,AI15,AL15,AO15,AR15,AU15,AX15,BA15,BD15,BG15,BJ15),{1,2,3,4,5,6}),N15:BK15,0)+1))/6}
with added braces.
The number 6 is the equates to the number of top scores you want returned.
Now, why 2 cells (L15:M15). I cannot make SUMPRODUCT evaluate the resulting array from the INDEX so we have to enter it at 2 cells. I don't think that would be a problem since in your screen shot, Column M is not used.
Note: If the range evaluated have less than 6 items, it will error out. Also good point by user3964075. It may or may not be able to deal with ties.