I have a google sheets cell with 5 different texts (from a dropdown) - how can I make another cell return a value based on the text - if-statement

The 5 values in J4 are Studio, 1, 2, 3, 4.
Mortgage! is another sheet where I want to take B2*(52/12) if studio, B3*(52/12) if 1 and so on
Here is what I have been working with. I think I am close I just can't get it together to work
If
$J$4='Studio',(Mortgage!B2*(52/12)
$J$4='1',(Mortgage!B3*(52/12)
$J$4='2',(Mortgage!B3*(52/12)
$J$4='3',(Mortgage!B4*(52/12)
$J$4='4',(Mortgage!B5*(52/12)

Your logic is acceptable. You need to use the correct syntax.
=IF(
$J$4='Studio',Mortgage!B2*(52/12),
IF($J$4='1',Mortgage!B3*(52/12),
IF($J$4='2',Mortgage!B3*(52/12),
IF($J$4='3',Mortgage!B4*(52/12),
$J$4='4',Mortgage!B5*(52/12)
))))
By the way, it is customary to post a link to a public Google Sheet showing sample data when asking questions about Google Sheets.

Firstly, I think you have an errory in your sample code as you say I want to take B2*(52/12) if studio, B3*(52/12) if 1 and so on, but your sample is doing (Mortgage!B3*(52/12) for both $J$4='1' and $J$4='2'.
Therefor, I will assumne you are instead expecting...
if
$J$4='Studio',(Mortgage!B2*(52/12)
$J$4='1',(Mortgage!B3*(52/12)
$J$4='2',(Mortgage!B4*(52/12)
$J$4='3',(Mortgage!B5*(52/12)
$J$4='4',(Mortgage!B6*(52/12)
As others suggested, you can achive this by applying a nested IF() function with correct syntax,
but other than standard IF() funciont, you can use IFS() function for these kinds of cases:
=IFS(
$J$4='Studio',Mortgage!B2*(52/12),
$J$4='1',Mortgage!B3*(52/12),
$J$4='2',Mortgage!B4*(52/12),
$J$4='3',Mortgage!B5*(52/12),
$J$4='4',Mortgage!B6*(52/12)
)
There is also a SWITCH() function in google sheet that do similar things:
=SWITCH($J$4,
'Studio',Mortgage!B2*(52/12),
'1',Mortgage!B3*(52/12),
'2',Mortgage!B4*(52/12),
'3',Mortgage!B5*(52/12),
'4',Mortgage!B6*(52/12)
)
You may even create your own array to lookup for result:
=LAMBDA(DATA,
VLOOKUP($J$4,DATA,2,FALSE)
)({
'Studio',Mortgag!B2*(52/12);
'1',Mortgage!B3*(52/12);
'2',Mortgage!B4*(52/12);
'3',Mortgage!B5*(52/12);
'4',Mortgage!B6*(52/12)
})
where the array part:
{
'Studio',Mortgag!B2*(52/12);
'1',Mortgage!B3*(52/12);
'2',Mortgage!B4*(52/12);
'3',Mortgage!B5*(52/12);
'4',Mortgage!B6*(52/12)
}
can be shortened into something like this:
ArrayFormula({{'Studio';'1';'2';'3';'4'},Mortgage!B2:6*(52/12)})
or
ArrayFormula({{'Studio';TO_TEXT(SEQUENCE(4))},Mortgage!B2:6*(52/12)})
Combine this with the VLOOKUP(), you get this:
=ArrayFormula(VLOOKUP($J$4,{{'Studio';TO_TEXT(SEQUENCE(4))},Mortgage!B2:6*(52/12)},2,FALSE))
XLOOKUP() function also works in a similar way as VLOOKUP():
=ArrayFormula(XLOOKUP($J$4,{'Studio';TO_TEXT(SEQUENCE(4))},Mortgage!B2:6*(52/12)))

Related

Nested IF function inside a vlookup for google sheets

I'm trying to nest an IF function inside a vlookup to filter data based on a cell in another sheet.
The ideal functionality would be for the cell to return data if it meets a specific criteria otherwise leave it blank.
This is what I have so far:
=IFERROR(vlookup(E2,IF('internal_all[Paste Here]'!H3="Indexable",'internal_all[Paste Here]'!A:AB,""),28,0))
Currently, it doesn't work but instead I get an error "VLOOKUP equates to an out of bounds range".
Any help would be much appreciated.
Here's a copy of my gsheet: https://docs.google.com/spreadsheets/d/13mcOOHIP6-YQKOhE_LHnmu3-7bSNKzvCSTVZ5BnTxPA/edit#gid=0
Here's an example of the error I'm running into:
If I understand your question correctly...Then all you would need to change is where you put the if. Including it in the Vlookup will mess with the size of range ie. A:AB has a size of 28 but "" has a size of 0. I would also change your formula to an array so you don't have 6000+ formulas calculating. Finally, I would add an array_constrain to stop the array at the end of your dataset. Here is a working example:
=Array_Constrain(ArrayFormula(IF('internal_all [Paste Here]'!B2:B="Indexable",vlookup(E2:E,'internal_all [Paste Here]'!A2:AB,28,0),"")),CountIf(A2:A,"<>"),1)
I also included that formula in H2 of your "internal links point to canonicalised URLs" tab. Good luck!
Edit:
After looking at the setup again, this updated formula should work.
=Array_Constrain(ArrayFormula(if(VLOOKUP(E2:E,'internal_all [Paste Here]'!A:B,2)="Indexable",vlookup(E2:E,'internal_all [Paste Here]'!A2:AB,28,0),)),CountIf(A2:A,"<>"),1)
Also, here is an updated Indexability formula for column G
=Array_Constrain(ArrayFormula(IFERROR(vlookup(G2:G,'internal_all [Paste Here]'!A:B,2,0))),CountIf(A2:A,"<>"),1)

Is there a way to have an IF statement look for even or odd numbers?

I am very new to coding and am trying to make a camera check out/check-in system using a google form and google sheet. I am using a bar code scanner to scan in the camera on the google form which is linked then to the google sheet. Right now I am trying to get the sheet to count how many times the bar code was scanned in and then based on that tell me if the camera is checked in or out. So if the bar code is scanned in only once I now someone checked it out but if it is scanned twice I know it has been returned and then when it appears a third time it is checked out again and so on and so forth.
I have already tried using LOOKUP but it only searches one row and I want to be able to check in several items at once. I also tried using VLOOKUP but it doesn't work either.
This is the code that I have so far but it only works once since it only looks if a code has been scanned in once or several times
=If(COUNTIF(Data_Entered!$E$2:$I$6,A2) = 0, "Check In", "Check Out")
I want it that instead of only saying = 0 that I can say = even numbers.
You can use MOD. Ex.) =MOD(A1,2)
It will return a 1 if odd, 0 if even.
=IF(ISODD(COUNTIF(A2:A, "<>")), "online", "ofline")
=ARRAYFORMULA(IF(LEN(A2:A), IF(ISODD(IF(A2:A<>"", ROW(A1:A), )), "on", "off"), ))

Stuck on Concatenation array formula with multiple criteria

I have a formula which worked quite well to obtain information in order to link a reference contained in column B with information in T column of Sheet 2.
I have a formula which checks if 'Sheet2'!B:B=B2. However, now I want the formula to only return information where the corresponding line also has "yes" in Column A.
For example, if B2=1001, I only want to return CAT in the example below:
Is it possible to have two criteria like this?
I have tried various AND formulas alongside the main formula I have but this brings back errors:
=IF(ISBLANK(A4),"",ARRAYFORMULA(TEXTJOIN(" ⦿",TRUE,IF('Sheet2'!B:B=B2,'Sheet2'!T:T,""))))
I need to put somewhere in this formula to check if A2="Yes"
=IF(ISBLANK(A4),, ARRAYFORMULA(TEXTJOIN(" ⦿", 1 ,
IF((Sheet2!A:A="yes")*(Sheet2!B:B=B2), Sheet2!T:T, ))))

How can I resolve INDEX MATCH errors caused by discrepancies in the spelling of names across multiple data sources?

I've set up a Google Sheets workbook that synthesizes data from a few different sources via manual input, IMPORTHTML and IMPORTRANGE. Once the data is populated, I'm using INDEX MATCH to filter and compare the information and to RANK each data set.
Since I have multiple data inputs, I'm running into a persistent issue of names not being written exactly the same between sources, even though they're the same person. First names are the primary culprit (i.e. Mary Lou vs Marylou vs Mary-Lou vs Mary Louise) but some last names with special symbols (umlauts, accents, tildes) are also causing errors. When Sheets can't recognize a match, the INDEX MATCH and RANK functions both break down.
I'm wondering how to better unify the data automatically so my Sheet understands that each occurrence is actually the same person (or "value").
Since you can't edit the results of an IMPORTHTML directly, I've set up "helper columns" and used functions like TRIM and SPLIT to try and fix instances as I go, but it seems like there must be a simpler path.
It feels like IFS could work but I can't figure how to integrate it. Also thinking this may require a script, which I'm just beginning to study.
Here's a simplified example of what I'm trying to achieve and the corresponding errors: Sample Spreadsheet
The first tab is attempting to pull and RANK data from tabs 2 and 3. Sample formulas from the Summary tab, row 3 (Amelia Rose):
Cell B3: =INDEX('Q1 Sales'!B:B, MATCH(A3,'Q1 Sales'!A:A,0))
Cell C3: =RANK(B3,$B$2:B,1)
Cell D3: =INDEX('Q2 Sales'!B:B, MATCH(A3,'Q2 Sales'!A:A,0))
Cell E3: =RANK(D3,$D$2:D,1)
I'd be grateful for any insight on how to best index 'Q2Sales'!B3 as the correct value for 'Summary'!D3. Thanks in advance - the thoughtful answers on Stack Overflow have gotten me this far!
to counter every possible scenario do it like this:
=ARRAYFORMULA(IFERROR(VLOOKUP(LOWER(REGEXREPLACE(A2:A, "-|\s", )),
{REGEXEXTRACT(LOWER(REGEXREPLACE('Q2 Sales'!A2:A, "-|\s", )),
TEXTJOIN("|", 1, LOWER(REGEXREPLACE(A2:A, "-|\s", )))), 'Q2 Sales'!B2:B}, 2, 0)))

Apply a function to a range of cells in a spreadsheet

The answers in topics with similar titles haven't given me much of a resolution to my particular problem, but possibly I am not asking the right question. It might help knowing I'm an absolute noob when it comes to spreadsheets, so finding my way around is next to nil.
Currently I can set a basic function in the first cell A1 =ROW()
Simple right? Well now here comes the complication. If I click on the bottom right of the cell and start dragging I can then apply that very same function to a whole range of cells. Let's say I apply it from A1:A10. Every cell within this group now has the same function.
Hooray! We did it, right? I applied a function to a range of cells each with their own output. But wait, if I then go back to the original cell and change its formula none of the other cells change with it. GRRRRR!!!!
There are a couple of fixes I've come up with but don't necessarily know how to implement. The first is to have every cell link back to the original cell and reference its function. This would be useful if I wanted to randomly scatter dependent cells about the document. The other would be much more useful in an orderly group where you know the exact dimensions by specifying in the original cell the size of the array you want to apply the function to.
With that said, let me hear your thoughts.
The closest I've come to an answer is to use FORMULA() which returns the formula used by a cell as text. Unfortunately all answers on evaluating the text resort to scripting. How strange! I thought something like this would be common. Might as well get to scripting.
Hold on, I may have spoke too soon. An array can be made with =MUNIT(), but it's only square. Drats!
Ok... I'm hoping the zebra stripes will eventually become its own answer unless someone else beats me to it. So a simple array can be made with ={1,2;3,4} where commas separate values by column and semicolons for values by row except to generate it you have to press Control+Shift+Enter (because reasons?). I'm thinking now that I'll need to have functions that can generate lists of values based on a single function for each row, and pray that it'll work. So, back to looking. (Wow this is taking forever)
The way I was hypothesizing can't even generate a 1x1, e.g., ={ROW()} returns Err:512 which is a formula overflow.
Alright, in summary so far I've narrowed down the two options,
1) link every cell to the original formula
2) populate an array with a single formula
each with their own incomplete answer,
a) use FORMULA() to return the formula of a cell as text
b) create a hypothetical array like so ={LIST_OF_VALUES()}
These both require a strange form of the nonexistent EVALUATE() function to 'function' correctly. Isn't that fun?
Google Sheets handles case b by allowing ={ROW()}Control+Shift+Enter to generate =ArrayFormula({ROW()}). Working with the general case of any sized array being filled with a single function doesn't exist in the world of spreadsheets it seems. That's very saddening because I can't think of a much better tool for what I want to do. Copy paste it is until I need to use macros.
Depending on your specific use case, creating a user-defined function may help:
use the Basic IDE to create your function;
apply it to any cells on any sheet;
modifying the Basic code will affect all cells where the function is used.
I've elaborated the steps in an answer on superuser.
Sure, you could write some complex code to update functions, but wouldn't the easy way be just to drag it to the same range of cells the same way you did before? It should properly overwrite the existing code in there, and if it doesn't, you can just as easily delete the outdated code and drag the new code in.
Probably the best approach is to simply drag the amended formula over the range of cells (as advised by OldBunny2800). This is less error prone and easier to maintain than a custom macro.
Another option would be to use an array function. Then you only have to edit the function once, and the same edit will be automatically applied to the whole range of cells in that array function.