Finding the right range from excel table - excel

What is the best way to find the right column for the travelled miles using visual basic coding or some excel function and return the price from that column? HLOOKUP can't be used here because the lookup value isn't exact and the ranges in the table are also not with specific intervals (If they were, I could use e.g. FLOOR(travelled miles/100)*100 and find the price with HLOOKUP). Obviously, it's easy to find the price manually with a small table but with a big table computer will be faster.

Note that, if x is between a and b, then MEDIAN(x,a,b)=x. Combine this with some nested IFs:
=IF(MEDIAN(B5,B1,C1-1)=B5,B2,IF(MEDIAN(B5,C1,D1-1)=B5,C2,IF(MEDIAN(B5,D1,E1-1)=B5,D2)))
I'm on my phone, so just done the first three cases, but hopefully you can see how it continues.
(should note you need to remove the dashes for this to work)
Edit:
I also want to answer your question in the comments above. You can use the following to keep the dash, but get a number to work with.
Assume cell A1 has got the value 10-. We can use the FIND function to work out where the - occurs and then use the LEFT function to only return the characters from before the dash:
=LEFT(A1,FIND("-",A1)-1)
This will return the value 10, but it will return it as a string, not a number - basically Excel will think it is text. To force Excel to consider it as a number, we can simply multiply the value by one. Our formula above therefore becomes:
=(LEFT(A1,FIND("-",A1)-1))*1
You may also see people use a double minus sign, like this:
=--LEFT(A1,FIND("-",A1)-1)
I don't recommend this because it's a bit complex, but combining with the formula above would give:
=IF(MEDIAN(B5,--LEFT(B1,FIND("-",B1)-1),--LEFT(C1,FIND("-",C1)-1)-1)=B5,B2,IF(MEDIAN(B5,--LEFT(C1,FIND("-",C1)-1,--LEFT(D1,FIND("-",D1)-1-1)=B5,C2,IF(MEDIAN(B5,--LEFT(D1,FIND("-",D1)-1,--LEFT(E1,FIND("-",E1)-1-1)=B5,D2)))

Related

Excel percentage increase based on formula

I am trying to fill the sell price column in an Excel spreadsheet with the increased values in colors based on the round up columns value (1 to 50 green, 50 to 100 blue, 100 to 150 yellow, 150+ pink).
I've opted for the percentage table because some items can be sold for a lot more than what I have purchased them for, so that's just for my benefit. I am open to any other suggestions and I am new to this whole business thing.
I was using IF in my formula which would work great for using one percentage increase in the formula:
=IF($E27<50,ROUNDUP(I$27,-1))
If I try to enter a second argument like
=IF(OR($E28<50,ROUNDUP(I$28,-1)OR($E28>50,<100,ROUNDUP(J$28,-1))))
I will get an error.
I'm probably using the formulas wrong, I've tried "AND" and a couple other formulas, but I can't find anyone else trying to achieve the same or similar.
So something like this:
=IF($E28<50,ROUNDUP(I$28,-1),IF($E28>50,ROUNDUP(J$28,-1),"Error"))
But not sure what the <100 was for.
Although the problem is not completely clear, I understand that you want to add a formula with nested if statements.
I will recommend you to try nested ifs in parts.
=IF($E27<50,ROUNDUP(I$27,-1),"First if condition is false")
If everything is working as per the requirement then edit that text in the formula to add another if statement.
=IF($E27<50,ROUNDUP(I$27,-1),IF(OR(condition 1, condition 2,more conditions),"value if true","value if false"))
In the second argument provided by you, the arguments of the OR function has not been properly provided. Ensure that all the arguments of an OR function are conditions separated by a comma.
$E28<50 This is a condition so it's ok.
But other arguments are not making sense.
Also, using OR multiple times inside the first OR arguments is not clear.
It would be beneficial if you could provide the basic table and mention the requirement clearly.

Greater Than, Less Than, IF formula + Extra Condition

I wrote an IF formula as follows...
=IF(AB2>=500000,"Platinum",IF(AB2>100000,"Gold",IF(AB2>0,"Silver","")))
This works perfectly fine, however I've been given a new caveat and I haven't been able to figure it out.
If Column labeled Sponsor (see below image) has a value, then it should become a "Platinum" tier.
So pretty much, I'm seeing if it's possible add this additional condition to my existing formula. Any help would be greatly appreciated!
You can just add an OR() to the IF statement that you already have.
=IF(OR(AB2>=500000,AA2<>""),"Platinum",IF(AB2>100000,"Gold",IF(AB2>0,"Silver","")))
=If(LEN(AA2)<> 0,"Platinum",if(AB2>50000,"Platinum .... etc.
However, your logic is going to get a bit twisted with the many nested IFs. You might instead consider using a CHOOSE > MATCH structure, thus:
=IF(LEN(AA2)<> 0,"Platinum",CHOOSE(MATCH(AB2,{0,100000,500000},1),"Silver","Gold","Platinum"))
This formula first checks to see if there's a sponsor, and if there is sets it to "Platinum"; if there isn't it proceeds to the CHOOSE(MATCH.
The MATCH looks for the largest number in the array (i.e., {0, 100000, 500000}) that is less than or equal to the value in AB2, and returns an index number for where it finds the match. The CHOOSE then selects that entry from the list and returns it.

Excel functions: indirect address column

First time asking a question after reading a lot in the past.
I'm running the following array function excel:
INDEX('Available Options'!$A$1:$CM$137,$B$1,
SMALL(
IF(
INDIRECT("'Feasibility Options'!"&ADDRESS($B$1,COLUMN('Feasibility Options'!$G$1),1,1)&":"&ADDRESS($B$1,COLUMN('Feasibility Options'!$O$1),1,1))=2,
COLUMN(INDIRECT("'Feasibility Options'!"&ADDRESS($B$1,COLUMN('Feasibility Options'!$G$1),1,1)&":"&ADDRESS($B$1,COLUMN('Feasibility Options'!$O$1),1,1)))),
ROW('Available Options'!1:1)))
The idea behind this is that there are a number of cells which either have 1s, 2s or 3s in (1 means default, 2 means an alternative and 3 means inactive) in a separate tab called 'Feasibility Options', and the prices for these options are held in the 'Available Options' tab. $B$1 contains a row number produced through a separate calculation.
Evaluating this formula gives a value error when resolving the Indirect part of the function, but the function works if I replace the column number formulae with column numbers as below:
INDEX('Available Options'!$A$1:$CM$137,$B$1,
SMALL(
IF(INDIRECT("'Feasibility Options'!"&ADDRESS($B$1,7,1,1)&":"&ADDRESS($B$1,15,1,1))=2,COLUMN(INDIRECT("'Feasibility Options'!"&ADDRESS($B$1,7,1,1)&":"&ADDRESS($B$1,15,1,1)))),ROW('Available Options'!1:1)))
Could someone explain why this would happen and how to fix it? I ideally need to use cell references rather than hardcoded column numbers as I will likely need to add more columns in at a later date.
Thanks for any help you can give and apologies if I've missed a previous thread which answers this sort of question.
I haven't tested this but I suspect the problem is caused by the COLUMN function which returns an array (even for a single value) and sometimes Excel has trouble processing this:
You can normally make it work by wrapping COLUMN in a SUM or MAX function, e.g.
MAX(COLUMN('Feasibility Options'!$G$1))
or using COLUMNS function instead, something like
COLUMNS('Feasibility Options'!$G$1:G1)
which can be dragged to increment
Better still would be to replace the whole INDIRECT/ADDRESS parts with INDEX, which should be simpler, shorter and more efficient. I can give you more detail on that if you're interested

SumProduct Using Multiple Criteria Returning Too Much Data

Although this question has been asked and answered, (Stack Overflow is where I learned how to implement SP), an issue has come up which I can't figure out.
I'm using SP to sum shipments within a pivot table using a product number (with wild-cards), and a specific date. For instance, part numbers can be "AX10235-HP", "AX11135-HP", "AX10235-HP2", "AX10235-HPSPARE" or TP10101-IBM. (There are a large variety of numbers.)
So in this case I want to sum the qty shipments of "AX???35-HP". I wish to sum just the first 2 parts in my short list. However, the command used causes all the parts to sum except the *-IBM number; as if there was a wild-card at the end of the number. In other words "AX???35-HP" is the same as "AX???35-HP*". I've tried wrapping the value in quotes but it takes uses the quotes literally so fails.
This is the function
SUMPRODUCT((S_PART_DATA)*(ISNUMBER(SEARCH($A6,S_PART_RANGE))*(S_PART_DATES=T$4)))
S_PART_DATA array of Shipments,
S_PART_RANGE array of list of part numbers,
S_PART_DATES array of Dates shipments were made
It works the way you describe because SEARCH function finds $A6 within other text, hence it may not be an exact match - better to use SUMIFS function like this:
=SUMIFS(S_PART_DATA,S_PART_RANGE,$A6,S_PART_DATES,T$4)
Assuming all named ranges are the same size and A6 contains the value AX???35-HP
If that doesn't work try this version
=SUMPRODUCT(S_PART_DATA*ISNUMBER(SEARCH("^"&$A6&"^","^"&S_PART_RANGE&"^"))*(S_PART_DATES=T$4))
concatenating the ^ values means you will [probably] only get exact matches

Sharepoint: Calculated Column replace all spaces

Seems like it would be a simple thing really (and it may be), but I'm trying to take the string data of a column and then through a calculated column, replace all the spaces with %20's so that the HTML link in the workflow produced email will actually not break off at the first space.
For example, we have this in our source column:
file:///Z:/data/This is our report.rpt
And would like to end up with this in the calculated column:
file:///Z:/data/This%20is%20our%20report.rpt
Already used the REPLACE, and made up a ghastly super nested REPLACE/SEARCH version, but the problem there is that you have to nest for EACH potential space, and if you don't know how many up front, it doesn't work, or will miss some.
Have any of you come across this scenario and how did you handle it?
Thanks in advance!
As far as I know there is no generic solution using the calculated-column syntax. The standard solution for this situation is using an ItemAdded (/ItemUpdated) event and initializing the field value from code.
I was able to solve this issue for my circumstances by using a series of calculated columns.
In the first calculated column (C1) I entered a formula to remove the first space, something like this:
=IF(ISNUMBER(FIND(" ",[Title])),REPLACE([Title],FIND(" ",[Title]),1,"%20"),[Title])
In the second Calculated column (C2) I used:
=IF(ISNUMBER(FIND(" ",[C1])),REPLACE([C1],FIND(" ",[C1]),1,"%20"),[C1]).
In my case, I wanted to encode upto four spaces, so I used 3 calculated columns (C1, C2, C3) in the same fashion and got the desired result.
This is not as efficient as using a single calculated column, but if SUBSTITUTE will not work in your SharePoint environment, and you cannot use an event handler or workflow, it may offer a workable alternative.
I actually used a slightly different formula, but it was on a work machine to which I don't have access at the moment, so I just grabbed this formula from a similar S.O. question. Any formula that will replace the first occurrence of a space with "%20" will work, the trick is to a) make sure the formula returns the original string unchanged if it does not have more spaces in it, and b) test, test, test. Create a view of your list that has the field you are trying to encode, plus the calculated fields, and see if you are getting the results you want.
so that the HTML link in the workflow produced email will actually not break off at the first space.
The browser only does this if you have not enclosed your link in quotes
If you wrap the link in quotes, it does not cut off at the first space
In a SharePoint Formula it would be:
="""file:///Z:/data/This is our report.rpt"""
becuase two quotes are the SP escape notation to output a quote
You can use this formula (Start trim for 1, in my case was 4):
=IF(ISBLANK([EUR Amount]),"",(TRIM(MID([EUR Amount],4,2))&TRIM(MID([EUR Amount],6,2))&TRIM(MID([EUR Amount],8,2))&TRIM(MID([EUR Amount],10,2))&TRIM(MID([EUR Amount],12,2))&TRIM(MID([EUR Amount],14,2)))*1)

Resources