variable cumulative target point without new row OR without VBA - excel

What I need to do is (please refer to the image below):
red numbers in C column should be calculated by excel. I wrote the
values that must be calculated after the proper formula is applied.
Each red number in C column gives the 1st point that the total of the values between D & I columns are >= related confidence level. For example:
C2 value is 2 because D2+E2+F2>=0,85. Since F2 is the 1st point to satisfy this requirement, C2 value is 2 (value of F1)
another example; C3 is 0 since immediately D3>=B3 already.
It won't be a proper solution to use only IF() function (that is what I can do but not proper) because this image is a simplified version of my real case. In my real case columns that are 0, 1, 2, 3, 4, 5 are extended until 60.
Is there any solution to this case
without VBA
without creating new rows for calculating cumulative values (there are also tons of reference rows so new rows will create fill-down inefficiencies)
regards

A simpler solution would be to add new columns to the right of your existing columns, and use those for cumulative values: then there's no problem with fill-down.

Related

Function to search for specific number and then to further search for the prefix

I have a huge amount of data to process in which 4 points with a related prefix needs to be subtracted from each other.
Data consists of ID and x value
Example
ID = 290.12, 290.03, 290.06, 290.09, 300.12, 300.03, 300.06, 300.09, 301.12, 301.03, 301.06, 301.09
(let's call prefix a "ring number" and suffix time on the clock)
X value = any numerical value for each ID assigned
What I'm hoping to do is to search for the first number before the dot i.e. 300 and then subtract the value of 300.06-300.12 in one cell and in another cell 300.03-300.09.
(The subtraction is just an example, how I need to manipulate with the numbers is slightly more complicated, but I got this one under control)
This is my actual Data and what I need to produce is to the right of the raw data. At the moment, I'm doing it manually for each set of "rings"
Anyone knows how to approach this? I'm thinking vlookup, but I'm not very proficient in excel.
New Excel
I tried vlookup, but I don't know how to construct the formula and I run out of ideas.
Edit:
I found out that REDUCE is no requirement in this case, so it can be shortened to:
=SQRT(SUM(((INDEX(B:D,XMATCH(I3+0.09,A:A),SEQUENCE(1,3))-INDEX(B:D,XMATCH(I3+0.03,A:A),SEQUENCE(1,3)))^2)))
You could change +0.09 and +0.03 to your needs and may reference them using LET() for easy maintaining:
=LET(id,I3,
_id1,0.09,
_id2,0.03,
SQRT(SUM(((INDEX(B:D,XMATCH(id+_id1,A:A),SEQUENCE(1,3))-INDEX(B:D,XMATCH(id+_id2,A:A),SEQUENCE(1,3)))^2))))
Previous answer:
=LET(
id,I3,
_id1,0.09,
_id2,0.03,
SQRT(
REDUCE(0, SEQUENCE(1,3),
LAMBDA(x, y,
x+((INDEX(B:D,XMATCH(id+_id1,A:A),y)
-INDEX(B:D,XMATCH(id+_id2,A:A),y))
^2)))))
This formula looks for the matching value of the id value I3 + _id1 minus the matching value of id value + _id2 for columns B to D and adds the ^2 results per column. Then it calculates it's square root.
You can change _id1 and _id2 to your needs.
To calculate the Delta (as shown) at once you could use:
=LET(id,I3,
_id1,0.09,
_id2,0.03,
_id3,0.12,
_id4,0.06,
x,SQRT(SUM((INDEX(B:D,XMATCH(id+_id1,A:A),SEQUENCE(1,3))-INDEX(B:D,XMATCH(id+_id2,A:A),SEQUENCE(1,3)))^2)),
y,SQRT(SUM((INDEX(B:D,XMATCH(id+_id3,A:A),SEQUENCE(1,3))-INDEX(B:D,XMATCH(id+_id4,A:A),SEQUENCE(1,3)))^2)),
(x-y)*1000)
You can have a column of unique values of the integers and a new column where you reference these values as id and drag down the formula to get your row by row result
In another column you can refer to these columns and sort per the second column using SORTBY()

Excel Calculate a running average on filtered data with criteria

I am trying to calculate a running average on a filtered data table. All other posts online use Sumproduct(Subtotal) on the entire range but do not calculate a row by row running average
I am stuck on how to calculate columns C and D.
If column B (Score) > 0, I want to sum and average it under column C (Average Win)
If column B (Score) < 0, I want to sum and average it under column D (Average Loss)
The table is filterable by column A (Type) and the results should look as follows
Progress so far:
I have figured out how to calculate a Cumulative score based on filtered data. However this does not fully solve my problem. I appreciate any help!
=SUBTOTAL(3,B3)*SUBTOTAL(9,B$3:B3)
SUBTOTAL(3,B3) checks if the current row is visible, SUBTOTAL(9,B$3:b3) sums the values.
Final update needed
Jos - Thank you for your detailed explanation on how subtotal() works. I learned a ton through your explanation and will continue to study it. This is my first time being exposed to structured referencing so some of the syntax is a bit confusing to me still
The last formula I need is a running win % column where a Win is defined by score > 0. Please see the picture below
My assumptions believe that the same formula would work, except that we average a 1 or 0 in each row instead of the [Score] column.
Using the prior solution, why can't we modify the output of your prior solution to calculate a running win %?
[...] IF([Score]>0,IF(ROW([Score])<=ROW([#Score]),[Win])))),0)
Where [Win] is a helper column with the outputs 1 for win, 0 for loss.
This could be done by saying
if([#score]>0,1,0)
Instead of averaging out the actual #Score, this would average out a column of 1's and 0's with the desired output 0%, 50%, 66%, etc.
I am aware that the solution I provided does not work but I am trying to embrace the correct logic. I still struggle to understand how these structured column references are calculated on a row by row basis.
For example: Average(If([Score]>0,[Score])
How is this calculated on a row by row basis? When A3 does If([Score] > 0,), does this equal If({-10}>0)? When on A4, does If([Score]>0) equal If({-10,20} >0)? Thank you for your patience and help thus far.
I disagree with your result for Average Loss for the last row of your unfiltered table (surely -9.33...?), but try this for Average Win:
=IFERROR(AVERAGE(IF(SUBTOTAL(3,OFFSET(INDEX([Score],1),ROW([Score])-MIN(ROW([Score])),)),IF([Score]>0,IF(ROW([Score])<=ROW([#Score]),[Score])))),0)
Same formula for Average Loss, changing [Score]>0 to [Score]<0.
Explanation:
Using the data you provided and assuming:
The table's top-left cell is in A1
The table is filtered on the Type column for "A"
In order to determine which rows are filtered, we must pass an array of range references - i.e. for each cell within a chosen column of the table - to the SUBTOTAL function. It's a touch unfortunate that such an array of range references can only be generated via a volatile function (INDIRECT or OFFSET), but here, unless we resort to helper columns, we are left with no choice.
INDEX([Score],1)
simply returns a range reference to the first cell within the Score column. When using Excel tables, it's preferable not to write formulas which include a mixture of structured and non-structured referencing, even if that results in slightly longer expressions. So here, for example, we would not reference A2 within the formula.
ROW([Score])-MIN(ROW([Score]))
generates an array of integers from 0 up to one fewer than the number of rows in the table, i.e.
{0;1;2;3;4}
and so
=IFERROR(AVERAGE(IF(SUBTOTAL(3,OFFSET(INDEX([Score],1),ROW([Score])-MIN(ROW([Score])),)),IF([Score]>0,IF(ROW([Score])<=ROW([#Score]),[Score])))),0)
becomes
=IFERROR(AVERAGE(IF(SUBTOTAL(3,OFFSET(A2,{0;1;2;3;4},)),IF([Score]>0,IF(ROW([Score])<=ROW([#Score]),[Score])))),0)
OFFSET then generates an array of range references (though note that you will not be able to 'see' this step within the Evaluate Formula window - rather, an array of #VALUE! errors is displayed):
=IFERROR(AVERAGE(IF(SUBTOTAL(3,{A2;A3;A4;A5;A6}),IF([Score]>0,IF(ROW([Score])<=ROW([#Score]),[Score])))),0)
SUBTOTAL then determines which of these range references is filtered (note that care must be given here to the choice of first parameter), returning the relevant Boolean, so that:
SUBTOTAL(3,{A2;A3;A4;A5;A6})
resolves to:
{1;1;1;0;1}
And so we now have:
=IFERROR(AVERAGE(IF({1;1;1;0;1},IF([Score]>0,IF(ROW([Score])<=ROW([#Score]),[Score])))),0)
and the rest is straightforward.
So, I would use averageifs().
=averageifs(B:B,B:B,">=1",A:A,"A")
is one example, note I have added the control of Type A in the example.
See:

Automatically fill a column based on some criteria from other columns

I would be very grateful if someone could help me with this question.
I'm working on a worksheet which has 3 columns R, SF and DF where the performance percentages
of each of these variables are recorded (R, SF, DF).
If the percentage is greater than 90, the variable is classified as Critical. If the percentage is greater than or equal to 80 and less than 90, the variable is classified as Attention.
Finally, if the variable is greater than or equal to 60 and less than 80, the variable is classified as Trigger.
I would like to automatically fill another column by comparing the 3 percentages of each variable and taking the highest value. If the highest value is the variable R, for example, then the cell in this other column will be filled with R and its respective classification,
(C -Critical or A - Attention or T - Trigger).
Non-VBA Solution
Consider two formulas:
=SWITCH(MATCH(MAX(B2:D2),B2:D2,0), 1, "R", 2, "SF", 3, "DF")
IF(MAX(B2:D2)>=90,"C",IF(MAX(B2:D2)>=80,"A",IF(MAX(B2:D2)>=60,"T","")))
The first formula will provide you with the column index (based on the input range) that is associated with the MAX value. You can then use SWITCH to convert the index - in this instance, we convert to a string. The conversion is as follows:
Column Index:Output = 1:R, 2:SF, 3:DF
The second formula is nested IF statements which gets evaluated from left to right. Once your criteria is met, the rest of the formula will not be evaluated so you only need to check for Greater Than criteria rather checking for In Between as you explained.
If you want the output in one cell you can just combine the formulas with & as shown below. I have also shared a photo of the setup I used so you can relate the formula to the ranges
A2 = SWITCH(MATCH(MAX(B2:D2),B2:D2,0), 1, "R", 2, "SF", 3, "DF") & IF(MAX(B2:D2)>=90,"C",IF(MAX(B2:D2)>=80,"A",IF(MAX(B2:D2)>=60,"T","")))

How to take the average between two values in a column and place this value in between them in Excel?

I have data in column A that goes from 360-800 in steps of 2 (360, 362, 364 etc).
Each one of these entries has a unique value (1.06E-07, 1.80E-07, 2.91E-07 etc).
Please see the image attached.
Data for column A, B and D
I have a new column D, which goes from 360-800 but in steps of 1 (360, 361, 362, 363 etc)
I want column E to have the same corresponding values as with column B, but for the new entries (361, 363, 365 etc), I want the value to be the average of the two B values it is in between.
For example, 360 should still have the value 1.06E07, but 361 should have a value of (1.06E-07 + 1.80E-07)/2. 362 should still have the value 1.80E-07. How can I do this?
Thanks
E1 should be
=IFERROR(VLOOKUP(D1,$A$1:$B$7,2,FALSE),(VLOOKUP(D1-1,$A$1:$B$7,2,FALSE)+VLOOKUP(D1+1,$A$1:$B$7,2,FALSE))/2)
Drag it down for the rest plus change the range, I only used a 7 row sample.
Here is a beginners approach (I'm pretty sure, there are lots of ways to do this)
I would start by filling the values for the even numbers by vlookup. After that put it in an if function that checks for ISERROR. for the case of an error, i.e. the value can not be found (your odd numbers) add two vlookups, one for the value - 1, and one for the value + 1, then add those two up and divide them by two.
Another formula using AVERAGEIFS function that can be used.
=IF(MOD(D1,2)=0,SUMIFS(B:B,A:A,D1),AVERAGEIFS(B:B,A:A,">="&(D1-1),A:A,"<="&(D1+1)))

Store an integer in a cell and use that to set the number of column gaps

I'm creating a revenue model on a simple spreadsheet. On the top, I have a variable cell (C5) that is the "number of weeks between transactions". Below that, I have a simple weekly revenue model.
Problem: What I would like is to be able to tweak the fields in yellow and have it apply dynamically to the model below so that it applies the sales amount from C4 every X weeks to the model below, where X is C5.
My initial guess was to use OFFSET, such as F10 =SUM(OFFSET(C10,0,$C$5)), but I've never used this function before and the more I think about it, I'm not sure if I'm approaching this correctly at all.
I created a mock desired results image to show what I would like to have happen if I enter 3 in C5 and then change it to 2.
May not be quite right but hopefully 'configurable' to suit. Assumes $500 is entered in C10 and (at least for the time being) 1 will not be entered in C5. Please try in D10 and copied across to suit:
=IF(MOD(COLUMN()-3,$C5)<MOD(COLUMN()-4,$C5),$C10,"")
A quick fix for the above failing to populate all cells when C5 is 1 is to wrap the formula in the condition =IF($C5=1,$C10,....)
MOD "returns the remainder after a number is divided by a divisor". The remainder being 0 when the number is an exact multiple of the divisor. If we take the first example (every third column) a suitable divisor is 3. Put =MOD(Column(),3) in A1 and copy across and the result is 1, 2, 0, 1, 2, 0, 1, ..... (Column() returns a number representing the column letter, with 1 for A, 2 for B etc., or the actual Column Heading where R1C1 reference style is checked under Working with formulas, in Formulas within Excel Options.)
So that establishes a series where every third position is identifiable as returning a value from MOD that is less than that of the immediately preceding cell. For the second example (every second column) with a divisor of 2 =MOD(Column(),2) in A1 copied across results in 1, 0, 1, 0, 1, ... so again the reduction in the remainder signals the position required for the formula to output the requisite value.
We are comparing the result of calculating the remainder for one column relative to the result of the same calculation performed on the previous column, hence -3, -4. Other (suitably paired) values might work equally well, it just seemed easier to 'start from zero' when in the first column for the formula (ColumnD or 4).
(If anybody would like to provide a proper explanation please feel free to edit!)

Resources