I'm struggling with the following:
I have price ranges from
100 - 200
201 - 300
301 - 400
401 - 500
501 - 600
In every range I give a number from 1-5. I'm trying to give a a number from 1 to 5 to a cell that will check in which price range is.
For example if I write in price field 150 it has to give me to the cell with the formula the number 1 according to the ranges I have. So far I've tried the following but I cannot nest more than 3 ifs.
=IF(AND(B9>=A10,B9<=C10),"1",(IF(AND(B9>=A11,B9<=C11),"2",IF(B9>=A12,B9<=C12,"3"))))
You could use =SUMPRODUCT() to do this. There are also some CSE formulas that would do the trick, but I prefer non-CSE since those can be finicky if someone messes with the formula and doesn't enter them properly:
=SUMPRODUCT((B9>=$A$10:$A$19)*(B9<=B10:B19)*(ROW($A$10:$A$19)-9))
Sumproduct will test each condition here that is then being multiplied together. The conditions in this formula are: (B9>=$A$10:$A$19) and (B9<=B10:B19) which are pretty self explanatory. From each condition, for each row in the range it gets a 1 or 0 (TRUE or FALSE) and then multiplies that by the ROW()-9 for each row being tested. In the end you get the ROW()-9 for whichever row has two TRUE conditions, or 1 * 1 * (Row()-9).
Note that because it tests each row, only one row should return two true conditions, otherwise you'll add up row numbers and get bad results.
Set up a cross-reference table of the minimum amounts for each price range in ascending order. From your sample data this could be Z2:Z7.
Your formula to examine the value entered into B9 would be,
=IFERROR(IF(B9<MAX($Z$2:$Z$7), MATCH(B9, $Z$2:$Z$7), NA()), "not in range")
If everything equal-to-and-above 501 should be in price group 5 then simply remove the top values (e.g. 601) and the check for the maximum.
=IFERROR(MATCH(B9, $Z$2:$Z$6), "not in range")
That will still return not in range for values less than 100 but anything over 500 will return price group 5.
Related
I am trying to create a formula that finds the monthly mileage for a vehicle. The simple =max(array)-min(array) will not work because there are blanks/0 cell values due to a vehicle not being driven. This causes the minimum to be zero. I have tried to use the small(array,2) but if there are multiple cells, it counts every blank as a separate value. Is there a simple way to express this? All cells are pulling the mileage from a separate workbook so even the blank cells have a formula. I want to write a formula for the following expression, "the cell with the maximum mileage minus the cell with the minimum mileage but the minimum cell can not be zero or blank, if it is skip/do not use".
I know the maximum for the first box is 40532 - minimum is 40285= 247
The maximum for the second box is 13281 - minimum is 13154= 127
You can use MAXIFS()for this: it calculates a maximum, in case of criteria.
MAXIFS() is described in this URL.
Edit for more explanation
I've just created the following worksheet:
A B C
1: 100 200 300
2: 0 100 300
3: 400 50 200
4: 0 100 100
I have entered this formula:
=MINIFS(A1:C4;A1:C4;">0")
The first A1:C4 is the range, where the minimum should be calculated.
The second A1:C4 is the range, where the criterion should be validated.
">0" is the criterion itself.
The result was 50, as it should be.
Currently. I have it set up when someone enters information in column E (Action Taken) then the whole row will turn yellow so it is easily seen that that item is being dealt with.
Another conditional format that I have set up is that once 5 working days pass on the date entered into column F (Date Actioned) then the row will turn red alerting the user to chase up the issue again.
Every week the user will contact more suppliers on the list regarding the listed product, and fill in their action taken and date actioned.
What I am looking to do is to add up all the suppliers contacted in one week (i.e. week 1 , 05.02.18 to 09.02.18) Which I know can be done by using the formula;
=COUNTIFS(F4:F18,">=5/2/18",F4:F18,"<=9/2/2018")
HOWEVER I only want to count each company once! So even though between the date 05.02.18 to 09.02.18, 8 actions were carried out, they only contacted 4 suppliers.
Is this possible? (FYI the screenshots attached are just a quick mock-up of the real document which contains thousands of products and more in-depth information).
If you don't mind adding a couple of working columns, the following is a possible solution:
Step 1
Set up two cells to contain the min and max dates for your range that you used in your formula =COUNTIFS(F4:F18,">=5/2/18",F4:F18,"<=9/2/2018"). This will allow you to up date things without having to recopy the formula each time. I used cells E1 and G1 for min and max date respectively.
Step 2
In a new column generate a list of supplier IDs that match your criteria. I arbitrarily chose column H. I placed the following formula in H4 and copied down:
=IF(AND(F4>=$E$1,F4<=$G$1),A4,"")
Step 3
In a new column generate a list of the count of the first time a supplier ID occurs from column H and do not count blank spaces. I arbitrarily chose column I. I placed the following formula in I4 and copied down:
=--(AND(COUNTIF($H$4:H4,H4)=1,H4<>""))
Step 4
Take the sum of the results from step 3. I arbitrarily chose to place the following formula in I19:
=SUM(I4:I18)
The "cop out" route, if you were only doing the calculation for 1 week would be to have a Pivot Table, with the Company as the Rows and the Date as the Columns. Then filter your columns, and you get a row per Company that week.
The Full route means looking into Array Formulae - you type one of these like normal, but instead of pressing [Enter], you press [Ctrl]+[Shift]+[Enter], and the equation will show in curly braces. (This is why they are sometimes called "CSE Formula" for "Control, Shift, Enter")
~Warning - This is a long walk through how I calculated the final formula. Hopefully it will make sense though!~
An array formula lets you iterate through every row in a range, calculate them seperately, and then add them all together at the end. This gives us the outside term - everything goes inside a =SUM(..). Press [Ctrl]+[Shift]+[Enter], and this will display as {=SUM(..)}
Now, what calculation do we want to be doing per row? Well, for every row where column F is within date, you want 1 per company within date. Well, another was to say "per" is "divided by" (hence the "Percentage" symbol being "0 / 0" or "%", and the lesser knows "Permille" symbol being "0 / 00" or "‰")
For the sake of reproducibility, I am going to assume that your Count is being done in Cell J2, and you have the Start/End of week dates in Cells H2 and I2
The formula for Row 4 would start out as =IF(AND(F4>=$H2,F4<=$I2), 1/???, 0), where ??? is how many times the Company on row 4 appears. Unfortunately, the AND function does not work with Array Formula. Fortunately there is an easy workaround - since boolean True/False can be treated as binary 1/0, the AND operator is the same as multiplication. Converting from boolean to binary is fastest by double-negation, so AND(F4>=H2,F4<=I2) can be rewritten as --(F4>=H2)*--(F4<=I2), which will work fine with array formula, giving us =IF(--(F4>=H2)*--(F4<=I2), 1/???, 0)
Now, before we work out what ??? should be, I'm going to skip down to row 18. There is method to this madness, I promise! Following the rules laid out above, the formula for row 18 is =IF(--(F18>=H2)*--(F18<=I2), 1/???, 0) - fairly simple? Now, if we want to run this for all rows from 4 to 18, we just need to join the ranges. So, you would get =IF(--(F4:F18>=H2)*--(F4:F18<=I2), 1/???, 0) Turning this into an Array Formula would get you an array of "1/???"s and "0"s, so add it together with SUM to get a single 'flat' number: =SUM(IF(--(F4:F18>=H2)*--(F4:F18<=I2), 1/???, 0))
Remember that "method" I mentioned earlier? Well, if we were looking for a straight Count of actions taken, ignoring the Unique Companies constraint, we could make ??? = 1, to get =SUM(IF(--(F4:F18>=$H2)*--(F4:F18<=$I2), 1, 0)) and hit [Ctrl]+[Shift]+[Enter] - which would give the same result as =COUNTIF(F4:F18, ">="&H2, F4:F18, "<="&I2) - and changing the 1 to D4:D18 would be a SUMIF on Products. (Incidentally, you can remove the IF statement from the CountIf, since the Condition returns 1 or 0 already)
So, last step! What is ??? Well, it's a Count of rows where Date Actioned is within our date bounds, and Company is the same as the current row. So, for Row 4 you have COUNTIFS(B4:B18, B4, F4:F18, ">="&H2, F4:F18, "<="&I2), and for Row 18 you get COUNTIFS(B4:B18, B18, F4:F18, ">="&H2, F4:F18, "<="&I2), making the final ??? become COUNTIFS(B4:B18, B4:B18, F4:F18, ">="&H2, F4:F18, "<="&I2) (The trick here is that the Range arguments are treated as all the cells at once, but the Condition arguments are treated as an array of each cell one-at-a-time)
Now, some people might argue that you need to put your 1/COUNTIFS(B4:B18, B4:B18, F4:F18, ">="&H2, F4:F18, "<="&I2) inside an IFERROR to be safe - however, this is in the TRUE part of an IF statement referrring to the same row, so we know that if the COUNTIF is being evaluated then there will always be at least 1 row that matches.
So, if we stick it all together, and add a load of $ symbols to lock the rows/columns in place (so that you can drag down column J to calculate for different weeks/dates in columns H and I) you get the (slightly unwieldy) formula as follows:
=SUM(IF(--($F$4:$F$18>=$H2)*--($F$4:$F$18<=$I2), 1/COUNTIFS($B$4:$B$18, $B$4:$B$18, $F$4:$F$18, ">=" & $H2, $F$4:$F$18, "<=" & $I2), 0))
And, one last time - Don't forget to press [Ctrl]+[Shift]+[Enter]
(The 2 Date cells, $H2 and $I2 are the only terms I have left 'unlocked', and even then only on the Row)
I am trying to count records that are located in different rows which:
are within a certain date range eg. starting from >= 01/01/2017
are within the same month as defined above eg. < 31/01/2017
have records within a range across multiple rows, row numbers must be obtained via MATCH by finding the row of the cell that contains "Negative Comment 1" and MATCH the row number of the cell that contains "Negative Comment 5" (eg. "Negative 1" is in Row 220, "Negative 5" is in row 224, hence the rance would be I220:AZZ224 which spans 5 rows)
Formula looks like this:
=IFERROR(COUNTIFS(
// starting date
'MED-FB-YTD'!$I$18:$AZZ$18,">="&DATE(YEAR(E3),MONTH(E3),"1")-1,
// end date
'MED-FB-YTD'!$I$18:$AZZ$18,"<"&DATE(YEAR(E3),MONTH(E3),"31"),
// define range between Negative Comment 1 to 5 and count all records that are not empty
INDIRECT("'MED-FB-YTD'!$I$"&MATCH("Negative Comment 1",'MED-FB-YTD'!$C:$C,0)&":$AZZ$"&MATCH("Negative Comment 5",'MED-FB-YTD'!$C:$C,0)),"<>"),
"ERR")
The problem is here
// define range between Negative Comment 1 to 5 and count all records that are not empty
INDIRECT("'MED-FB-YTD'!$I$"&MATCH("Negative Comment 1",'MED-FB-YTD'!$C:$C,0)&":$AZZ$"&MATCH("Negative Comment 5",'MED-FB-YTD'!$C:$C,0)),"<>"),
The formula works fine if I change the range to count from 5 rows to 1 row (eg. change from I220:AZZ224 to I220:AZZ220), which leads me to believe that the countifs() formula doesnt like to count cells across multiple rows, which in turn however is unlikely as I used countifs() before and did just that.
Right now, I am always getting the #value error. Any suggestions?
EDIT
Sample data below:
MED-FB-YTD (data source):
Display form:
There seems to be something missing in the formula which you have pasted at the end (I mean in your problematic line).
Can you re-share your formula?
I have a bunch of sequential rows and I'm trying to average the last 90 based on a criteria. The average needs to be in a single cell, rather than a column that calculates a running average. I figured out how to calculate an average for the last 90 rows, but I am not able to correctly add the if function to meet the criteria prior to averaging.
Data:
sale type (b) Data(c) Rownumber (E)
a 45 1
b 35 2
c 36 3
c 56 93
Here is the average function that's working correctly AVERAGE(OFFSET(E2,COUNTA(E:E)-1,-2,-90)).
Here is the AVERAGEIF function that I'm trying to run that is giving incorrect data:
=AVERAGEIF(B:B,I15,OFFSET(E2,COUNTA(E:E)-1,-2,-90))
I15 cell in this case, is the sale type that I am trying to match.
Thanks in advance for the help!
=AVERAGEIF(OFFSET(B2,COUNTA(E:E)-2,0,-90),$I$15,OFFSET(C2,COUNTA(E:E)-2,0,-90))
first: you need to "-2", not "-1" from your row, you're not getting the last 90 with -1 .. (test it by changing a record in data to "999" at the outskirts. You'll see it pick up that value when the AVG changes dramatically.)
second: your and range have to match .. heights anyway. So use the same offset formula in both.
To slightly optimize this, you could calc that "COUNTA(E:E)-2" in another column, name it, then just reference it in both cases (that way Excel only calcs it once, not twice). ;)
Also, if the I15 cell is a single cell, you might want to $I$15 it to be safe. I don't think this matters in this case, just a habit of doing that to single, isolated cells that aren't part of a range :)
If you actually have row numbers (of the data) in column E you could use AVERAGEIFS and just use another criteria based on column E, like this:
=AVERAGEIFS(C:C,B:B,I15,E:E,">"&MAX(E:E)-90)
I am analysing library statistics relating to loans made by particular user categories. The loan data forms the named range LoansToApril2013. Excel 2007 is quite happy for me to use an index range as the sum range in a SUMIF:
=SUMIF(INDEX(LoansToApril2013,0,3),10,INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6))
Here 10 indicates a specific user category, and this sums loans made to that group from three columns. By "index range" I'm referring to the
INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6)
sum_range value.
However, if I switch to using a SUMIFS to add further criteria, Excel returns a #VALUE error if an index range is used. It will only accept a single index.
=SUMIFS(INDEX(LoansToApril2013,0,4),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL")
works fine
=SUMIFS(INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL")
returns #value, and I'm not sure why.
Interestingly,
=SUMIFS(INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,4),INDEX(LoansToApril2013,0,3),1,INDEX(LoansToApril2013,0,1),"PTFBL")
is also accepted and returns the same as the first one with a single index.
I haven't been able to find any documentation or comments relating to this. Does anyone know if there is an alternative structure that would allow SUMIFS to conditionally sum index values from three columns? I'd rather not use three separate formulae and add them together, though it's possible.
The sumifs formula is modelled after an array formula and comparisons in the sumifs need to be the same size, the last one mimics a single column in the LoansToApril2013 array column 4:4 is column 4.
The second to bottom one is 3 columns wide and the comparison columns are 1 column wide causing the error.
sumifs can't do that, but sumproduct can
Example:
X 1 1 1
Y 2 2 2
Z 3 3 3
starting in A1
the formula =SUMPRODUCT((A1:A3="X")*B1:D3) gives the answer 3, and altering the value X in the formula to Y or Z changes the returned value to the appropriate sum of the lines.
Note that this will not work if you have text in the area - it will return #VALUE!
If you can't avoid the text, then you need an array formula. Using the same example, the formula would be =SUM(IF(A1:A3="X",B1:D3)), and to enter it as an array formula, you need to use CTRL+SHIFT+ENTER to enter the formula - you should notice that excel puts { } around the formula. It treats any text as zero, so it will successfully add up the numbers it finds even if you have text in one of the boxes (e.g. change one of the 1's in the example to be blah and the total will be 2 - the formula will add the two remaining 1s in the line)
The two answers above and a bit of searching allowed me to find a formula that worked. I'll put it here for posterity, because questions with no final outcome are a pain for future readers.
=SUMPRODUCT( (INDEX(LoansToApril2013,0,3)=C4) * (INDEX(LoansToApril2013,0,1)="PTFBL") * INDEX(LoansToApril2013,0,4):INDEX(LoansToApril2013,0,6))
This totals up values in columns 4-6 of the LoansToApril2013 range, where the value in column 3 equals the value in C4 (a.k.a. "the cell to the left of this one with the formula") AND the value in column 1 is "PTFBL".
Despite appearances, it isn't multiplying anything by anything else. I found an explanation on this page, but basically the asterisks are adding criteria to the function. Note that criteria are enclosed in their own brackets, while the range isn't.
If you want to use names ranges you need to use INDIRECT for the Index commands.
I used that formula to check for conditions in two columns, and then SUM the results in a table which has 12 columns for the months (the column is chosen by a helper cell which is 1 to 12 [L4]).
So you can do if:
Dept (1 column name range [C6]) = Sales [D6];
Region (1 column name range [C3]) = USA [D3];
SUM figures in the 12 column monthly named range table [E7] for that 1 single month [L4] for those people/products/line item
Just copy the formula across your report page which has columns 1-12 for the months and you get a monthly summary report with 2 conditions.
=SUMPRODUCT( (INDEX(INDIRECT($C$6),0,1)=$D$6) * (INDEX(INDIRECT($C$3),0,1)=$D$3) * INDEX(INDIRECT($E7),0,L$4))