Excel Formula Slow - excel

is there anything i can do to further improve performance of this formula ?
=IF($A3<>"",IF(Jan!$E6<>"",LET(d_patt,IF(Jan!$E6<>"",VLOOKUP(Jan!$E6,SETTINGS!$A$12:$B$27,2,FALSE)&IF(Jan!$B6<>"",Jan!$B6,0)&IF(Jan!$C6<>"",Jan!$C6,0)&IF(Jan!$D6<>"",Jan!$D6,0),""),"ROT"&IF(LEN(Teams!$BHR4)>0,MID(Teams!$BHR4,MOD(NETWORKDAYS.INTL(Teams!$C4,I$2,"0000000")-1,LEN(Teams!$BHR4)/3)*3+1,3),"000")&IF(LEFT(d_patt,3)="OVT",d_patt,"OVT000")&IF(LEFT(d_patt,3)="SSI",d_patt,"SSI000")&IF(LEFT(d_patt,3)="SSO",d_patt,"SSO000")&IF(LEFT(d_patt,3)="SDS",d_patt,"SDS000")&IF(LEFT(d_patt,3)="HOL",d_patt,"HOL000")&IF(LEFT(d_patt,3)="LID",d_patt,"LID000")&IF(LEFT(d_patt,3)="UNP",d_patt,"UNP000")&IF(LEFT(d_patt,3)="FLD",d_patt,"FLD000")&IF(LEFT(d_patt,3)="MAT",d_patt,"MAT000")&IF(LEFT(d_patt,3)="LIS",d_patt,"LIS000")&IF(LEFT(d_patt,3)="CBR",d_patt,"CBR000")&IF(LEFT(d_patt,3)="ABS",d_patt,"ABS000")),"ROT"&IF(LEN(Teams!$BHR4)>0,MID(Teams!$BHR4,MOD(NETWORKDAYS.INTL(Teams!$C4,I$2,"0000000")-1,LEN(Teams!$BHR4)/3)*3+1,3),"000")&"OVT000SSI000SSO000SDS000HOL000LID000UNP000FLD000MAT000LIS000CBR000ABS000"),"")
i have this on a sheet for each day of the year x 400 people so 146k+ times. this is therefor taken up 80% of the sheet load time.
The sheet basically gets shift patters from Teams, check if there is any holidays, overtime etc from the relevant month tab and relevant cell for the day, and then will generate a code like below.
ROT080OVT000SSI000SSO000SDS234HOL000LID000UNP000FLD000MAT000LIS000CBR000ABS000
i have so far managed to make this faster by using the LET function, but not show if its possible to make any further improvements.
if you need an example file i can send this or upload somewhere, not sure if that is possible via stackoverflow or a preferred site to upload to.
Thanks

The following is a shortened version of your formula to reduce the complexity of computations.
Instead of building the 'OVT000SSI000...' string one piece after another while always checking if the first 3 characters of 'd_patt' match the current piece, we can set the whole string with '000's as default and only replace the section that matches 'd_patt' (see highlighted elements in screenshot below)
Which results in the full formula:
=IF(LEN($A3)>0,"ROT"&IF(LEN(Teams!$BHR4)>0,MID(Teams!$BHR4,MOD(NETWORKDAYS.INTL(Teams!$C4,I$2,"0000000")-1,LEN(Teams!$BHR4)/3)*3+1,3),"000")&LET(default,"OVT000SSI000SSO000SDS000HOL000LID000UNP000FLD000MAT000LIS000CBR000ABS000",d_patt,VLOOKUP(Jan!$E6,SETTINGS!$A$12:$B$27,2,FALSE)&IF(LEN(Jan!$B6)>0,Jan!$B6,0)&IF(LEN(Jan!$C6)>0,Jan!$C6,0)&IF(LEN(Jan!$D6)>0,Jan!$D6,0),IF(LEN(d_patt)>0,REPLACE(default,SEARCH(LEFT(d_patt,3),default),6,d_patt),default)),“”)
If $B6, $C6 and $D6 can only be either empty or a numerical number, in other words, if they are never a letter or special character, the 'd_patt' function can be further shortened as follows:
Which results in the full formula:
=IF(LEN($A3)>0,"ROT"&IF(LEN(Teams!$BHR4)>0,MID(Teams!$BHR4,MOD(NETWORKDAYS.INTL(Teams!$C4,I$2,"0000000")-1,LEN(Teams!$BHR4)/3)*3+1,3),"000")&LET(default,"OVT000SSI000SSO000SDS000HOL000LID000UNP000FLD000MAT000LIS000CBR000ABS000",d_patt,VLOOKUP(Jan!$E6,SETTINGS!$A$12:$B$27,2,FALSE)&(Jan!$B6+0)&(Jan!$C6+0)&(Jan!$D6+0),IF(LEN(d_patt)>0,REPLACE(default,SEARCH(LEFT(d_patt,3),default),6,d_patt),default)),“”)

Related

How to identified the smaller number only from specific lines of a table

I am not familiar with excel as you can probaly guess by my question so I am sorry if it's a silly question but I have been googling for a long time and I can't do it.
I manage to do it in excel 365 with the function filter, but I can't on excel 2019 (I am required to do it in excel 2019)
I want to identifed the smaller number of a specific combination of cells using two table.
Table1 has name of people and places as well as a number. (the number shows the difference of the last time a person went to a place and the [in months])
(In this project the inspector cannot go to the same place twice unless 4 months have pass, thus why I want the smaller number, using the date of the last visited and the fcuntion now I get teh number of months that have pass)
Table2 has only the name of one person out of these people but has the name of all places. I want to get the smaller number for every place.
This is my table1: (I hided other peoples names so I can show a more compact examlplo)
And this is my table2:
I thought that I could use a function aggregate with a function if inside of it to get only the values that I desire.
It did not worked thou. Was I had miss undertand the fact that function if only gives me true or false. But thought that the aggregate function could wordk. It did not as well
=AGGREGATE(5;3;A2&B2=Table1[#Place]&Table1[#name];1).
overall my question could be summarize to which funtion should I used?
Which function should I use?
obs: In excel 365 I used concat to make a code an thus only used one cell, but I don't see why it wouldn't work if I just select two cells insted of one (teh concat cell)

Create an Excel Formula that uses filtered data

I'm trying to design a second page that shows % results of my data on page 1.
For example, Column F & G allow manual entry of numbers 1-4 which are based off data the user types in at another location.
This is being used for trade tracking in investments so there will be quite a few numbers but the end result will be a row will show a specific stock, it's subsequent data, whether it made or lost money, etc.
What I want to do in page 2 is using the numbers 1-4 which were typed in at columns F & G, translate that into an edge on page 2.
For example, if there were 50 columns of data typed out for trades executed, I could take the number of winning trades of a certain setup (say number 3) and divide that by the total trades of 50 to come out with a win % for that setup.
However, I have no clue to how to translate that forumla into a filter formula so that on page 2 I could see that of the numbers 1-4 (4 different setups) I could easily see the highest and lowest win % to determine the best setup to use.
I'm not the best in excel but I understand enough to code most of that, I simply have no idea how to take that end formula and add a filter to it so that it only uses partial results. I've got 4 other formulas I want to use on page 2 as well to help build something that could really benefit myself, but if someone could just show me how to filter data into a formula, I think I could take it form there.
Thanks for the help
Ben
You can also do something like this with array formulas
=MAX(IF(Sheet1!$F$2:$F$50=$A2,$E$2:$E$50))
(Press Ctrl+Shift+Enter [CSE], instead of just Enter when entering Array Formulas)
Also, take a look a the SUMPRODUCT function. It comes in very handy for filtering data. Here are some helpful links...
https://www.get-digital-help.com/2017/12/07/sumproduct-multiple-criteria/
https://www.get-digital-help.com/2017/12/08/sumproduct-and-if-function/
https://www.get-digital-help.com/2010/09/01/extract-a-unique-distinct-list-by-matching-items-that-meet-a-criterion-in-excel/

How to use "IF" code with multiple conditions?

I have 5 columns of data with around 50,000 rows. This is the ambulance response times to an incident. I am trying to figure out the total number of incidents as multiple ambulances respond to a single incident. The 'IF' function has been useful upto a certain extent where the multiple ambulances reached at the same time but when it is not at the same time, it considers it as a different incident. I would like to add a buffer of 20 minutes but I am not able to figure out how to incorporate that. The second problem is with the incident number. The incidents 2014-014374-006, 2014-014374-009 are the same, just the ending numbers are different. How do I differentiate? Can I do it in excel or other platforms?
http://imgur.com/a/30VHl
To return the incident number, use a formula like this: "=IF(ISERROR(SEARCH("-",D5,SEARCH("-",D5)+1)),D5,LEFT(D5,SEARCH("-",D5,SEARCH("-",D5)+1)-1))" where D5 is the cell with your incident number.
What this formula does is it first creates an if statement that will allow you to determine if the incident has the second dash or if it doesnt. If it doesn't, then it will return the value in the cell. If it does, it will return the text to the left of that dash. The search function looks for a substring, and by nesting a search and adding "1" to the value of the first search, we are looking for the substring that comes after the first one is found.
It is a rather confusing formula the first time you use it, but it works like a charm once you understand it.
I will see if I can figure the dates out. That might be more difficult. If you can simply use the incident number for this, you will likely have an easier time.

Finding the right range from excel table

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)))

Excel can't find a value even though it exists within the worksheet

this is my first post so i am sorry if this is confusing at all. I am trying to use a vLookup to run a comparative analysis between two reports. I am using a part number as a reference and trying to return the cost associated with the part from one of the two reports. So, the first issue that I encountered was due to the fact that some of the part numbers had letters in them and some didn't, so to be consistent I used the following code to clean up the part numbers:
IFERROR(VALUE(F11&C11), F11&C11)
where F11 and C11 are two components of the part number that needed to be concatenated to generate the full number. Now, the vLookup will not return anything except for #N/A for a few of the part numbers that are actually in the sheet. All of the part numbers are formatted the same for the 892 part numbers that I am searching for but get a returned value on 571 of the 892 part numbers but of the remaining 321 part numbers that did not have a return, about a third actually exist in my sheet. Lastly and for example, part number 110874402 exists in both sheets but gets a #N/A from the vLookup. When I copy the value from one sheet and search it in the other sheet using Ctrl + F, I get the following:
(I have an image to show but apparently can't post it without a reputation of 10 or more...oops)
The highlighted cell shows that the value exists but Excel can't find it. Does anyone have any ideas why this is or what I could be doing differently? I've been having this issue for a few months now on separate projects and haven't found any resolution.
Thanks in advance,
try =VLOOKUP("*"&TRIM(F569)&"*", BOBJ!$D$3:$P$2237, 7, FALSE) - I have a feeling spaces may have crept around the part numbers, which means that the exact match will not work.
The TRIM takes the spaces from the cell you are looking at, and the "*"'s will allow a wildcard search - note that this also means that CAT would also match CAT1, but if it produces results where there were none before, it gives you something to check for.

Resources