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","")))
Related
I am attempting to count instances of resistance to 1 or 1+ antibiotics under certain conditions. Here is an example of what what my spreadsheet looks like:
For each drug "1" indicates resistance and "0" indicates sensitivity.
If I wanted to determine the number of bacteria in Group A that are resistant to only one antibiotic how would I do this? Or if I wanted to find how many bacteria in Group A are resistant to 1 or more antibiotics?
I've been struggling with this one for awhile so if anyone could point me in the right direction I would sure appreciate it.
Ideally my output would look like this
These are array formulas. You MUST use Ctrl-Shift-Enter to enter these formulas, and Excel will magically insert curly braces (you cannot insert them yourself).
For exactly 1 resistance, enter into I2 as I have the setup in the pic below :
=SUM(($B$2:$B$11=$H2)*IF(MMULT($C$2:$E$11, TRANSPOSE(COLUMN($C$1:$E$1)^0))=1, 1, 0)) for typeA.
Drag the formula down to get type B as in my set up.
=SUM(($B$2:$B$11=$H3)*IF(MMULT($C$2:$E$11, TRANSPOSE(COLUMN($C$1:$E$1)^0))=1, 1, 0))
For more than 1 resistance, in J2, use:
=SUM(($B$2:$B$11=$H2)*IF(MMULT($C$2:$E$11, TRANSPOSE(COLUMN($C$1:$E$1)^0))>1, 1, 0)*(MMULT(IF($C$2:$E$11=9, 0, 1), TRANSPOSE(COLUMN($C$1:$E$1)^0))= COLUMNS($C$1:$E$1)))
Again, drag the formula down to get typeB...
Note that there are only ever three cell ranges/areas which you need to input into the formulas (albeit in several spots).
The data range for the type column
The data area for the resistance test results
The column headers for the drugs(should be the same width as the test results area).
If you set up named ranges for these areas, then you could put the named range into the formulas, and never have to amend the formula range arguments when the data ranges change size. But that's another point...
Edit for explanation:
If you evaluate formula parts, you might see something like this(for the image I provided)
=SUM(({TRUE;TRUE;TRUE;TRUE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE})*IF(MMULT({1,0,0;1,9,1;0,1,1;9,1,0;1,0,1;1,1,0;9,1,1;0,1,9;0,1,1;1,1,0},{1;1;1})>1, 1, 0)*(MMULT({1,1,1;1,0,1;1,1,1;0,1,1;1,1,1;1,1,1;0,1,1;1,1,0;1,1,1;1,1,1},{1;1;1})= 3))
True or false evaluates as 1 or 0 when multiplied.
The effect of the '^0' is to turn each non-zero number in the resultant arrays into a '1'. This allows matrix multiplication to take place on the datarange to spit out column vectors.
TRANSPOSE({3,4,5}^0) becomes: TRANSPOSE({1,1,1}), which then becomes this: {1;1;1}. Notice the difference between commas and semicolons - this means a 1x3 vector is transposed into a 3x1 vector. Then you can use that as the second parameter into matrix multiplication with a 10x3 matrix(thats the dataset in our case).
The output of that MMULT is a 10x1 column vector representing some output.
The first MMULT is used to test if the row Total of any bacteria is > 1. The second MMULT is used to see if all the row entries for any bacteria are <> 9.
A similar thing is done for the case for Exactly One. The MMULT function is used once to determine if the row total for a bacterium is exactly 1.
Create a new column for "Resistance Count" and use =COUNTIF(B2:D2,">=1") for cell E2 and fill down. Then you can filter the table by Type or Resistance Count. Use SUBTOTAL to count the filtered rows.
Here's what I would do:
1) Create an additional column (named "Count") to the right of your table with the count of 1s in each bacteria row. The formula is: =COUNTIF(C2:E5, "1")
2) Create another column (named "Resistance")to the right of your table with a nested IF statement. The formula is: =IF(F2=1,"Resistant to 1",IF(F2=0,"Resistant to 0","Resistant to More than 1"))
3) Create a Pivot Table with this Data. Put "Resistance" in the Columns Field, "Type" in the Rows Field, and "Sum of Count" in the Values field.
This should give you exactly what you want.
I asked this question a couple of week back, however deleted it after going down a different track. It has now come up again.
I use the following formula to total the values in the DK range, based on if the value in the associated EC column equals "EE", which works perfectly.
I also want to keep this type of formula so that I can filter on other columns and it will automatically alter the total based on what is being displayed.
=SUMPRODUCT(SUBTOTAL(9,OFFSET($DK$18,ROW($DK$18:$DK$4102)-ROW($DK$18),,1)),--($EC$18:$EC$4102 = "EE"))
Below is a snippet from the spreadsheet
The Question
I would like to expand this formula to round the values in the DK range to 2 decimal places before it gets subtotalled.
Is this possible and if so how?
It sounds like you are trying to set the ROUND operation in the wrong place. Each cycle of the SUMPRODUCT function is acting on a single digit from the SUBTOTAL function; it only matters whether SUBTOTAL believes it to be hidden or not. That is what needs to be ROUNDed, not the range in the OFFSET function. The range in the OFFSET function has been converted to an incremental set of numbers with the ROW function (e.g. {0, 1, 2, ... 4082, 4083, 4084}).
=SUMPRODUCT(ROUND(SUBTOTAL(9, OFFSET($DK$18, ROW($DK$18:$DK$4102)-ROW($DK$18), 0, 1, 1)), 2), --($EC$18:$EC$4102 = "EE"))
I'm not going to retype your image's data so no pretty pictures. You might also want to look into the more recent AGGREGATE function as a substitute for SUBTOTAL (xl2010+).
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!)
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.
I am trying to get the average value(s) of some specific entries. I have two columns: A-which is an index column (it goes e.g. from 1 to 1000) and B which is the values column.
I know there is an AVERAGE function and there is an AVERAGE IF function, which will probably help me but I can't seem to get it working the way I need to.
What I need to do is to get the average value of the entries in column B that match this description for the index in column A: 3 + (3*n) in which n >= 0. In this case I need the average of the values in column B, whose entries in A are 3, 6, 9, 12, 15...
Is it possible to do this with excel or do you think it would be better to write a program to get those values?
Thanks for your tips!!
-Jordi
You can use an "array formula" with AVERAGE function, e.g.
=AVERAGE(IF(MOD(A2:A100,3)=0,IF(A2:A100>0,B2:B100)))
confirmed with CTRL+SHIFT+ENTER
To modify according to your comments in simoco's answer you can use this version
=AVERAGE(IF(MOD(A2:A100-11,3)=0,IF(A2:A100-11>=0,B2:B100)))
That will average for 11, 14, 17, 20 etc.
You can use SUMPRODUCT for this:
=SUMPRODUCT((MOD(A1:A1000,3)=0)*B1:B1000)/MAX(1,SUMPRODUCT(1*(MOD(A1:A1000,3)=0)))
Explanation:
MOD(A1,3) gives you 0 only if value in A1 is in form 3*n
MOD(A1:A1000,3)=0 gives you array of true/false values {FALSE,FALSE,TRUE,FALSE,..}
since False is casts to 0 and TRUE casts to 1 when multipliybg by any value, (MOD(A1:A1000,3)=0)*B1:B1000 returns you array of values in column B where corresponding value in column A is in form 3*n (otherwise zero 0): {0,0,12,0,..}
SUMPRODUCT((MOD(A1:A1000,3)=0)*B1:B1000) gives you a sum of thouse values in column B
SUMPRODUCT(1*(MOD(A1:A1000,3)=0)) gives you number of values in form 3*n in column A
and the last thing: MAX(1,SUMPRODUCT(1*(MOD(A1:A1000,3)=0))) prevent you from #DIV/0! error in case when there is no values in column A in form 3*n
UPD:
in general case, say for rule 11+3*n you could use MOD(A1:A1000-11,3)=0