How can I automate these formulas? - excel

Hello,
I need to automate these formula.
Wheat 2 USA minus wheat 1 USA, Wheat 2 Brazil minus wheat 1 Brazil, Wheat 2 Canada minus wheat 1 Canada, Wheat 2 Argentina minus wheat 1 Argentina and so on for every product and taking into account corresponding regions and week numbers.
Barley 2 USA minus barley 1 USA, Barley 2 Brazil minus barley 1 Brazil, Barley 2 Canada minus barley 1 Canada ...
A formula should work in such a way that when I populate it, it understands the logic and make a calculation.

Use LOOKUP to find previous value of current product:
=IFERROR(C2-LOOKUP(2,1/($A$1:A1=A2),$C$1:C1),"")
or so if the Input number column matters:
=IFERROR(C2-LOOKUP(2,1/(($A$1:A1=A2)*($B$1:B1=(B2-1))),$C$1:C1),"")

First: I like #basic's solution much better! I keep forgetting that =LOOKUP(LargerThanAll,Nums,Values) returns the value for the highest num!
That said, here's another way:
First, put your cursor on the top line and Insert - Table, making sure you check the "My table has headers" checkbox in the dialog box that appears.
Now, in addition to having it formatted, there are formula benefits.
Keeping with your example where the B2 = "Product",
Change F2 to "Product|Number" to create a new column
Change F3 to =[#Product]&"|"&[#[Input Number]] (Because you're using tables, you can use column names rather than cell references, [#ColumnName] is the column value for the current row, it will use that formula for the entire column, and the formula is stored once instead of once per row!)
Change G2 to "PrevRow"
Change G3 to =MATCH([#Product]&"|"&([#[Input Number]]-1),[Product|Number],0) (you now have the table row number for the previous value
Change E3 to =IF(ISNUMBER([#PrevRow]),[#Quantity]-INDEX([Quantity],[#PrevRow]),"")
Hide columns F and G. (Or fold their functionality into your Volume's formula so your volume formula doesn't need them and delete them.)

Related

Arranging data in Excel

I have data in excel. I need help, to arrange it.
part of the data
I need to write for each product all of the countries where it is sold, separate the countries with " | ", For Example: if a certain product is sold in SPAIN, UK, FRANCE, BRAZIL and RUSSIA the row of this column will show: SPAIN | UK | FRANCE | BRAZIL | RUSSIA.
It's need to be in the same column....
Here is one easy way you could do it if you want to see what you're doing.
Fill column C and D, result will be in D. Column B needs to be sorted.
A
B
C
D
1
Country
Product Code Central
Country List
Formatted List
2
UKRAINE
194
=IF(B2=B1;C1&"|"&A2;A2)
=IF(B3<>B2;C2;"")
If you have a version of Excel that understands both TEXTJOIN and FILTER (the former is the most recent, available in Excel 365) the formula below will return the result you describe.
=TEXTJOIN("|",TRUE,(FILTER(A$2:A$11,B$2:B$11=D2,"None")))
Here A2:A11 has the country names, B2:B11 the product numbers and D2 any value from B2:B11.

Excel - Find if a product changed price

How can I find if a product changed it's price in excel? For example:
Yesterday's prices:
Potatoes 5,50
Tomatoes 7.40
Apples 5.60
Cucumber 4.30
Today's prices:
Potatoes 5,50
Tomatoes 5.20
Apples 5.50
Cucumber 4.30
Tomatoes and apples changed their price. How is it possible to highlight those changes based on "A" column product description?
This formula will return TRUE if an item in the list has changed price:
=COUNTIFS($A$1:$A$8,A1,$B$1:$B$8,"<>"&B1)>0
Enter it in C1 (in this example) and drag down
Here is what you can try. I also attached some pics for your reference.
Columns A and B are for yesterday's prices, columns C and D are for today's prices, and column E is to see the price changes (you don't need column E but I just want to show you so you know what is happening). Also, the formula for column E is =INDEX($A$3:$B$7,MATCH($C3,$A$3:$A$7,0),2)-$D3.
To highlight whichever product had price changed. We will use Conditional Formatting which is under Home > Conditional Formatting > New Rule > Use a formula.... Under cell D3, you enter the same formula like in cell E3 which is =INDEX($A$3:$B$7,MATCH($C3,$A$3:$A$7,0),2)-$D3. Pick the color you want as the pic sample below.
Then applies to =$D$3:$D$6 just like the pic shows below.
This should work for you. Try and let me know.
Use the conditional formatting on another column. E.g. have a column of Yesterday-Today and highlight if <> 0.
This will work, use the formula
=IF((AND(A1=C1,B1<>D1)),"yes","no")
where A1, C1 have fruite and B1, D1 have prices.
Below is the result obtained.
Potatoes 5,50 Potatoes 5,50 no
Tomatoes 7.4 Tomatoes 5.2 yes
Apples 5.6 Apples 5.5 yes
Cucumber 4.3 Cucumber 4.3 no
Then you can filter/highlight based on whether it is a yes/no.

Excel Index Partial match

I have Sheet1 with column A listing every single country in alphabetical order..
A
1 Afghanistan<
2 Albania
3 Algeria
4 American Samoa
5 Andorra
----------
228 United Kingdom
229 United States
etc
I have Sheet2 column A with empty cells with adjacent cells in column B listing address details
A B
1 empty cell Unit 3, Road;London, United Kingdom
2 empty cell Building 1, Road, TX, United States
3 empty cell 8th floor, Business Park, India 1234
etc
What I would like to know is how can I obtain the country within the address details in sheet2 column B and place them in Sheet2 column A, based on a match on the list of countries in Sheet1 column A.
Part of the problem is there is no coherent method as to how to country is placed within the address; could be at the end or in the middle of the address.
I have tried various index match formulas with no luck
any help would be appreciated.
I tried it with the reference table being in A1:B7, and lookups being A10:B10 onwards down. The formula is for these cells. You can adjust it for Sheet1/2!.
Assuming your data is in B10 onwards, and your reference data was in B1:B7, you can write this formula in A10 =INDEX($B$1:$B$7,MAX(IF(ISERROR(FIND($B$1:$B$7,B10)),-1,1)*(ROW($B$1:$B$7)-ROW($B$1)+1))). This is an array formula, so please hit Ctrl+Shift+Enter for excel to read it as an array formula.
(In the screenshot, I have pasted the table in A10:B12 as values only in D10:E12)
Text to Columns with a comma delimiter

Conditional Formatting - Highlight every cell that doesn't match in two rows, then move to next two rows

I have two worksheets that I'm trying to compare and then highlight every cell that is different between the two. I've cut/pasted all the rows into one worksheet and highlighted the ones from the original spreadsheet. It's easy visually to see the differences, but I'm trying to use conditional formatting to highlight just the rows that are different. I only want to check the first two rows for differences, then move to the next two rows checking for differences, then move to the next two rows.
Worksheet1
1 Brown, Jean 100 Main St Richmond VA This is a long note about this contact. 12/14/2014 Yes
Worksheet2
1 Brown, Jean S. 101 Main St Richmond VA This is a long note about this contact. 12/14/2015 No
Worksheet1
2 Tomas, Bill 2500 Sky Cir Charlottesville CA This is a long note about this contact. 12/15/2014 No
Worksheet2
2 Tomas, Bill 2500 Sky Cir Charlottesville VA This is a long note about this contact. I added some to it. 12/15/2014 No
Every time I try to do it, it just checks each cell against the previous cell. I just want to compare the first two rows, then compare the next two rows, etc. I need to attach this to an affidavit showing what changes I made to the worksheet, and I don't want to rely on my eyeballing each row and manually highlighting the differences. Our IT group tried a special Compare software, but the result was a very difficult to read PDF file with lots of little pop-up comments that you have to hover over to see the differences.
You can achieve what you need with conditional formatting.
Assume your data is as follows:
A B C D E F
1 Brown, Jean 100 Main St Richmond VA This is a long note 12/14/2014 YES
2 Brown, Jean 101 Main St Richmond VA This is a long note 12/14/2015 NO
3 Tomas, Bill 2500 Shy Cir Charlotte CA This is a long note 12/15/2014 NO
4 Tomas, Bill 2500 Shy Cir Charlotte CA This is a new note 12/15/2014 NO
For each column you need to set a conditional format formula. Example for Column A:
Open Conditional Formatting
Select New Rule
Select Use a formula to determine which cells to format
Add the following formula
=AND(MOD(ROW(),2)=0,A1<>OFFSET(A1,-1,0))
Now apply for format you want to use as a highlight e..g red color
Note: You need to add the formula for each column separately and update the column references. For example, column B formula would be:
=AND(MOD(ROW(),2)=0,B1<>OFFSET(B1,-1,0))
The trick with this formula is the MOD(ROW(),2 = 0. It looks at even rows only (i.e. 2, 4, 6 etc..) and then compares to the previous row. This is important to know depending on how your data is set up in your spreadsheet i.e. in my example I assume your first row is in row 1 and so it is every even row I am comparing to the previous row

Count the number of companies per country in Excel

I have the following 2 excel sheets in the same workbook:
companies:
A B
1 COMPANY COUNTRY
2 Apple USA
3 Microsoft USA
4 Samsung Taiwan
5 Philips Netherlands
6 Tulip Netherlands
countries:
A B
1 COUNTRY NUM_COMP
2 USA 2*
3 Taiwan 1*
4 Netherlands 2*
In sheet countries column B I need the number of companies per country. I have now counted them by hand, but I need a formula for cells B2 to B4 to do this automagically, since the actual sheet is much, much longer than this example.
Can anyone help me? Your help is greatly appreciated.
Function 'Countif' should be helpfull :)
=COUNTIF(B:B;B2)
cheers
Sky
For the number of different companies per country try this formula in B2
=SUM(IF(FREQUENCY(IF(companies!B$2:B$2265=A2,MATCH(companies!A$2:A$2265,companies!A$2:A$2265,0)),ROW(companies!A$2:A$2265)-ROW(companies!A$2)+1),1))
That's an "array formula" which needs to be confirmed with CTRL+SHIFT+ENTER so that curly braces like { and } appear around the formula in the formula bar.
Now copy formula down column

Resources