Check if a Cell Value is between Two Values using Vlookup - excel

In Excel, I have a table as follows, which shows pricing based on volume.
If you buy up to 4 items per month, the unit price is $100, 5 to 8 is $90, 9 to 20 is $80, anything above 20 is $50.
A | B | C
----------------
1 | 4 | 100
5 | 8 | 90
9 | 20 | 80
21| 1000 | 50
I have my monthly purchase volumes in another column, say d:
D
--
3
6
2
4
3
10
7
7
10
2
I need to find the unit prices (C column values) based on this series falling between the values of A and B columns. I know I can use a compound if statement like =IF(AND(D$1>=A1,B1>=D$1),C1,0) ... but since my pricing table is actually much larger than my example, this approach becomes convoluted. How can I do this with a Vlookup in an elegant way?

I'd go with the following in E1:
=INDEX(C$1:C$4,MATCH(D1,A$1:A$4))
which, at worst should be just as fast as VLOOKUP but at best is much faster.

This can be done by dragging the following formula down to cover the full column D:
=LOOKUP(2,1/($A$2:$A$5<=D2)/($B$2:$B$5>=D2),$C$2:$C$5)
This will take each D value, compare with A and B, locate which bucket it falls into, and pull the C value. If not found, will return an N/A.

Here is an approach using SUMIFS:
=SUMIFS($C$1:$C$4,$A$1:$A$4,"<="&E1,$B$1:$B$4,">="&E1)

Related

Calculate sum of differences between rows but only if the previous cell is bigger than the current one

I started to get a headache around my problem that I cannot figure out for the love of me.
There are unknown amounts of column if that makes any difference, but basically each row needs to be compared to the previous one and ONLY when the previous value is greater, the difference between them gets added to the sum.
So for example I have this table
| A |
--|-----|
1 | 100 |
2 | 90 |
3 | 80 |
4 | 100 |
5 | 70 |
6 | 20 |
7 | 100 |
...
Expected result: 100, derived from ((100-90) + (90-80) + (100-70) + (70-20))
I have spent a whole day browsing every single excel tutorial page and cannot find a single helpful answer. Please help :(
Formula for Cell B2: (pull down through the rows).
=IF(A1>B1;A1-B1;0)+B1
Logic: If previous value is larger than current value, add the difference to the total.
If you want to do it in one formula, a basic way would be two use two ranges offset by one cell:
=SUMPRODUCT((A1:A6-A2:A7)*(A1:A6>A2:A7))
If you wanted to make a bit more dynamic (assuming there are no gaps in the data) you could try
=SUMPRODUCT((A1:INDEX(A:A,COUNT(A:A)-1)-A2:INDEX(A:A,COUNT(A:A)))*(A1:INDEX(A:A,COUNT(A:A)-1)>A2:INDEX(A:A,COUNT(A:A))))
If there are blanks between numbers, this won't work and you would probably need to go back to a simpler pull-down formula

Excel countif and sumif together

I am trying to write a formula in Excel which will count how many times we have sold less than 50 of a particular product. For example, here is a day's sales:
Order | Product | Qty
1 | A | 5
2 | A | 5
3 | A | 5
4 | B | 30
5 | C | 75
I want a formula in a cell which says how many times we have a requirement for less than 50 of a certain product. So in the example above, there is a total of 15 As, 30 Bs and 75 Cs, so 2 of those are less than 50.
I think it will need to be an array function of COUNTIF and SUM, but can't figure it out.
You could use this formula:
=SUMPRODUCT(--(IF(ROW($B$2:$B$10)=MATCH($B$2:$B$10,$B$1:$B$10,0),SUMIF($B$2:$B$10,$B$2:$B$10,$C$2:$C$10),"")<50))
Note: It's an array formula and must be entered through Ctrl+Shift+Enter
Product order placement can be randomized and does not have to be in order.
Another way
=SUMPRODUCT((SUMIF(B2:B10,B2:B10,C2:C10)<50)/COUNTIF(B2:B10,B2:B10))
Maybe something like that will help:
=SUMPRODUCT(--IF($B$2:$B$11<>$B$1:$B$10,SUMIF($B$2:$B$11,$B$2:$B$11,$C$2:$C$11)<50,0))
Note that this is an array formula so needs to be entered with Ctrl+Shift+Enter. Data needs to be sorted by Product (i.e. product A cannot appear in random rows, like row 2, 20 and 100; it needs to be grouped together).
Result:

Excel - Rather complex SUM IF criteria

I have roughly the following setup:
Values:
MONTH | DURATION | VALUE |
5 | 3 | 120 |
6 | 1 | 100 |
Expected outcome for totals:
MONTH | TOTAL
5 | 120
6 | 220
7 | 120
What I would like to do, is to be able to sum in another table the total values for each month. The logic would be to SUM every value where the total table's month is equal or higher than that of the values, but lower than the value's month + duration.
Does that make any sense? Is that possible? I'm cracking my head and I can't seem to find a way to solve it.
Thank you very much.
The easiest solution is probably to make another column with the end month. And then use SUMIFS to check if month is >= starting month and <= ending month.
=SUMIFS(<Range of Values>,<Range of starting>,"<="& "Target month",<Range of ending>,">="& <Target month>)
DSUM is the best candidate for this, I believe. See Microsft's documentation and this site for help understanding function, and what it is doing. I have made very complex calculations possible in Excel by using the "database" methods (DSUM, DCOUNT, etc).

Build 1D array / list in formula by multiplying values for use in AVERAGE()

I have an excel spreadsheet with a list of values, column A contains the grading, column B contains the number of occurrences:
A | B
---------------
Grading | Count
1 | 1
2 | 1
3 | 2
4 | 3
5 | 5
I would like to find the average grading based on the count but to do this I need to build a list based on these values, I.E. the above chart should translate into:
=AVERAGE(1,2,3,3,4,4,4,5,5,5,5,5).
I have managed to come to a solution through a very convoluted method of creating a new table, using IF and COUNTIF to print out an array and then AVERAGE the entire range but this is time consuming to repeat and I'm sure there is much simpler way of doing this.
If I'm not mistaken, you can just take the sum of product of columns A and B, then divide by the sum of the Count column:
=SUMPRODUCT(A2:A6, B2:B6) / SUM(B2:B6)
Note that using your hand written expanded formula yielded the same results:
=AVERAGE(1,2,3,3,4,4,4,5,5,5,5,5)

Excel: Average of parts of a column based on another column

Using Excel 2011 for mac, I have three columns: ID, Start date, end date and time to completion. (Date format: dd/mm/yyyy)
ID | Start | End | Time
1 | 01/01/2016 | 05/01/2016 | 4
2 | 04/01/2016 | 08/01/2016 | 4
3 | 01/02/2016 | 14/02/2016 | 13
4 | 02/02/2016 | 20/02/2016 | 18
5 | 01/03/2016 | 05/03/2016 | 4
6 | 06/03/2016 | 08/03/2016 | 2
7 | 12/03/2016 | 15/03/2016 | 3
Column D is basically the difference between column C and column B.
Now I have the total average, which is easy to calculate but I'd also like to have the averages for the different months.
And this is where my knowledge falls apart. I've tried several things but I can't seem to figure out how to calculate an average using only the cells in a column that match a certain value in another column. I could sort the tickets by date and do it manually by doing the average for only a certain range but as this list constantly changes this is definitely not a nice option.
Check out the AVERAGEIF function
AVERAGEIF(selection_range, criteria, averaging_range)
It uses the values in the selection_range to filter which values in the averaging_range will be averaged.
In your case you could say AVERAGEIF(B1:B8, "01/01/2016", D1:D8)
There are multiple ways. I would personally use an array formula, but that may be a bit advanced and overly complicated.
I suggest adding a column E "Month" - into E2 add:
=MONTH(B2)
Then copy cell E2 to E3:E8.
Now you can easily get a monthly average by applying the AVERAGEIF command:
=AVERAGEIF(E2:E8,2,D2:D8)
The second argument, 2, indicates February, but may be exchanged with any number from 1-12.

Resources