Getting the next higher value with VLOOKUP or INDEX/MATCH - excel

I have the following Excel spreadsheet:
A B C D
1 0 Product 1 7.500 Product 4
2 1.000 Product 2
3 5.000 Product 3
4 10.000 Product 4
5
In Cell C1 I type a random number (in this case 7.500). Now I want that in Cell D1 the corresponding Product is shown to the value in Cell C1. Since 7.500 does not exist in Column A the next higher value should be used. In this case 10.000 which belongs to Product 4.
I tried to go with the following formula in Cell D2 but instead of getting Product 4 I get #NV as a result.
=INDEX(A1:B4;MATCH(C1;A1:A4;-1);2)
The only solution I found so far was changing the values in Column A from ascending to descending. However, I would prefer to have a solution which does not require a change of the order in the list.
Do you have any idea how to solve this issue without changing the order in the list?

For unsorted data you can use below formula::
=INDEX(B1:B4,MATCH(SMALL($A$1:$A$4,COUNTIF($A$1:$A$4,"<"&C1)+1),A1:A4,0))
See image for reference

Related

Ignore text values in subtotal function

Excel-Sheet:
A B C D E
1 1.200
2 Product A 500
3 Product B 400
4 Product C OK
5 Product D #NA
6 Product E 300
7
8
In the above table I have list of products in Column A and some data about the products in Column B.
In Cell B1 I want to calculated the subtotal of Column B using =SUBTOTAL(9,B2:B6).
However, now I have the issue that Column B not only consists of numbers.
It can also have the data type text (OK, NA). Therefore, the result in Cell B1 currently is #NA.
Is there any kind of formula that I could use so only the number data is considered and the result is 1.200 as in the table above?
Please note:
This function =AGGREGATE(9,6,B2:B6) won't help me because I want to filter the list later on so I need to go with the SUBTOTAL.
Use 7 as the second criterion in AGGREGATE instead of 6 as it will also exclude hidden rows:
=AGGREGATE(9,7,B2:B6)
You can solve this, combining the Excel worksheet functions =Value() and =IfERROR():
The function =Value() gives the value of a number, and in case of text it gives an error.
=IfError() can be used to give 0 in that case.
So, imagine you have following situation:
Column A Column B Column C
1 =Value(A1) =IfError(B1;0)
3.5 =Value(A2) =IfError(B2;0)
AB =Value(A3) =IfError(B3;0)
abc10 =Value(A4) =IfError(B4;0)
This gives following results:
Column A Column B Column C
1 1 1
3.5 3.5 3.5
AB #Value 0
abc10 #Value 0
You can simply take the sum of column C.
So this is based on the summary in B1.
=SUM(IF(ISERROR(B2:B6),"",B2:B6))
You need to push Ctrl+Shft+Enter for this to work.
Hope it helps.

Identify if list contains not unique values without countif in a helper column

A B C
1 Product A 1 Error
2 Product B 1
3 Product C 2
4 Product C 2
5 Product D 1
6 Product E 1
7
8
In the table above I want to identify if the values in Column A are unique.
If there is at least one value which is not unique Error should be displayed in Cell C1.
In order to achieve this I went with helper Column B and with the following formulas:
Column B `=COUNTIF($A$1:$A$6,A2)`
Cell C1 =`IF(COUNTA($A$1:$A$6)<SUM($B$1:$B$6),"Error","OK")`
All this works fine.
Now, I am wondering if there is also way to avoid the helper column.
Basically, a formula that goes through Column A and if it identfies at least one not-unique value it should display Error in Cell C1.
use:
=IF(MAX(COUNTIF($A$1:$A$6,$A$1:$A$6))>1,"Error","OK")
This is an array formula and depending on one's version will require the confirmation of Ctrl-Shift-Enter instead of Enter when exiting edit mode.
If one has the dynamic formula UNIQUE() then:
=IF(COUNTA(UNIQUE($A$1:$A$6))<>COUNTA($A$1:$A$6),"Error","OK")
As a normal formula.
Another formula, that will work in Conditional formatting:
=SUMPRODUCT(--(MATCH($A$1:$A$6,A:A,0)<>ROW($A$1:$A$6)))>0

Vlookup and sum all instances of the matching lookup

this is probably an extremely basic problem but I can't figure a way to do this within Excel.
I have a list of values IDs from a regional sales manager,
he wants to see if his figures have been inputted into the monthly report and are reporting correctly.
However, as he sells by region and we report by product we have multiple instances of his ID by Product
so our monthly report.. for example
ID Value
1 16,999
1 22,521
3 400
3 221
5 71
6 22,000
So he has provided me with a list of IDs
1
2
3
4
5
6
and wants a list with its total revenue not just the first match up.
Is an excel limitation or is there a way to do this?
You can use a SUMIF formula. Basically you give it the column to check the value of, then you give it the expected value and finally the colum to sum.
Option 1 (whole range)
=SUMIF(A:A, 1, B:B)
Option 2 (defined range)
=SUMIF(A1:A7, 1, B1:B7)
Option 3 (Using excel table)
=SUMIF([Id], 1, [Value])
For more details please refer to: https://support.office.com/en-ie/article/sumif-function-169b8c99-c05c-4483-a712-1697a653039b
Is this what you're looking for?
=SUMPRODUCT((A1:A5=1)*B1:B5)
Taken from here: Sum values from multiple rows using vlookup or index/match functions
How it works:
An array formula is used to create an array of numbers that gets passed to the SUMPRODUCT formula.
The array formula processes A1 and B1 together, then A2 and B2 and so on... if A1 is equal to 1, B1 is added to the array.

Getting the next lower value with VLOOKUP

I have the following Excel spreadsheet:
A B C D
1 15.000 Product 1 7.500 Product 2
2 5.000 Product 2
3 1.000 Product 3
4 0 Product 4
5
In Cell C1 I type a random number (in this case 7.500). Now I want that in Cell D1 the corresponding Product is shown to the value in Cell C1.
Since 7.500 does not exist in Column A the next lower value should be used.
In this case 5.000 which belongs to Product 2.
I tried to go with the following formulas in Cell D2 but instead of getting Product 2 I always get Product 4 as a result.
=VLOOKUP(F16,$A$1:$B$4,2,TRUE)
=VLOOKUP(F16,$A$1:$B$4,2)
Do you have any idea how to solve this issue?
For unsorted data you can use below formula:
=INDEX(B1:B4,MATCH(LARGE($A$1:$A$4,COUNTIF($A$1:$A$4,">"&C1)+1),A1:A4,0))
See image for reference
i will try it with addition columns, which indicates the difference between given 7.5 and col A like this: =IF($C$1-A1<0,999999,$C$1-A1) and then get the mininum value like =MIN(E1:E4). then get the according value in column B.
If the order is not guaranteed to be ascending then you can use an array formula (use ctrl+shift+enter instead of just enter to create an array formula)
=INDEX(B2:B5,MATCH((C2-MIN(IF((C2-A2:A5)<0,MAX(A2:A5),C2-A2:A5))),A2:A5,0))

Excel conditional SUMPRODUCT / SUMIFS / Array Formula for optional dimension

I have a sheet of data with multiple dimensions like this:
A B C D E
1 COUNTRY FLAVOUR SIZE DATE SALES ($)
2 Japan Strawberry 100ml 10/12/14 100
3 Japan Banana 100ml 10/03/15 100
4 China Orange 200ml 14/04/15 30
5 France Strawberry 200ml 11/04/15 400
6 UK 200ml 23/04/15 250
7 ....
I want to aggregate this data over a date range, where the summary sheet has each dimension (country & flavour), and if I do not specify a dimension it sums all rows for that dimension.
A B C
1 COUNTRY FLAVOUR SALES TOTAL
2 Japan Strawberry 100
3 Japan 200
4 Strawberry 500
I can do this if all the dimensions are present (i.e. row 2 above) using a SUMPRODUCT or SUMIFS:
=SUMPRODUCT((data!A$2:A$100=A1)*(data!B$2:B$100=B1)*(data!D$2:D$100>[start_date]*(data!D$2:D$100<[end_date])*(data!E$2:E$100))
However I have not been able to figure out how to include all rows for a dimension if that input cell is empty (e.g. row 3 above). I tried:
Adding an IF statement or OR statement within the criteria (e.g. OR(data!A$2:A$100=A1,isblank(A1))).
Using a + in a SUMPRODUCT as an OR statement, (per this answer https://stackoverflow.com/a/27536131/1450420)
One solution is to have different branches of the formula depending on which summary dimensions are present, but that would quickly get out of control if I extend this same behaviour to further dimensions like Size.
Any help appreciated!
(I'm running Excel Mac 2011).
EDIT
Per #BrakNicku's comment one of the formulas I tried was =SUMPRODUCT(((data!A$2:A$100=A2)+ISBLANK(A2))*((data!B$2:B$100=B2)+ISBLANK(B2))*(data!E$2:E$100))
The reason this doesn't work is that sometimes my data has blank attributes (edited above). For some reason this formula double-counts rows where the attribute present matches (e.g. data!A6) but the other attribute is missing (e.g. data!B6).
EDIT 2
I can see why this double-counting is happening, because the + is summing the match because data!A$2:A$100=A2 (they match because they are both blank) and the match because ISBLANK(A2) (it is indeed blank). The question would remain how to achieve this without double counting. If needed a workaround could be to fill all blank cells on my data with some placeholder value.
The reason for double-counting values is here:
((data!A$2:A$100=A2)+ISBLANK(A2))
If a cell in A column is blank, both parts of this sum are equal 1. To get rid of this problem you can change it to:
(((data!A$2:A$100=A2)+ISBLANK(A2))>0)
Try this (I only included the first two, I left the dates out):
=SUMPRODUCT((((Data!$A$2:$A$5=A2)+(A2=""))>0)*(((Data!$B$2:$B$5=B2)+(B2=""))>0)*(Data!$E$2:$E$5))

Resources