Create an Excel Formula that uses filtered data - excel

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/

Related

Excel Formula Slow

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)),“”)

VLOOKUP query help required - count from a range

I'm trying to build a spreadsheet to help automate points scoring for an office F1 fantasy league we have.
I've attached an example data set, but basically I need to search a range, then count how many times the constructor appears in the numbered positions (discounting R, D as they've not finished), then carry this over to the standings.
I also need to do something similar for the top 10 which says if 2 cars from the same constructor (Mercedes, Mercedes) appear in positions 1-10 then add points to the standings.
In the working model the data for race1 is direct from the BBC via web query, so how they appear with 'driver' in between is how it must remain (I also have other actions running which lookup the driver info, so can't be moved).
I've popped the example on my drive here and updated version.
You need to be consistent with spellings or this won't work, but for standings B2 you might try:
=IF(COUNTIFS(race1!C:C,A2,race1!A:A,"<>D",race1!A:A,"<>R")=2,20,IF(COUNTIFS(race1!C:C,A2,race1!A:A,"<>D",race1!A:A,"<>R")=1,7,-15))
and in C2:
=COUNTIF(race1!$C$2:$C$11,A2)*10
both copied down to suit.
Edit for number of cars in column B change first formula to:
=COUNTIFS(race1!C:C,A2,race1!A:A,"<>D",race1!A:A,"<>R")
and for points put first formula in C2 (copy both down to suit).

Break-Down Data in Excel without VBA (Formula Only)

Many times, I am required to provide some type of break-down to the customers - an example is shown in the attached figure.
I have a table of data ("TABLE DATA" - which is some type of pivot) + Customer provides its official form, its structure must be preserved (highlighted in yellow ). Basically, I need to separate the cost details of CODE "A" and CODE "B" into 2 separated sections.
Customer requires me to provided details for each individual Part (example shows Part A - "Break-Down Part A)
Is there anyway to put a"ITEM" from "TABLE DATA" into Code A and Code B ? the rests can be solved by Vlookup (Price, Quantity) - note: "ITEM" is non-duplicated values . Thank you very much
Number your rows in the breakout using =1 and =A1+1 and then just use the formula ="B-ITEM"&TEXT(A1,"000"). If you want to skip making a counter column you could use ="B-ITEM"&TEXT(ROW()-1,"000") to just use the current row number (minus 1 or however many you need).
If your items aren't sequentially like that, but still unique, I would recommend adding counters on the original tab similar to what you have, which would let you quickly find the 5th A or 7th B, something that counts the previous instances of your current type, and then adds 1. For Row 6 you could do =COUNTIF(A$1:A5,A6)+1.

IF-Then or Find Function w/ Excel

My apologies if this has already been answered in some form; it’s difficult to come up with the correct wording to do a proper search.
I have been charged with creating some basic reporting for my team and I need to create an “if-then” formula. Essentially, if Column A contains the word “Open Rate,” I want the formula to grab the associated percentage from column B (16.49%) and make an average of all the open rates on another sheet. (16.49% + 14.98% + 14.48% / 3 = 15.31%)
I would simply add all of them but the data set is ridiculously large and always growing. Also, the numbers of rows between data sets are not equal and thus a nice pattern is out of the question.
excel uses a vb type syntax
=IF(A2<>"open rate",A2,AVERAGE(Sheet2!A:A))
the above formula says if a2 is not equal to open rate, then return a2, else return the average of column A in sheet 2
Please try:
=AVERAGEIF(Sheet1!A:A,"=Open Rate",Sheet1!B:B)
with your first sheet name adjusted to suit, if necessary.
Edit re supplementary
Google Doc does not at the moment have a function =AVERAGEIF, however it does have the building blocks for it. Average (as in arithmetic mean) may be calculated as the sum of the values in a dataset divided by the count of all the individual items in the dataset:
=sumIF(Sheet1!A:A;"=Open Rate";Sheet1!B:B)/countIF(Sheet1!A:A;"=Open Rate")
Google Doc does have the =AVERAGE function and this may be more suitable than the above.

Excel: How to parse/cast text as a formula?

Is it possible to parse/cast text (like "=A1+A2") as a formula in MS Excel? I want to build a formula from pieces of text - some of which will only be typed in later by a user.
If the INDIRECT() function did not only work for referencing cells, then I could have typed this =INDIRECT("=A1+A2").
I know you can a work around this problem by simply adding a lot more hidden columns to do sub calculations. But for the sake scalability and efficiency, I would rather do something like the above.
I found a similar questions here and here, yet they don't solve my problem.
The Real-world problem:
Read on for a better understanding as to why you would want to do the above
Scenario
Each item in the list consists of a string, which contains anywhere from 1 to 5 account names each. Each account name is followed by an account number in brackets. The length of the number determines the type of account. Part of the account number is a date, of which the date format depends on the type of account. Further more, each account type may have more that 1 account-number length associated with it, although each number-length[*] is only associated with 1 account type.
Objectives
Extract account-names and their respective account-numbers and account-types from a list.
Make an assumption as to the account-type from the account-number
Validate this assumption by inspecting the build of the number and elements in the name
Check the validity of the account-numbers depending on their type.
The tricky part (this is where my problem lies)
The account-types and their respective account-number-lengths are not known before hand, and are typed into a table by the user of the sheet, specifying a type of account and the number-lengths associated with this account-type. The user should type this into a list - not go and tinker around with delicate formulas
Done so far
Column A: Contains the raw data (each cell has up to 5 names and numbers)
Columns B..F: Each column extracts 1 name, remains empty if all are already extracted
Columns G..K: Each column extracts 1 number corresponding to its name in columns B..F, remains empty if all are already extracted
Columns L..P: Each column calculates the length of the corresponding number in columns
G..K
Now the user would type the following details into a table which assigns certain number-lengths an account type:
TYPE2, BUSINESS, (OR(length=13,length=6))
where length will later be replaced with the cell address which contains the calculated account number-length.
What I want to do now
Columns Q..U:
Should all indicate the account-type of the corresponding account-number in columns G..K. The idea is to build a nested if-elseIf-elseIf formula using the criteria typed in by the user as specified above. Example of one of the elseIF statements:
SUBSTITUTE(CONCATENATE("=IF(",criteria,",",type,",",errCode)),"length","O10"))
All of these elseIf statements will then be concatenated together to form a master formula which will then need to be parsed/cast as a formula to calculate the account-type
This proposal uses only 5 columns (1 for each account-number, containing the master formula) and a table specifying account-types and criteria, also keeping the user away from formulas. Editing 1 line of code (the criteria) will update all formulas. Efficient & Scalable.
Since the user should never tinker around with the formulas under the hood, a simple 1 column if-elseIf-elseIf is out of the question. The alternative to the above would be to make a separate column to test for each account-type for each account-number. Separating/Abstracting out each test to its own column results in much better readability, easier editing & much less debugging - Unless you like multi-screen-wide-formulas. Example: 5 account-numbers * 10 possible account types = 50 extra columns.
Each edit to any criteria needs to copied to 4 other non-adjacent columns and drag-filled down 10,000 rows (columns can not be adjacent since it is effectively a 5x5 array of columns). Not Efficient nor scalable. Unless I'm missing some elegant way of updating non-adjacent formulas in a single click
The rest of the validations error indications are trivial.
Sample data
Tshepo Trust (6901/2005) Marlene Mead (8602250646085)
Great Force Inv 67 Pty Ltd (200602258007)
Jane (870811) Livingstone (6901/2005) Janette Appel (8503250647056) James (900111)
I know all this would probably be much easier to achieve with clever usage of VBA, eliminating all the need to simulate abstraction, encapsulation, multi-dimensional arrays and functional programming on a spreadsheet. But until I can program in VBA, worksheet formulas will be my refuge.
[*]: account number-length could also be described as the amount of digits in the number or as indicated by this formula: LEN(accNumber)
In VBA you have access to Cell.Formula.
I usually used Range to peek a cell by address.
I'm not sure if this would answer your question(it's a very detailed question!), but if your user was entering the account numbers in a table (I'm calling it 'RefTable') , that was:
Length of account number | business type
----------------------------------------
6 | Accountant
8 | Advisor
Then you could just use a vlookup on the length of the account number, given you've already separated them out.
=vlookup(len(accNumber), Reftable, 2, false)
Make sure that you either use a dynamic range name, or specify plenty of space below in RefTable, so that when your users add types, they don't get lost.
Also, if you have two different accounts with the same length, this could get you into trouble.

Resources