Excel Logical operators inside If loop - excel

So this works:
=IF(OR(D2="MEXICO",D2="TURKEY",D2="CHINA",D2="BRAZIL",D2="INDIA",D2="INDONESIA",D2="POLAND",D2="COLOMBIA",D2="ARGENTINA",D2="PHILIPPINES"),D2,"Others")
But this doesn't
=IF(D2=OR("MEXICO","TURKEY","CHINA","BRAZIL","INDIA","INDONESIA","POLAND","COLOMBIA","ARGENTINA","PHILIPPINES"),D2,"Others")
Is there a way to get around writing D2= inside every single time? I am looking to see if the criteria can be used in multiple places .. say in a different sheet I also have country names, but just not in column "D".

You can use something like this:
=IF(ISERROR(VLOOKUP(D2,{"MEXICO","TURKEY"},1,0)),"Others",D2)
Futhermore, as #barryhoudini suggest, in excel 2007 or later you can use:
=IFERROR(VLOOKUP(D2,{"MEXICO","TURKEY"},1,0),"Others")

I would suggest that you create a list of country names in a column in a sheet somewhere and use that as a look up where ever you need it. You can create a separate sheet with this data, say datasheet.
Let's say you have a list of countries in A1:A25 of datasheet, you can then do something like this:
=IF(COUNTIF(datasheet!A1:datasheet!A25, D2) <> 0, D2, "Other")
Additionally, I would create a named range for the set of country names if I expect them to change in the future. This way my formulas will refer to the name and if I add countries I do not have to change the formulas.

It's possible to use OR but you need to change the syntax a little - like this
=IF(OR(D2={"MEXICO","TURKEY","CHINA","BRAZIL","INDIA","INDONESIA","POLAND","COLOMBIA","ARGENTINA","PHILIPPINES"}),D2,"Others")

Alternatively, this should work for you:
=IF(ISNA(MATCH(D2, {"MEXICO","TURKEY","CHINA","BRAZIL","INDIA","INDONESIA","POLAND","COLOMBIA","ARGENTINA","PHILIPPINES"}, 0)), "Others", D2)

Related

Is it possible to create a SUM of all of the unique names 2 dimensionally and their value like in the example below?

I am trying to find a function that will look through all of the sheet to find unique names and sum the value that was assigned at a specific date like below: (End result should be like the summary) - I am restricted to use this format and can't have all the names under one column and dates under another.
A simply old fashion Sumif function is enough.
In I2, formula copied down :
=SUMIF(A:E,H2,B:F)
"I am trying to find a function that will look through all of the sheet to find unique names and sum the value that was assigned"
Assuming:
You indeed don't know the names beforehand (and over the course of 800+ columns and idemt dito rows (or more), it's "impossible" to write these out beforehand);
You have an arbitrairy range (of up to 800 columns and many rows);
Access to the BETA-channel of ms365.
Formula in H3:
=LET(X,WRAPROWS(TOCOL(A3:F5,1),2),Y,INDEX(X,0,1),Z,UNIQUE(Y),HSTACK(Z,BYROW(Z,LAMBDA(a,SUM((Y=a)*INDEX(X,0,2))))))
Note: The above is based on the assumption you don't know the unique names up front (as stated in the body of your question). Admittingly, if these are known, there are other/better answers.
So laid the data out like so and used sumifs():
SUMIFS($C$2:$C$8,$B$2:$B$8,F2)
Will let you consider adding a date control: prior to, equal to or after...
If you say you cannot change the source data, then make a data sheet to copy all the data, do the results like I show then link the results over...
So if you have to keep the format (instead of copying the data as already suggested - perhaps you missed that as you did not address that in your comment) then you could use sumifs() multiple times like so:
And just for fun playing with date control, still using your format:

How to do this lookup operation in Excel

There are two sheets (sheet1 & sheet2) in my Excel file, it's like daily work routine (entry date, pickup date, dispatch date). Some details will change as per the work flow and even new entries will appear.
I just need to compare both files if a change occurred in one cell it must have to show entire row of sheet1 (I can't specify exact headline for that all details are too precious and it has more than 100 headlines).
So if there is any formula for that please let me know like
IF+VLOOKUP
please correct below given formula
=If(RECHERCHEV(A2,sheet1!A8:FM264,1,FAUX)=(RECHERCHEV(A2,sheet2!A8:FM257,1,FAUX);"";RECHERCHEV(A2,sheet1!A8:FM264,1,FAUX))
It's the French version.
Try this array formula in cell A1 of sheet3 and drag across and down.
=IF(AND(EXACT(Sheet1!1:1,Sheet2!1:1)),"",Sheet1!A1)
Not really sure what you're looking to do here, and I don't speak french, but it looks like you have an extra parenthesis before your 2nd RECHERCHEV function.
Try this :
=If(RECHERCHEV(A2,sheet1!A8:FM264,1,FAUX)=RECHERCHEV(A2,sheet2!A8:FM257,1,FAUX);"";RECHERCHEV(A2,sheet1!A8:FM264,1,FAUX))
Though I'm not sure why the IF function uses semi-colons, but the RECHERCHEV uses commas, so maybe this:
=If(RECHERCHEV(A2,sheet1!A8:FM264,1,FAUX)=RECHERCHEV(A2,sheet2!A8:FM257,1,FAUX),"",RECHERCHEV(A2,sheet1!A8:FM264,1,FAUX))
Also it seems you want the entire row to update, so I am not sure how this vlookup would work since the arrays start in different rows than the lookup value.

How can I create the equivalent of an explode(), implode() pattern match approach in Google Sheets using formulas?

Here's my goal:
I have the following data set:
From that, I'd like to generate the following:
In the interest of RTFM, here's my thought process and what I've tried:
Firstly, the top set's two columns are in their own named ranges: Color_Abbrevs, Category_Names, respectively.
I know I can use JOIN() to produce the results in Category Output from the category names like so:
JOIN("/",Category_Names)
My challenge now is how to create a sort of "pattern matcher" (I don't know what else to call it) whereby I can use the abbreviations in place of the category names to render the result string. An example of the desired pattern format is shown in A8:A10.
To start, I tried to think through using something like an INDEX and MATCH approach:
=INDEX(Category_Names,MATCH(LEFT(A8,FIND("/",A8)-1),Category_Abbrevs,0))
This yields the correct value in A9, so I thought I might be on the right track. The part I'm stuck on is how to connect the JOIN and INDEX and MATCH formulas together to allow for a variable length of Abbreviations and Categories.
Ideally, I want to be able to continue adding values to the top data set and define whatever unique "patterns" I need in a list via the second data set to get the desired result.
Is this possible using formulas, or do I need to write some Google script to achieve it?
EDIT: Rows B8 and B9 both have typos (apologies). B8 should show "Tile Daily Store/Porcelain" and B9 should show "Tile Depot Store/Metallic Porcelain".
Alternatively you also can use the formula (at B8):
=ARRAYFORMULA(JOIN("/";LOOKUP(SPLIT(A8;"/");$A$2:$A$6;$B$2:$B$6)))
in Google Sheets to get the "category output" in the same order like it is at "structure"
EDIT
Looks like I missed something here :P
=ARRAYFORMULA(JOIN("/";VLOOKUP(SPLIT(A8;"/";TRUE);$A$2:$B$6;2;FALSE())))
Will do if everything is also in the list (if something is not found, it will completely error out)
=ARRAYFORMULA(JOIN("/";IFERROR(VLOOKUP(SPLIT(A8;"/";TRUE);$A$2:$B$6;2;FALSE());"---")))
This will show "---" for each part which was not found...
In Google Sheets use this formula:
=JOIN("/",filter($B$1:$B$6,ISNUMBER(SEARCH($A$1:$A$6,A8))))
In excel, Excel introduced in Office 365 the TEXTJOIN() function, which we can use in an array formula:
=TEXTJOIN("/",TRUE,IF(ISNUMBER(SEARCH($A$1:$A$6,A8)),$B$1:$B$6,""))
Being an array in excel on must use Ctrl-Shift-Enter when exiting edit mode instead of Enter. If done correctly then Excel will put {} around the formula.
NOTE
Both these methods will put the output in order of the searched area and not the order in the criteria cell.

Excel - How to add value after 3rd /

I have excel file with one value that need to be edited. It's link to a image.
My link template looks like this:
this
http://website.com/something/brand/product/product_name/image.jpg
I need to add 'medium' after /product/
so my template would be
this
http://website.com/something/brand/product/medium/product_name/image.jpg
example:
http://website.com/cake/cutie/bigcakes/pink_caramel/hr74.jpg
would be
http://website.com/cake/cutie/bigcakes/medium/pink_caramel/hr74.jpg
Of course all products are different, so can i maybe say something like, add medium/ after 6th / ? I don't know how else, as its huge file with thousands of products, brands and product names.
Well, using the formula of #SkipIntro, you can use the CONCATENATE, LEFT and MID formulae to get your desired result.
=CONCATENATE(LEFT(A1,FIND(CHAR(1),SUBSTITUTE(A1,"/",CHAR(1),6))),"medium",MID(A1,FIND(CHAR(1),SUBSTITUTE(A1,"/",CHAR(1),6)),100))
This assumes your link template is in cell A1. If it's in any other cell, replace the A1 with the required cell address.
EDIT:
I overlooked a much simpler one ^^; :
=SUBSTITUTE(SUBSTITUTE(A1,"/",CHAR(1),6),CHAR(1),"/medium/")
You can incorporate Skip Intro's suggestion into a REPLACE function like this
=REPLACE(A1,FIND(CHAR(1),SUBSTITUTE(A1,"/",CHAR(1),6))+1,0,"medium/")

Excel, Specifying cell contents as a result of other cells

I don't use excel often, and I haven't really found a good solution to my problem. (which is probably really simple).
I would like to have a cell with a function in my spreadsheet that shows another cell value value that depends on yet another cell value.
Such as:
The Best Deal heading simply uses the formula
=MAX(D3,D1000)
But under Best Deal I would like to display the Name Test1 rather than the numeric value.
Another thing that would be nice to know, is if there is a way to know the maximum row with data in it. So rather than =MAX(D3,D1000) something like =MAX(D3,Max(RowCount_InD))
Obviously that function wouldn't work as I wrote it, but hopefully this pseudo code gives you an idea of what I mean. The purpose is that if more entries are added, it would be able to handle them.
I know this is possible, but I'm having some trouble. Hopefully I can get some help here.
Thanks!
The easiest way to do this is to use a combination of Index and Match. Match will find the position of the maximum value, and then Index will look in column A and return the data in that same position. So, your formula would be:
=INDEX(A$3:A$1000,MATCH(MAX(D$3:D$1000),D$3:D$1000,0))
Put that formula in F3. No hidden columns required.
Sorry, I missed the part about the expanding range. You can do that by using Count or CountA along with Offset. The new formula would be:
=INDEX(A3:OFFSET(A3,COUNTA(A:A)-1,0),MATCH(MAX(D3:OFFSET(D3,COUNT(D:D)-1,0)),D3:OFFSET(D3,COUNT(D:D)-1,0),0))
More complex, but it is basically the same except that it will expand as you add new values at the end.
There is only one 'simple' way I can think of this, but it requires hidden columns (sorry).
set E1 = A1 and fill down all the way (Basically you are making a copy of column A in column E but you are using a formula so it will always be the same)
Then under 'Best deal' - put this formula:
=VLOOKUP(MAX(D3,D1000),$D:$E,2,FALSE)
Then hide column E so it doesn't look like a mess. This way you do not need any fancy macro's and it will work everywhere because it is a normal formula.
"Another thing that would be nice to know, is if there is a way to know the maximum row with data in it. So rather than =MAX(D3,D1000) something like =MAX(D3,Max(RowCount_InD))"
This is a called a dynamic named range. Create a name for the ratio data, and set up the formula for the name range to be this:
=OFFSET($D$3, 0, 0, COUNTA($D$3:$D$1048576), 1)
More info here: http://www.ozgrid.com/Excel/DynamicRanges.htm
Then, assuming you name this named range ratio_data, your function could be referring to =MAX(ratio_data) in combination with index-match as suggested by #Tim Mayes. The range will expand automatically as you add more data.
=INDEX(A$3:A$1000,MATCH(MAX(ratio_data),ratio_data,0))
Ideally, you can replace the A3:A1000 by a dynamic named range as well.

Resources