excel nested vlookup function using formats and NA Arguments - excel

I placed an example below, of which I don't necessarily 'need' to work, but I don't like that I can't get it to work. I've attempted to use the ISNA function, but am having little success since I
=IF(VLOOKUP(H3,Credit!H:J,3,FALSE)=(J3*-1),"Please Purge",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)<(J3*-1),"Not enough Credit... research",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)<(J3*-1),"Additional Credit… Research","No Credit Exists")))
I really would like to have a response to each formula, am I using the wrong functions or the wrong format?

To avoid repeating the VLOOKUP function multiple times you can use SIGN and CHOOSE in this scenario like this
=CHOOSE(SIGN(VLOOKUP(H3,Credit!H:J,3,FALSE)+J3)+2,"Not enough Credit... research","Please Purge","Additional Credit… Research")
If you add the VLOOKUP result to J3 you will get a negative number, zero or a positive number, SIGN function will return -1, 0 or 1 respectively for those and then adding 2 gives 1, 2 or 3 so we can use CHOOSE function to convert 1,2 or 3 to the relevant text value
That formula still gives #N/A error if H3 isn't found in Credit!H:H so to avoid that use IFERROR function (assumes Excel 207 or later), so final version becomes:
=IFERROR(CHOOSE(SIGN(VLOOKUP(H3,Credit!H:J,3,FALSE)+J3)+2,"Not enough Credit... research","Please Purge","Additional Credit… Research"),"No credit exists")

perhaps
=IF(ISNA(MATCH(H3,Credit!H:H,0)),"No Credit Exists",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)=(J3*-1),"Please Purge",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)<(J3*-1),"Not enough Credit... research","Additional Credit… Research")))
the MATCH part looks for the value H3 in Credit!H:H and if it isn't there the ISNA handles the resulting error and returns "No credit exists"; the rest is basically just a tweak of the original formula

Related

Excel formula to allow me to retrieve the codes of the most valuables drinks

Good night,
I'm trying to think of a simple excel formula to allow me to get the codes of the most valuables drinks.
I don't wanna use PivotTable for this one.
Ex:
I want to retrieve, for MALIBU, the code 8991
For JAMESON, the code 6113 etc
I'm stuck here since I woke up haha
Thanks!
Try below formula for dynamic spill result-
=LET(x,UNIQUE(C2:C12),y,BYROW(x,LAMBDA(r,INDEX(SORT(FILTER(A2:B12,C2:C12=r),2,-1),1,1))),HSTACK(x,y))
Using MAX function to consider the scenario where more than one code for a given drink can have the maximum value. In cell E2 use the following formula:
=LET(rng, A2:C13, codes, INDEX(rng,,1), values, INDEX(rng,,2),
drinks, INDEX(rng,,3), drinksUx, UNIQUE(drinks),
maxValues, BYROW(drinksUx, LAMBDA(ux,
TEXTJOIN(",",,FILTER(codes, (drinks = ux)
* (values = MAX(FILTER(values, drinks=ux))))))),
HSTACK(drinksUx, maxValues)
)
Here is the output:
Note: Another code for HEINEKEN was added for testing purpose of more than one code with maximum value.
XMATCH can be used for the same purpose too, but it is a more verbose formula:
=LET(rng, A2:C13, codes, INDEX(rng,,1), values, INDEX(rng,,2),
drinks, INDEX(rng,,3),drinksUx, UNIQUE(drinks),
maxValues, BYROW(drinksUx, LAMBDA(ux, TEXTJOIN(",",,
LET(maxValue, MAX(FILTER(values, drinks = ux)),
FILTER(codes, ISNUMBER(XMATCH(drinks & values, ux & maxValue))))))),
HSTACK(drinksUx, maxValues)
)

Excel customer data validation for chars and numbers

I am trying to validate a combination of char and numbers that looks like this XXXX0000000.
I have tried this formula; =OR((LEFT(B2,3)="XXXX",LEN(B2)=11),AND(LEFT(B2,3)="XXXX",LEN(B2)=11).
The error message I receive is as follows:
excel error message
Title: "Excel customer data validation for chars and numbers"
...I have the feeling it's not just about validating XXXX0000000 but it's about the pattern of characters and numbers. Therefor try:
Formula in B1:
=IF(ISERROR(FILTERXML("<t><s>"&A1&"</s></t>","//s[translate(substring(.,1,4), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','')=''][string-length()=11][substring(.,5)*0=0]")),"Invalid","Valid")
Where:
//s[translate(substring(.,1,4), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','')=''] - Check if when we translate the first 4 characters to nothing this also equals empty string;
[string-length()=11] - Check that node is 11 characters long;
[substring(.,5)*0=0] - Check that substring from 5th position onwards equals zero when multiplied by zero.
Note: FILTERXML() is case sensitive and is currently checking for uppercase alpha-chars.
EDIT:
To use this in data-validation; Ditch the IF() since you don't need that in validation and nest the remainder in NOT():
=NOT(ISERROR(FILTERXML("<t><s>"&A1&"</s></t>","//s[translate(substring(.,1,4), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','')=''][string-length()=11][substring(.,5)*0=0]")))
When you select your range, make sure the validation rule has the topleft cell in the reference.
You have two formulas but no joining of them
IE you have an OR formula
=OR((LEFT(B2,3)="XXXX",LEN(B2)=11)
Which will return a true/false answer
You also have an AND formula
=AND(LEFT(B2,3)="XXXX",LEN(B2)=11)
Which will return a true/false answer
when you work through it you are being given a return of:
=True(or false), true (or false)
That isn't a formula and is causing the error output
I think you want to use an IF statement to join them and get an output as desired:
E.g.
=If(OR(LEFT(B2,3)="XXXX",LEN(B2)=11),AND(LEFT(B2,3)="XXXX",LEN(B2)=11), DO SOEMTHING IF TRUE, DO SOMETHING IF FALSE)
I suggest this:
OR(LEFT(B2,3)="XXX",LEN(B2)=11,AND(LEFT(B2,3)="XXX",LEN(B2)=11))
It corrects the number of characters error and sorts the logic.

COUNTIFS counting double amount of values

I've got the following formula that works correctly
=SUM(COUNTIFS(MachineData!N:N,{"*Arlington*","*RenewNorfolk*"}, MachineData!$X:$X,"Y"))
but now if I try to do the same but with "not arlington or not renewnorforlk" I get the wrong answer (it counts double the amount of values that I want to count)
=SUM(COUNTIFS(MachineData!N:N,{"<>*Arlington*","<>*RenewNorfolk*"}, MachineData!$X:$X,"Y"))
what is happening here?
Your first statement is equivalent to
=COUNTIFS(MachineData!N:N,"*Arlington*", MachineData!$X:$X,"Y") + COUNTIFS(MachineData!N:N,"*RenewNorfolk*", MachineData!$X:$X,"Y")
where the array constant is manually split into it two constituent parts.
If you try this with the second statement
=COUNTIFS(MachineData!N:N,"<>*Arlington*", MachineData!$X:$X,"Y") + COUNTIFS(MachineData!N:N,"<>*RenewNorfolk*", MachineData!$X:$X,"Y")
we can see that anything that isn't either Arlington or RenewNorfolk gets counted by both COUNTIFS statements, which isn't what we want the result to be.
The simplest solution is to use
=COUNTIFS(MachineData!N:N,"<>*Arlington*", MachineData!N:N,"<>*RenewNorfolk*", MachineData!$X:$X,"Y")
which requires all the criteria to be met for a data item to be counted.

Logic evaluation problem in SUMPRODUCT Formula

I am using a formula based on SUMPRODUCT, SUBTOTAL, and OFFSET. To enable count of visible rows only with criteria. I a trying it on a simple sample data which as follows. Data starts from B4 in the Range B4:B12 Header B3:
B Column
HD
2
2
4
6
2
1
8
9
2
Formula is :
=SUMPRODUCT((B4:B12=B4)*(SUBTOTAL(103,OFFSET(B4,ROW(B4:B12)-MIN(ROW(B4:B12)),0))))
It gives correct result of 4 counts for a value of 2.
I went for evaluation of the formula to fully understand its logic. I could comprehend major part of its logic but certain steps are not quite clear to me. I am reproducing evaluation steps below with my comments.
Step -1
=SUMPRODUCT(({2;2;4;6;2;1;8;9;2}=2)*(SUBTOTAL(103,OFFSET(B4,ROW(B4:B12)-MIN(ROW(B4:B12)),0))))
OK
Step -2
=SUMPRODUCT(({TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;TRUE})*(SUBTOTAL(103,OFFSET(B4,ROW(B4:B12)-MIN(ROW(B4:B12)),0))))
OK
STEP-3
=SUMPRODUCT(({TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;TRUE})*(SUBTOTAL(103,OFFSET(B4,ROW(B4:B12)-MIN(ROW(B4:B12)),0))))
OK
STEP-4
=SUMPRODUCT(({TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;TRUE})*(SUBTOTAL(103,OFFSET($B$4,{4;5;6;7;8;9;10;11;12}-MIN({4;5;6;7;8;9;10;11;12}),0))))
OK
STEP-5
=SUMPRODUCT(({TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;TRUE})*(SUBTOTAL(103,OFFSET($B$4,{4;5;6;7;8;9;10;11;12}-4),0))))
OK
STEP-6
=SUMPRODUCT({TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;TRUE}*(SUBTOTAL(103,OFFSET($B$4,{0;1;2;3;4;5;6;7;8},0))))
Why {0;1;2;3;4;5;6;7;8} ??
STEP-7
=SUMPRODUCT({TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;TRUE}*(SUBTOTAL(103,{#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;})))
Why {#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;} ??
STEP-8
=SUMPRODUCT({TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;TRUE}*({1;1;1;1;1;1;1;1;1}))
How 1 instead of #VALUE!
STEP-9
=SUMPRODUCT({1;1;0;0;1;0;0;0;1})
OK
Step -10
4
OK
I am not having full clarity on the following points
STEP-6 : Why {0;1;2;3;4;5;6;7;8}
STEP-7: Why {#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;}
STEP-8: How 1 instead of #VALUE!
Hope Someone helps in clarifying the logic behind these mentioned spots. Please forgive me for asking clarity on such a trivial matter.
STEP-6 : Why {0;1;2;3;4;5;6;7;8}
Because the {4;5;6;7;8;9;10;11;12}-4 evaluates to {4-4;5-4;6-4;7-4;8-4;9-4;10-4;11-4;12-4} which is {0;1;2;3;4;5;6;7;8}
STEP-7: Why {#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!}
The formula evaluator fails getting the values out of the 9 cell references got via OFFSET($B$4,{0;1;2;3;4;5;6;7;8},0) = {$B$4;$B$5;$B$6;$B$7;$B$8;$B$9;$B$10;$B$11;$B$12} in array context. But that does not matter because:
STEP-8: How 1 instead of #VALUE!
the SUBTOTAL(103,... is a COUNTA subtotal which, for each single cell reference of the 9 cell references got in step 7, counts 1 if it is not hidden, else 0. So it does not matter whether the cell values was evaluated or not.
Btw.: The same can be achieved using
=SUMPRODUCT((B4:B12=B4)*(SUBTOTAL(103,INDIRECT("B"&ROW(B4:B12)))))
Annotation:
Such formulas are result of trial and error. I doubt any Excel programmer was able predicting all usages of the functions they implemented. There are usages of Excel functions in the wild which are as much thought outside the box that they originally could not have thought so.
Bonus:
=SUMPRODUCT(OFFSET(B4,ROW(B4:B12)-MIN(ROW(B4:B12)),0))
results in 0 using your values in B4:B12.
Here the formula evaluator also fails getting the values out of the 9 cell references got via OFFSET($B$4,{0;1;2;3;4;5;6;7;8},0) = {$B$4;$B$5;$B$6;$B$7;$B$8;$B$9;$B$10;$B$11;$B$12} in array context. And the result is {#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!}. But now it matters because we need the values.
In that case we can use N function to force getting the values
=SUMPRODUCT(N(OFFSET(B4,ROW(B4:B12)-MIN(ROW(B4:B12)),0)))
This results in 36, the sum of your values in B4:B12.

Countif function not acting how I would expect

So I have an excel function where I want to check to see if a string contains any of the strings mentioned, if it does, simply add 1 to the total, here's what I have:
=COUNTIF(C2:F2, "*offline")+COUNTIF(C2:F2, "*Expired")+COUNTIF(C2:F2, "*login")+COUNTIF(C2:F2, "*log in")
So for example if C2 says "login" D2 says "offline" , this function would only show "1".
Examples using just one Countif
If you want to count 1 then here is an example
=IF(SUM(COUNTIF(C2:F2, {"*offline","*Expired","*login","*log in"}))>0,1,0)
If you want to count all instances then change the above formula to
=SUM(COUNTIF(C2:F2, {"*offline","*Expired","*login","*log in"}))
Screenshot
So, you don't really want a count, you just want to know if any of those cells have one of the values you're looking for?
Surround your function in an if statement and print 1 if it has a count at all.
=IF(COUNTIF(C2:F2, "*offline")+COUNTIF(C2:F2, "*Expired")+COUNTIF(C2:F2, "*login")+COUNTIF(C2:F2, "*log in"),1,0)

Resources