Excel - nesting the IF and AND function - if-statement

I was wondering if anyone could help with the following. I have found one question and answer relating to my query (I think!!) but I can't break it down to do what I want.
I have created a spreadsheet and used the IF & AND functions to do half of what I want.
Basically if the answer is "no" in one column and one of four options in another (111,112,118,119) I want it to bring in the value of C2. This is what I have come up with:
=IF(AND(E2= "No",F2=112),C2,0)
This part works fine but I also need it to bring in the value of C2 if "Yes" (E2) is selected AND the value of D2 is equal to F2 - this is what I have come up with
=IF(AND(E2="No",F2=111),C2,0),IF(E2 ="Yes",D2=F2,C2)
It doesn't work.
I found the answer linked at the top of the post, but my Excel skills aren't up to pulling it apart to fit what I want.

The reason you can't get the formula to work is because there are two separate formula thrown together in a cell:
=IF(AND(E2="No",F2=111),C2,0) - alone this is a complete formula and will return either C2 or 0.
If you want to nest your if statements you need to look at chaining them off each other: If([something],[do this],If([something else],[do this],If(... you get the point.
In terms of what you are trying to achieve there is a more effective method though, by using another formula, MATCH() that returns the position of a match in the list (array or range) you provide. You can just check whether the result of that formula is a number, like so:
=IF(AND(E2="No",ISNUMBER(MATCH(F2,{111,112,118,119}))),C2,0)
EDIT
So instead of providing 0 when the result of the AND() is false, we kick off another if that is your "Yes" clause... This then gives the 0 if it fails... Flip them round if you want "Yes" to be calculated first.
=IF(AND(E2="No",OR(F2=111,F2=112,F2=118,F2=119)),C2,IF(E2="Yes",D2=F2,0))
So the final result based off your comment would have been:
=IF(OR(AND(E2="Yes",D2=F2),AND(E2="No",OR(F2=111,F2=112,F2=118,F2=119))),C2,0)

Related

Google sheets - How to compare a formula within a cell with a string to spot changes in the formula?

I help a small business with an application which is entirely run from google sheets and google forms. The issue is that from time to time the business owner will go into the sheet and delete rows of old data. I've noticed that as a result, some of the formulas will change the row which they are looking at. This is despite me using explicit cell references such as $A$1 for example.
So what I would like to do, is use somehow compare the cell which contains the formula, with a string of what the formula should be, then return a value if the formula matches. I had thought an =If function would solve this but so far I am not having any luck.
This is what I have used so far:
Lets say cell A1 contains the formula I want to check and the formula is (this works fine): =FILTER(Dashboard!A2:A, Dashboard!C2:C1 = TODAY())*
I am using =IF(A1="=FILTER(Dashboard!A2:A, Dashboard!C2:C*1 = TODAY())",True,False)
I am expecting the function to compare the value of A1 with my string and return the value True. If the formula does not match the string it should return the value False.
I currently am returning the value of False despite the formula and string being an exact match. I assume this is because my =If statement is looking at the value returned by the =Filter function rather than the formula itself.
Any help would be appreciated.
thanks
You could just use INDIRECT() in the place of explicit cell ($A$1) reference you mentioned and that should solve the problem of formulas going haywire due to rows deletion in Form Responses tab. Please do test it out.
INDIRECT("Sheet!"&A1)
INDIRECT("A1")

How to automatically feed a cell value from a range of values, based on its matching condition with other cell value

I'm making a time-spending tracker based on the work I do every hour of the day.
Now, suppose I have 28 types of work listed in my tracker (which I also have to increase from time to time), and I have about 8 significance values that I have decided to relate to these 28 types of work, predefined.
I want that, as soon as I enter a type of work in cell 1 - I want the adjacent cell 2 to get automatically populated with a significance value (from a range of 8 values) that is pre-definitely set by me.
Every time I input a new or old occurrence of a type of work, the adjacent cell should automatically get matched with its relevant significance value & automatically get populated in real-time.
I know how to do it using IF, IFS, and IF_OR conditions, but I feel that based on the ever-expanding types of work & significance values, the above formulas will be very big, complicated, and repetitive in the future. I feel there's a more efficient way to achieve it. Also, I don't want it to be selected from a drop-down list.
Guys, please help me out with the most efficient way to handle this. TUIA :)
Also, I've added a snapshot and a sample sheet describing the problem.
Sample sheet
XLOOKUP() may work. Try-
=XLOOKUP(D2,A2:A,B2:B)
Or FILTER() function like-
=FILTER(B2:B,A2:A=D2)
You can use this formula for a whole column:
=INDEX(IFERROR(VLOOKUP(C14:C,A2:B9,2,0)))
Adapt the ranges to your actual tables in order to include in the second argument all the potential values and their significances
This is the formula, that worked for me (for anybody's reference):
I created another reference sheet, stating the types of work & their significance. From that sheet, I'm using either vlookup, filter, xlookup.Using gforms for inputting my data.
=ARRAYFORMULA(IFS(ROW(D:D)=1,"Significance",A:A="","",TRUE,VLOOKUP(D:D,Reference!$A:$B,2,0)))

Excel Alternative to nested IF

I have a couple of rather large nested if functions in my spreadsheet. It sure would be nice to have an alternative method. Problem is I'm using a wildcard (*) in my lookup because the source text has slight variations (date for example).
For example, if my list of data contains:
VENMO PAYMENT 220828 1022093447487 BRENDA HOSPY
VENMO PAYMENT 220813 1031323447487 BRENDA HOSPY
I want these to show in an adjacent column of cells as just Venmo
Currently my if function in that second column of cells is:
=IF(COUNTIF($F10,"*APPLE.COM/BILL*"),"AP",
IF(COUNTIF($F10,"IIA VOYA*"),"VOYA",
IF(COUNTIF($F10,"VENMO PAYMENT*"),"Venmo",
IF(COUNTIF($F10,etc...
This works fine but quickly gets unruly as more things get added.
I've spent a great deal of time searching for functions and processes that would make this easier, or at least more compact, but I can't find a way with typical functions like vlookup or index/match.
If I've explained this in a comprehensible fashion perhaps you've seen or experienced a similar situation and could offer a suggestion. It would be appreciated!
I'm not opposed to using a programming function.
I've looked at, and for, various Excel functions or combinations with no luck on my own or online.
I have created a structure as below
Formula present in B2 is as below
=IFERROR(INDEX($F$2:$F$9,MIN(IF(COUNTIF(A2,"*"&$E$2:$E$9&"*")>0,ROW($E$2:$E$9),9999999)-1)),"---")
Enter it as an Array Formula using Ctrl+Shift+Enter
It will search all the strings present in column E in A2 when found will return all the row numbers of column E where there is a match, i have then used min to get the first one, and if not found it will return 9999999, and as the data is starting from row 2 i have added -1 to make it equal to the data index. after that i have called the index to search value present at that index in column F. and at the end used the if error function to show --- where no match was found and 999999 was returned.

sumproduct if a cell contains a certain value, give all results otherwise just the specified result

My issue is that I need to reference a cell (A1) which will either be the name of a state that can be found in column L, or it can be "All States" which I then want to include all results of column L. I can't work out how to include this.
=SUMPRODUCT(--(IF(A1="All States",Data!$L:$L,Data!$L:$L=A1)),Data!Q:Q)
I want to add a bunch more criteria based on the above so I don’t want to go down the route of imbedding the sumproduct in an if function because the formula will quickly become too unweildy.
You have a lot of choices. Using your initial formula I would tweak it to
(A) =SUMPRODUCT((IF($A$1="All States",1,($L$2:$L$11=$A$1)))*($Q$2:$Q$11))
But this would need to be entered as an array formula so instead of just confirming with ENTER, you need CONTROL+SHIFT+ENTER. You will know you have done it right when { } show up around your formula. Note that they cannot be added manually.
A non array type formula which would be faster I believe would be to look at your two options. You are either dealing with a single state or all states. Set up an IF check to determine if you need to sum all of column Q, or if you need to find a single value from column Q. I used the following formula:
(B) =IF(A1="all states",SUM($Q$2:$Q$11),INDEX($Q$2:$Q$11,MATCH($A$1,$L$2:$L$11,0)))
A bit of a cheat but but simplifies things, is to add a final state to the bottom of your list in L and call is "All States". In the corresponding row in Q place =sum(First Cell:Last Cell). If you do that then you can use the following formula:
(C) =SUMPRODUCT(($L$2:$L$12=$A$1)*($Q$2:$Q$12))
That are other options out there as well, just thought I would show some options.

Output using 2 conditions, second condition will use one of 2 different formulas

Currently trying to make this formula using IF/IFS , AND
currently looks like this: =IF((D7=Yes)AND(C7>2500),C7*E5)
so I am trying to check for 2 conditions
I have a cell that has a "yes, no" pull down. So it is checking for a yes
if it is yes then it should check if another cell is less than 2500.
If it is >2500, then a specific formula should be used (C7*E5)
If it was <2500, then it would use a different formula (basically the same, just E5 would be F%, fulling from a different number.
I am not sure if I am on the right track at all.
I have tried using AND, IF, IFS. I am sure I am close but not doing the right combo.
this is how you do it:
=IF(AND(D7="Yes"; C7>2500); C7*E5; C7*F5)
unless you want it like this:
=IF(D7="Yes"; IF(C7>2500; C7*E5; C7*F5); )