Multiple IF statements without adding them together - excel-formula

I am trying to write a formula in Excel that is comprised of 6 separate formulas each with multiple criteria, I will try and explain what I am trying to do below.
If the value in B7 is 2 and the value in F7 is between 3 or 0 the value in G7 is assigned as A, if the value in B7 is 2 but the value in F7 is between 4 and 6, the value in G7 is assigned as B etc..
I have managed to get it working when the value in B7 is 1 but I cannot get it working for when the value is 1 or 2.
I have tried using the & between the two formula but all it does is add them together. I have tried using ELSEIF, IF(OR(AND as well as multiple other combinations, all to no avail. My formula for when the value in B7 is 1 is below.
=IF(AND(B7=1,F7<=1),"A",IF(AND(B7=1,F7>=2,F7<=4),"B","C"))
One example of what I have tried to get it working for 1 and 2
=IF(AND(B7=1,F7<=1),"A",IF(AND(B7=1,F7>=2,F7<=4),"B","C"))OR(IF(B7=2,F7<=3),"A",IF(AND(B7=2,F7>=4,F7<=6),"B","C"))
Thank you

This is a combined formula with 2 Approx. Lookup formulas for Table 1 and Table 2 as show in below picture
1] Approx. Lookup formula for Table 1 :
=LOOKUP(F7,{0,2,5},{"A","B","C"})
2] Approx. Lookup formula for Table 2 :
=LOOKUP(F7,{0,4,7},{"A","B","C"})
3] To choose Table 1 or Table 2 using CHOOSE function
=CHOOSE(B7,{0,2,5},{0,4,7})
So, the combined formulas become >>
=IFERROR(LOOKUP(F7,CHOOSE(B7,{0,2,5},{0,4,7}),{"A","B","C"}),"")
Finally add an error trap IFERROR function in return blank for B7 give number other than 1 or 2.

Related

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.

Populating Excel table using 2 cell coordinates - lots of data

I need your help with this problem I'm facing using Excel. Basically I need to populate a table, or better, a given group of cells (dimensions 3x3), and my starting point is:
row numb. column name. value
2 A 10
3 C 4
4 B 20
so I would need to obtain a group of cell like this:
1 A B C
2 10 0 0
3 0 0 4
4 0 20 0
where the cells that have no value can be 0 or whatever. In other words, I have the coordinates where I need to insert the value, and I need to be insert the value corresponding to the coordinates in the right cell.
I already tried many times using functions like MATCH, VLOOKUP and INDEX (also ROW and COLUMN) but without success, because it inserts the correct values but also other combinations of coordinates that I don't want.
My idea was to start from cell A2 and, with the formula, check if there's a match with the coordinates of row and column in the data, and finally print the value.
PS: I would prefer to avoid VBA.
Try this array formula: (Of course, change your cell ranges as necessary)
= IFERROR(INDEX($G$2:$G$4,MATCH(TRUE,ADDRESS(ROW(),COLUMN(),4)=($F$2:$F$4&$E$2:$E$4),0)),0)
Note this is an array formula, so you must press Ctrl+Shift+Enter rather than just Enter after typing the formula.
See working example below.

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 concatenation by using formula or vlookup

I have two sheets in excel workbook.
I need the formula which matches SITEID and concatenate 3 values to 1 separated by / .
I have tried to use Vlookup with ranges but not get the actual results.
First sheet contains (4 columns):
SiteId Cell Sector Bore
MDLH1238 12381 1 10
MDLH1238 12382 2 20
MDLH1238 12383 3 40
MDLH1239 12391 1 60
MDLH1240 12401 1 50
MDLH1240 12402 2 20
Second sheet contains (2 columns):
SiteId Bore
MDLH1238
MDLH1239
MDLH1240
The expected result should be like this :
SiteId Bore
MDLH1238 10/20/30
MDLH1239 60
MDLH1240 50/20
Assuming there's only ever 3 sectors per site, and using your sheet names, and assuming your cells start in A1, enter these in Sheet2, adjacent to the SiteIDs:
Cell B2:
=SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A2,Sheet1!$C$2:$C$7,1)&"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A2,Sheet1!$C$2:$C$7,2)&"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A2,Sheet1!$C$2:$C$7,3)
Cell B3:
=SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A3,Sheet1!$C$2:$C$7,1)&"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A3,Sheet1!$C$2:$C$7,2)&"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A3,Sheet1!$C$2:$C$7,3)
Cell B4:
=SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A4,Sheet1!$C$2:$C$7,1)&"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A4,Sheet1!$C$2:$C$7,2)&"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A4,Sheet1!$C$2:$C$7,3)
That should produce content like:
SiteId Bore
MDLH1238 10/20/40
MDLH1239 60/0/0
MDLH1240 50/20/0
That's got extra "/0" entries where the sector 2/3 don't exist, but the formulas get longer and harder to read, to do that.
Edit: Adds the formulas for dealing with "/0"
Cell B2:
=SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A2,Sheet1!$C$2:$C$7,1)&IF(SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A2,Sheet1!$C$2:$C$7,2)>0,"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A2,Sheet1!$C$2:$C$7,2),"")&IF(SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A2,Sheet1!$C$2:$C$7,3)>0,"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A2,Sheet1!$C$2:$C$7,3),"")
Cell B3:
=SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A3,Sheet1!$C$2:$C$7,1)&IF(SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A3,Sheet1!$C$2:$C$7,2)>0,"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A3,Sheet1!$C$2:$C$7,2),"")&IF(SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A3,Sheet1!$C$2:$C$7,3)>0,"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A3,Sheet1!$C$2:$C$7,3),"")
Cell B4:
=SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A4,Sheet1!$C$2:$C$7,1)&IF(SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A4,Sheet1!$C$2:$C$7,2)>0,"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A4,Sheet1!$C$2:$C$7,2),"")&IF(SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A4,Sheet1!$C$2:$C$7,3)>0,"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A4,Sheet1!$C$2:$C$7,3),"")
Output:
SiteId Bore
MDLH1238 10/20/40
MDLH1239 60
MDLH1240 50/20
What you would like to be able to do is to concatenate elements of an array using "/" as a separator. Unfortunately native Excel can't do this, but there are plenty of good VBA functions already written which will, e.g. the one described here.
So I would suggest this solution:-
=StringConcat("/",IF(Sheet1!A$2:A$7=A2,Sheet1!D$2:D$7,""))
starting in cell B2 of the second sheet and pulled down as necessary. This is an array formula and must be entered using CtrlShiftEnter.
In order to use the StringConcat function, you need to copy the code from the web page, press AltF11, select Insert|Module, then paste in the code.

Excel countif(s) multiples

I'm trying to calculate the count of multiple occurrences of a figure using countif.
I have the range set but I need a calculation which can count in multiples of 50 without me having to type thousands of versions of countif (=COUNTIF(B2:B5,">=50")-COUNTIF(B2:B5,">100" etc.).
Data Count
50 1
70 1
80 1
10 0
150 3
This data should show 6 but at the moment I'm getting 4.
First you can start by making bins. you can make it with Data analysis tool or half manual
Like in the example, on A2 enter 0 and on b2 enter =a2+50
Same goes for a3 enter =b2 and last on a4 =a3+50
Now you can drag it down as much as you like.
Instaed of using countif use sumif finction. let's assume your data is on cloumn H and the values you want to sum are in column I, then on c2 enter
=SUMIFS(I:I,H:H,">"&A2,H:H,"<="&B2)
you can drag it down as much as you like.
Simply use Excels ROUNDDOWN function:
e.g. for B2: =ROUNDDOWN(A2/50,0)

Resources