Excel Formula to Determine Size - 3 variables - excel

I am trying to write a formula.
The variables are:
1 - Type (Copper or Aluminum)
2 - Amps (100, 150 or 200)
3 - Distance (in feet).
Determining the type of wire, the amps the wire will be pushing, and the distance determines the wire type.
Example: if I am using Aluminum type wire, for 100 Amps that is less than 150 ft, I would use type 1 wire.
Second Example: if I am using Aluminum, for 100 Amps that is greater than 150 ft but less than 200 feet, I would use 1/0 wire.
Any suggestions? Thanks!
Dimitri

Here is an example formula using all three variables as you requested. The scant information in your example is not inclusive enough to construct a formula that will account for all the variables involved.
Column "A" has the wire (aluminum); Column "B" has the amperage and "C" has the length in feet. D1 has the formula: =IF(AND(A1="Aluminum",B1=100,C1<150),"Type 1",IF(AND(A1="Aluminum",B1=100,(AND(C1>150,C1<200))),"1/0","?")).
Two issues: The "1/0" text will produce an error flag in the cell because of an interpretation for a two-year date. Simply click "ignore error" for all these cells. Secondly, the question mark is there because of not knowing what you would want to do with the other variables if the ones within the formula both prove false. This formula is only a partial answer that sees your examples.

=IF(AND(D10=100,$L$4=1),VLOOKUP(I10,$A$136:$C$158,3,TRUE),IF(AND(D10=150,$L$4=1),VLOOKUP(I10,$E$136:$G$154,3,TRUE),IF(AND(D10=200,$L$4=1),VLOOKUP(I10,$H$136:$J$149,3,TRUE),IF(AND(D10=100,$L$5=1),VLOOKUP(I10,$K$136:$M$158,3,TRUE),IF(AND(D10=150,$L$5=1),VLOOKUP(I10,$N$136:$P$158,3,TRUE),IF(AND(D10=200,$L$5=1),VLOOKUP(I10,$Q$136:$S$154,3,TRUE),"UNKNOWN"))))))
That ended up being my formula. Worked Great.

Related

Counting if part of string is within interval

I am currently trying to check if a number in a comma-separated string is within a number interval. What I am trying to do is to check if an area code (from the comma-separated string) is within the interval of an area.
The data:
AREAS
Area interval
Name
Number of locations
1000-1499
Area 1
?
1500-1799
Area 2
?
1800-1999
Area 3
?
GEOLOCATIONS
Name
Areas List
Location A
1200, 1400
Location B
1020, 1720
Location C
1700, 1920
Location D
1940, 1950, 1730
The result I want here is the number of unique locations in the "Areas list" within the area interval. So Location D should only count ONCE in the 1800-1999 "area", and the Location A the same in the 1000-1499 location. But location B should count as one in both 1000-1499 and one in 1500-1799 (because a number from each interval is in the comma-separated string in "Areas list"):
Area interval
Name
Number of locations
1000-1499
Area 1
2
1500-1799
Area 2
3
1800-1999
Area 3
2
How is this possible?
I have tried with a COUNTIFS, but it doesnt seem to do the job.
Here is one option using FILTERXML():
Formula in C2:
=SUM(FILTERXML("<x><t>"&TEXTJOIN("</s></t><t>",,"1<s>"&SUBSTITUTE(B$7:B$10,", ","</s><s>"))&"</s></t></x>","//t[count(.//*[.>="&SUBSTITUTE(A2,"-","][.<=")&"])>0]"))
Where:
"<x><t>"&TEXTJOIN("</s></t><t>",,"1<s>"&SUBSTITUTE(B$7:B$10,", ","</s><s>"))&"</s></t></x>" - Is the part where we construct a valid piece of XML. The theory here is that we use three axes here. Each t-node will be named a literal 1 to make sure that once we return them with xpath we can sum the result. The outer x-nodes are there to make sure Excel will handle the inner axes correctly. If you are curious to know how this xml-syntax looks at the end, it's best to step through using the 'Evaluate Formula' function on the Data-tab;
//t[count(.//*[.>="&SUBSTITUTE(A2,"-","][.<=")&"])>0]")) - Basically means that we collect all t-nodes where the count of child s-nodes that are >= to the leftmost number and <= to the rightmost number is larger than zero. For A2 the xpath would look like //t[count(.//*[.>=1000][.<=1499])>0]")) after substitution. In short: //t - Select t-nodes, where count(.//* select all child-nodes where count of nodes that fullfill both requirements [.>=1000][.<=1499] is larger than zero;
Since all t-nodes equal the number 1, the SUM() of these t-nodes equals the amount of unique locations that have at least one area in its Areas List;
Important to note that FILTERXML() will result into an error if no t-nodes could be found. That would mean we need to wrap the FILTERXML() in an IFERROR(...., 0) to counter that and make the SUM() still work correctly.
Or, wrap the above in BYROW():
Formula in C2:
=BYROW(A2:A4,LAMBDA(a,SUM(FILTERXML("<x><t>"&TEXTJOIN("</s></t><t>",,"1<s>"&SUBSTITUTE(B$7:B$10,", ","</s><s>"))&"</s></t></x>","//t[count(.//*[.>="&SUBSTITUTE(a,"-","][.<=")&"])>0]"))))
Using MMULT and TEXTSPLIT:
=LET(rng,TEXTSPLIT(D2,"-"),
tarr,IFERROR(--TRIM(TEXTSPLIT(TEXTJOIN(";",,$B$2:$B$5),",",";")),0),
SUM(--(MMULT((tarr>=--TAKE(rng,,1))*(tarr<=--TAKE(rng,,-1)),SEQUENCE(COLUMNS(tarr),,1,0))>0)))
I am in very distinguished company but will add my version anyway as byrow probably is a slightly different approach
=LET(range,B$2:B$5,
lowerLimit,--#TEXTSPLIT(E2,"-"),
upperLimit,--INDEX(TEXTSPLIT(E2,"-"),2),
counts,BYROW(range,LAMBDA(r,SUM((--TEXTSPLIT(r,",")>=lowerLimit)*(--TEXTSPLIT(r,",")<=upperLimit)))),
SUM(--(counts>0))
)
Here the ugly way to do it, with A LOT of helper columns. But not so complicated 🙂
F4= =TRANSPOSE(FILTERXML("<m><r>"&SUBSTITUTE(B4;",";"</r><r>")&"</r></m>";"//r"))
F11= =TRANSPOSE(FILTERXML("<m><r>"&SUBSTITUTE(A11;"-";"</r><r>")&"</r></m>";"//r"))
F16= =SUM(F18:F21)
F18= =IF(SUM(($F4:$O4>=$F$11)*($F4:$O4<=$G$11))>0;1;"")
G18= =IF(SUM(($F4:$O4>=$F$12)*($F4:$O4<=$G$12))>0;1;"")
H18= =IF(SUM(($F4:$O4>=$F$13)*($F4:$O4<=$G$13))>0;1;"")

IF Formula not calculating properly

I've structured a formula that should spit out a numerical answer that is basically a simple sum formula with IF statements assigning numerical values to qualitative inputs. Apologies for the length, I am looking at a number of different factors.Formula is:
Cell F36 contains:
=IF(F32="Medium-High", 18, IF(F32="High", 24, SUM(F16, IF(F20="High",5,IF(F20="Medium-High",4,IF(F20="Medium",3,IF(F20="Low-medium",2,IF(F20="Low",1))))),IF(F24="High",5,IF(F24="Medium-High",4,IF(F24="Medium",3,IF(F24="Low-Medium",2,IF(F24="Low",1))))),IF(F28="High",5,IF(F28="Medium-High",4,IF(F28="Medium",3,IF(F28="Low-Medium",2,IF(F28="Low",1,IF(F28="N/A",0)))))),IF(F30="N/A",0,IF(F30="High",5,IF(F30="Medium-High",4,IF(F30="Medium",3,IF(F30="Low-Medium",2,IF(F30="Low",1)))))),IF(F32="High",5,IF(F32="Medium-High",4,IF(F32="Medium",3,IF(F32="Low-Medium",2,IF(F32="Low",1,IF(F32="N/A",0)))))))))
F16 - contains values from 1 to 5
F20, F24, F28, F30, F32 - Are dropdowns, where you choose a value: Low, Low-Medium, Medium, Medium-High, High;
Right now, based on a test input, where: F16 = 5, F20 = Low (1), F24= Medium-High (4), F28 = N/A (0), F30 = Medium (3), F32 = Medium (3) my output in F36 is 11, however doing simple adding, I should be at 5+1+4+0+3+3 = 16.
Where am I losing 5 points?
You can create a table allocating numerical output to each qualitative inputs and using vlookup to get your output. For example, for a table created on K19:L25, the following can be used:
=SUM(F16,VLOOKUP(F20,K19:L25,2,FALSE),VLOOKUP(F24,K19:L25,2,FALSE),VLOOKUP(F28,K19:L25,2,FALSE),VLOOKUP(F30,K19:L25,2,FALSE),VLOOKUP(F32,K19:L25,2,FALSE))
EDIT:
Tried your formula and it gives the correct result. Maybe your 5 in F16 is not a numerical value? You can test it by using
=ISNUMBER(F16)
and it should give a TRUE if it is a number.
Debug embedded IFs is just hell.
What you are doing is recode a 5 levels scale. You may use alternative solutions.
a. place the 5 text values (from "Low" to "High") somewhere in a sheet, say in T1:T5, even better, give this range a name
then you can retrieve the values you search with
MATCH(F20,$T$1:$T$5,0)
b. if it's suitable for your use, you may use combo boxes, presenting the 5 choices and giving the desired answer (from 1 to 5) in a linked cell.
(maybe not the answer, but I can't comment…)
(This should be a comment but I needed the formatting capabilities of an answer)
This is the current logic of your formula:
Check cell F32: "Medium-High" outputs 18, "High" outputs 24
If F32 is neither of those, then SUM the following:
F16
Lookup for F20, F24, F28, F30, and F32 where the lookup for each is:
"High" = 5
"Medium-High" = 4
"Medium" = 3
"Low-Medium" = 2
"Low" = 1
I find it strange that you first check cell F32 only to check it again later in the sum. Because this current logic produces incorrect results, we can't really advise how to fix it without sample data and expected results. My guess is you are summing too many lookups by including the F32 in there, but that's just speculation without data.

Excel Solver - Prevent Identically Named Results

This may sound a bit odd and maybe I'm just missing the forest through the trees on this question, but is there a way to force the Excel Solver to return only one instance of a result? As a short example imagine that we have some results on the likability of various objects (colors, animals, and shapes). We want the solver to return the three most preferred objects from this list.
Red (400)
Dog (120)
Circle (100)
Red (400)
Cat (90)
Square (75)
Blue (90)
Horse (60)
Triangle (70)
Green (80)
Snake (30)
Rectangle (40)
Yellow (40)
Rabbit (20)
Pentagon (15)
The problem is, of course, simplified in this example. Basically, my issue arises in that I want one of each type, namely Red, Dog, and Circle but I keep getting Red, Red (again), and Dog because the total is higher. I want to define a way to prevent Solver from returning two values named the same. I just can't seem to figure it out and Google doesn't seem to produce any viable responses either.
It's unclear how your data is setup, and this could affect how you setup the Solver problem, but here is one method (nb - this method will only work if you have 200 or fewer values to choose from).
Make Column A for "Category". This would have values such as "Color", "Animal", and "Shape".
Column B would be for "Type", and contain the information you provided. (e.g. Dog, Cat, ... Red, Blue, ... Circle, Square, ...)
Column C is the Value or Score for the type shown in Column B, again the information you provided.
Column D has fields that Solver will manipulate, let's call it "Selected". Selected will be a 0 or a 1.
Column E is the result of selection, a simple calculation, =C2*D2, filled down.
Make Cell H2 the sum of Column E. This will be your objective for Solver.
Make G3 through G5 the values in "Category" (Color, Animal, Shape).
Make H3 through H5 the total selected values in each category. That is =SUMIF($A$2:$A$16,"="&G3,$D$2:$D$16) filled down.
The workbook looks like this ...
... from this, you can setup Solver with the following ...
Set Objective: is $H$2
To: is set to Max. (i.e. you are looking for the most preferred)
By Changing Variable Cells: is set to $D$2:$D$16
Subject to the Constraints: has four entries. $D$2:$D$16 = binary; $H$3 = 1; $H$4 = 1; $H$5 = 1
Select a Solving Method: is set to Evolutionary. You can use GRG Nonlinear, but it takes longer.
The dialog looks like this ...
... with the following result, which meets your criteria ...

excel- purchase cost function with multiple variables

So I'm not good with excel (computers in general) and can do some things but this one is out of my league.
This is the problem:
The cost of a used car is highly correlated with the following variables:
t= age of car 1 ≤ t ≤ 5 (years)
V= volume of engine 1000 ≤ V ≤ 2500 (cubic centimeters)
D= number of doors D= 2,3,4,5
A= accessories and style A= 1,2,3,4,5,6 (qualitative)
Using regression analysis, the following relationship between the cost and four independent variables was found:
purchase cost= (1+1/t)*V*(D/2+A)
Plot the purchase price of the car as a function of the four variables.
I know how to input the function into excel and only use one number from each variable:
Function:
=(1+(1/B2))*C2*((D2/2)+E2
Where: B2=1, C2=1000, D2=2, E2=1
Which: A1=4000 (for the purchase cost)
What I don't know is how to make the function use multiple number combinations within those variables (i.e. how to change one variable and not the others). I've looked up "youtube" videos and numerous websites to figure this out and none of them showed me what I needed to know. Any help would be greatly appreciated.
I think you have fundamentally solved your problem but there is a typo in your formula which is preventing it from calculating. Add a closing parenthesis at the end your formula. Then assuming that the formula is placed in cell A1 and your example values are placed in the cells indicated in your post, simply type a new numeric value in B2, C2, D2 and/or E2 'manually' and your formula result will update.
If you wish you can create a dropdown list in your cells to hold the list of values for each of your variables. This link should get you going.

If statment of a cell calculated using formula

My formula is giving me unexpected responses.
=IF(I5+H5=0,"Paid","Due")
see below
H I J k
-£34.40 £34.40 £0.00 Due
Cell H is calculated with this
=(SUM(F5+G5))*-1
See correct output with exact same formula on same worksheet
=IF(I3+H3=0,"Paid","Due")
H I J K
-£205.44 £205.44 £0.00 Paid
Cell H is calculated he same
=(SUM(F3+G3))*-1
Any ideas why the top calculation not correct but the bottom one is.
This is most likely the floating point issue. You should not compare floating point numbers directly with = because computers can't store the full decimal places. Just like if you divide 1 dollar by 3, you end up with .3333333333333 cents, well if you add 3 of those you don't necessarily get back 1 dollar, but slightly less due to the "lost" 3333's at the end. The proper way to compare is using a Delta threshold, meaning "how close" it needs to be.
so instead of
if (a+b=c,"paid", "due")
you would do
if(ABS(c-(a+b))<.01, "paid", "due")
so in that case .01 is the delta, or "how close" it has to be. It has to be within 1 cent. the formula literally means "if the absolute value of the difference between c and (a+b) is less than 1 cent, return paid, else return due. (of course, this will say due if they overpaid, so keep that in mind)
you should always do this.

Resources