Is this process possible with an excel formula [duplicate] - excel

This question already has answers here:
VLookup with Multiple Criteria with VBA and the array formula method
(5 answers)
Closed 1 year ago.
I'm trying to create a sort of excel formula
1.) Go within a Table
2.) Identify all rows that contain “Specific first name” & “ Specific last name”
3.) Then, from those previously identified rows, identify if those rows also contain “Dental”
4.) If the row does contain “Dental” take the appropriate cell in THAT row that contains the dental amount, ( because the dental amount is not the cell directly after/to the right of the the cell that contains dental.
First name and last name will be cell references.
If I can create this formula, I plan to create a Macro that places this formula in the proper cells

Here/screenshot(s) refer:
<Response structured as follows: M1(a/b) sum/count followed by M2 (sum/count resp.).
M1 -- utilises 'Filter approach' recommended in commentary (#Tragamor) - will explore this first - per screenshot, M1 (cell O6):
NB: requires Office 365 compatible version of Excel (see M2 for different approach in this regard)...
=LET(q_,FILTER(Table1,--ISNUMBER(MATCH("*"&Table1[Fld0_type]&"*",Table3[Dental assoc.],0))*ISNUMBER(MATCH("*"&Table1[Fld2_Name]&"*",Table2[Names],0))),COUNT(INDEX(q_,,MATCH("*"&"cost"&"*",Table1[#Headers],0))))
Noting length may seem cumbersome but mainly attributable to field/table referencing preferences/convention (and dynamism)
Analogous count (P6) is provided for on similar basis/formulation:
**note omission RE: index 'row' argument -- purposeful as this (or 0 for that matter) generally returns all rows from data in question.
=LET(q_,FILTER(Table1,--ISNUMBER(MATCH("*"&Table1[Fld0_type]&"*",Table3[Dental assoc.],0))*ISNUMBER(MATCH("*"&Table1[Fld2_Name]&"*", Table2[Names],0))),COUNT(1*ISNUMBER(INDEX(q_,,MATCH("*"&"cost"&"*",Table1[#Headers],0)))))
M1(b) - outside of scope per commentary provided (screenshot above).
M2 - Absconds from filter method (CELL o8 as in 'oscar 8'):
=SUM(Table1[Fld 3_cost]*ISNUMBER(MATCH("*"&Table1[Fld0_type]&"*",Table3[Dental assoc.],0))*(ISNUMBER(MATCH(Table1[Fld2_Name],Table2[Names],0))))
Likewise, we have analogous 'count' record (cell p10):
=COUNT(1*(Table1[Fld 3_cost]*ISNUMBER(MATCH("*"&Table1[Fld0_type]&"*",Table3[Dental assoc.],0))*(ISNUMBER(MATCH(Table1[Fld2_Name],Table2[Names],0)))))
Notes:
Wildcard '*' in match functions (i.e. 'Tom' will match with Tomas (weird spelling for that name, normally has 'h' in it but all the same☺)

Related

Excel advanced vlookups for a schedule comparison

I wondering if anyone will be able to help me sort the formula below out:
=IFERROR((VLOOKUP($D96,August!$C:$P,F$78,FALSE))-(VLOOKUP($D96,July!$C:$O,(F$78+1),FALSE)),IF(U96="NEW PART",(VLOOKUP($D96,July!$C:$O,(F$78+1),FALSE)),IF(V96="NEW PART",(VLOOKUP($D96,August!$C:$O,(F$78),FALSE)),"")))
Originally the formula was
=IFERROR((VLOOKUP($D95,August!$C:$P,F$78,FALSE))-(VLOOKUP($D95,July!$C:$O,(F$78+1),FALSE)),"BLANK")
However rather than returning "BLANK" if either sheet does not include that part number I would like the formula to return the figure on the one sheet they appear on. Columns U and V highlight weather the product number is on each sheet. These figures would be + figures if they appear in august and minus figures if they appear in July.
Link/screenshot refer:
In short - replace final 'FALSE' with an additional iferror(Aug,-July)
(see revision at end, following comments / feedback re sound applications/customizing soln as required)..
Formula - per OP request
=IFERROR(VLOOKUP(H4,B4:C14,2,FALSE)-VLOOKUP(H4,E4:F14,2,FALSE),IFERROR(VLOOKUP(H4,B4:C14,2,FALSE),-VLOOKUP(H4,E4:F14,2,FALSE)))
Improvised version
(pre-requisite: Office 365 compatible version of Excel)
=LET(A,INDEX(C4:C14,MATCH(H4#,B4:B14,0)),B,INDEX(F4:F14,MATCH(H4#,E4:E14,0)),IFERROR(A-B,IFERROR(A,-B)))
Motive
Arguments in favour of this version include:
OP version: 127 chars (vs 104) i.e. ~20-25% length reduction on this basis
Audit/review - arguably easier given let function
Flexibility: unless you plan to take advantage of vlookup 'approximate matching' (using True flag instead of False), Index more robust in that it can handle forward and backward references in relation to the indexed column (i.e. with vlookup, index has to lie to left of the column comprising the cell to be returned)
The usual benefits assoc. with 'spill' ranges (i.e. potential for 'dynamic' range feature and automatic calc. from single cell entry)
REVISION:
The following screenshot should shed some light on references/ranges you may wish to alter for 1st formula in present response to operate as you intend within your workbook (corresponding ranges are colour-coded with clear visual link between each)...
So to apply in your case, you'd need to replace shaded/boxed ranges/references in my proposal with those you're using (as indicated - i.e. replace by H4 with your $D95 etc,..."
JB: replace final 'FALSE' with an additional iferror(Aug,-July)
This concept is clearly delineated within screenshot above.
OP: "I tried and just got N/A"
As link in opening line provides evidence of two alternative solns. working error-free, presume 'n/a' result of incorrect application...

Scorecard Question Part 1 - multiple IFs formula

my challenge is of 2 parts (2nd part was already responded by Michal Rosa and Lee Mac).
Here is part 1:
I am working on a scorecard which has series of references. I initially wrote a series of Nested IFs which was very long and also is tedious to change especially when targets change. How can I hardcode or create a formula where I can just change the targets/scoring matrix on the table
Please see sample data:
KRA Data
Say if the agent's LOB is Email, and is in a tenure of 61-90 Days, we return corresponding KRA Rating from the KRA Rating Matrix depending on Actual Score. Like for Agent 1, her Actual Closure score is 18.55 and corresponding KRA rating for her tenure of 61-90 Days is 4.
Similarly, for her TPH, her Actual TPH is 7.02, which assigns a KRA Rating of 3 in the Scorecard Rating Matrix.
You can use nested INDEX / MATCH :
For the outer one (i.e. the one that will find the rating), you use a MATCH which will match the nearest value in the table that is still less than value. You have to modify the look of your rating matrix, instead of putting 4.5 - 5.5, you have to put a single value, i.e. 4.5. You always start with the lowest possible value (typical 0 or minus something), and you end with the highest value.
With the inner one, you extract the array (row) from your matrix that matches both criteria (tenure and LOB), and this array will be fed into the outer match. As it is now, you have to use two formula's, one for the TPH and one for the closure. If your KPI would not be in merged cells, but on each row (like for Tenure and LOB), you could add another condition in the inner MATCH and do everything with a single formula.
The array formula (ctrl+shift+enter) is like this:
{=INDEX($C$1:$F$1;MATCH(D9;INDEX($C$2:$F$5;MATCH(1;($A$2:$A$5=$A9)*($B$2:$B$5=B9);0););1))}
This is a screenshot, starting from A1 (Tenure) and with the formula in F9. I used the colors of your spreadsheet to make it more visual.
This is the same formula with the cell and range references replaces by text so you can better understand and replace with the correct ranges of your worksheet. I hope it is self-explanatory, otherwise just ask:
=INDEX(The_rating;
MATCH(closure-rate_value;
INDEX(Matrix_with_closure-rate_cutoffs;MATCH(1;(LOB_column=LOB_value)*(Tenure_column=Tenure_value);0););1))

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