Excel generating prices difference between two sheets - excel

Let's say I have a *.xlsx file that contains the following two sheets:
sheet1:
sheet2:
How can I generate a third sheet that looks like this:
sheet3:
B2 in sheet3 is -1 because 54 - 55 = -1.
B3 in sheet3 is 67 because 67 - 0 = 67. (Sheet2 doesn't have Banana item so its price of banana is set to 0).

Simplest way would be using VLOOKUP(). You can also use INDEX/MATCH or XLOOKUP() if you have Excel O365
=IFERROR(VLOOKUP(A2,Sheet1!$A$2:$B$10,2,FALSE),0)-IFERROR(VLOOKUP(A2,Sheet2!$A$2:$B$10,2,FALSE),0)

So the equation on sheet 3 has to be, =sheet1!B2 - sheet2!B2 This will solve the problem. You can get more information on Excel Formulas for Linking Data between Different Sheets
I tried but It doesn't 100% solve your problem, =IF(ISERROR(VLOOKUP(Sheet1!A1,Sheet2!$A$1:Sheet2!A10,1,FALSE)),Sheet1!B1,Sheet1!B1-Sheet2!B1)
You might be able to get an idea.

Related

Excel: running maximum of two rows, or just return value in one row

I have an Excel spreadsheet:
Name
Grade
Name1
82
Name1
90
Name2
65
Name3
90
Name3
60
I would like an Excel command that will do the following in a new column (TrueGrade, column C):
If a string occurs twice in column A (Name)
then get the maximum of the two values from column B (Grade)
else get the value from column B in the same row as the name (which only occurs once).
This is what the result should look like:
Name
Grade
TrueGrade
Name1
82
90
Name1
90
Name2
65
65
Name3
90
90
Name3
60
Unfortunately, vlookup does not return multiple values.
So far, I have tried this in cell C2:
=INDEX($A$2:$B$5, SMALL(IF($A$2:$A$5=B2, ROW($A$2:$A$5)), ROW(1:1))-1,COLUMNS($A$2:$B$5))
which gave me 82, but this is just the first instance of a grade for Name1.
Using your test data as an example, putting this formula in C2 and copying down gave me your expected results:
=IF(COUNTIF(A$2:A2,A2)>1,"",MAXIFS(B$2:B$6,A$2:A$6,A2))
Obviously extend the ranges to suit your situation. Also note that the CountIF formula range is slightly different than the Maxifs formula. This also assumes you have the MaxIfS formula. If you don't you can do the same thing with an array formula:
=IF(COUNTIF(A$2:A2,A2)>1,"",MAX(IF(A2=A2:A6,B2:B6)))
Just remember to confirm the array formula with Ctrl+Shift+Enter.
I like to use SUMPRODUCT in these cases (because I always forget to properly enter array formulas).
So in cell C2, you can use:
=SUMPRODUCT(MAX(($A$2:$A$6=A2)*($B$2:$B$6)))
EDIT: late with the updated answer based on my earlier work but it's the same as #sous2817:
=IF(COUNTIFS(OFFSET($A$2,0,0,ROW()-ROW($A$2)+1,1),$A2)=1,SUMPRODUCT(MAX(($A$2:$A$6=A2)*($B$2:$B$6))),"")
This still works without an array formula.

Vlookup and sum all instances of the matching lookup

this is probably an extremely basic problem but I can't figure a way to do this within Excel.
I have a list of values IDs from a regional sales manager,
he wants to see if his figures have been inputted into the monthly report and are reporting correctly.
However, as he sells by region and we report by product we have multiple instances of his ID by Product
so our monthly report.. for example
ID Value
1 16,999
1 22,521
3 400
3 221
5 71
6 22,000
So he has provided me with a list of IDs
1
2
3
4
5
6
and wants a list with its total revenue not just the first match up.
Is an excel limitation or is there a way to do this?
You can use a SUMIF formula. Basically you give it the column to check the value of, then you give it the expected value and finally the colum to sum.
Option 1 (whole range)
=SUMIF(A:A, 1, B:B)
Option 2 (defined range)
=SUMIF(A1:A7, 1, B1:B7)
Option 3 (Using excel table)
=SUMIF([Id], 1, [Value])
For more details please refer to: https://support.office.com/en-ie/article/sumif-function-169b8c99-c05c-4483-a712-1697a653039b
Is this what you're looking for?
=SUMPRODUCT((A1:A5=1)*B1:B5)
Taken from here: Sum values from multiple rows using vlookup or index/match functions
How it works:
An array formula is used to create an array of numbers that gets passed to the SUMPRODUCT formula.
The array formula processes A1 and B1 together, then A2 and B2 and so on... if A1 is equal to 1, B1 is added to the array.

Matching cell from two values

need help here :) I am not excel expert
I have a simple spread sheet with some data and I need to find the matching values from another sheet. Some help would be appreciated.
The data looks like this:
d1 d2 d3 d4 d5
c1 1 5 4 4 3
c2 2 4 9 1 2
c3 4 4 7 8 4
c4 4 7 1 9 2
c5 4 4 7 6 8
So above c1, c2 etc. means Code's and d1, d2 etc. means Dates (future dates).
The numbers between I need to catch in a different spread sheet
example
Code: c2 - User provides the code
Date: d4 - User provides the date
Value: 1 - this value I need to get with formula
Should I attach example file if needed?
If possible to use performance wise formulas as might be quite few of them. Perhaps INDEX/MATCH? if I know how to use it :) but I think also INDEX/MATCH will slow it down a lot, I might be wrong also :)
thank you for your help in advance.
EDIT:
Added screenshot, might help also what is needed.
Assumptions / prerequisites:
Sheet1 cells (A1:F6) is your data / headers from your example
Sheet2 cell B3 is where the user types the code
Sheet2 cell B4 is where they type the date
Sheet2 cell B5 is where the value displays
this would be your formula in Sheet2 C5
=INDEX(Sheet1!A:F,MATCH(B3,Sheet1!$A:$A,0),MATCH(B4,Sheet1!1:1,0))

Excel look up value in array, return next value

I would like to look up a value in a range and return the value in the next row, but can't quite figure out how to do this. I especially would like to do this with formulas rather than VBA, and preferably with built-in formulas than custom (VBA) formulas, due to macro security issues.
I'm using Excel 2010. My workbook has two worksheets, "assessment" and "lookup". In lookup, I have lookup tables.
"lookup" looks something like:
Column A Column B Column C
1 Sales Engineering Manufacturing
2 Alice Bobbie Charlie
3 Dawn Edgar Frank
4 George Holly Isabel
In "assessment," I have some some drop downs from which users select one name from each column in "lookup." Based on some other criteria, I then rank these and create a new, sorted list (using INDEX() and MATCH()) that produce the selected name and corresponding column name a new sort order
Column A Column B
10 Engineering Edgar
11 Sales Alice
What I'd like is to return the name from the next row.
Column C
10 Holly
11 Dawn
But I'm having real trouble figuring out how to get there.
Assuming lookups is located at B2:D5 (change as required) and the result data is at F2:H3 (change as required) enter this formula in cell H2 then copy down.
=INDEX(
INDEX($B$2:$D$5,0,MATCH($F2,$B$2:$D$2,0)),
1+MATCH($G2,
INDEX($B$2:$D$5,0,MATCH($F2,$B$2:$D$2,0)),0))

Excel concatenation by using formula or vlookup

I have two sheets in excel workbook.
I need the formula which matches SITEID and concatenate 3 values to 1 separated by / .
I have tried to use Vlookup with ranges but not get the actual results.
First sheet contains (4 columns):
SiteId Cell Sector Bore
MDLH1238 12381 1 10
MDLH1238 12382 2 20
MDLH1238 12383 3 40
MDLH1239 12391 1 60
MDLH1240 12401 1 50
MDLH1240 12402 2 20
Second sheet contains (2 columns):
SiteId Bore
MDLH1238
MDLH1239
MDLH1240
The expected result should be like this :
SiteId Bore
MDLH1238 10/20/30
MDLH1239 60
MDLH1240 50/20
Assuming there's only ever 3 sectors per site, and using your sheet names, and assuming your cells start in A1, enter these in Sheet2, adjacent to the SiteIDs:
Cell B2:
=SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A2,Sheet1!$C$2:$C$7,1)&"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A2,Sheet1!$C$2:$C$7,2)&"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A2,Sheet1!$C$2:$C$7,3)
Cell B3:
=SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A3,Sheet1!$C$2:$C$7,1)&"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A3,Sheet1!$C$2:$C$7,2)&"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A3,Sheet1!$C$2:$C$7,3)
Cell B4:
=SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A4,Sheet1!$C$2:$C$7,1)&"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A4,Sheet1!$C$2:$C$7,2)&"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A4,Sheet1!$C$2:$C$7,3)
That should produce content like:
SiteId Bore
MDLH1238 10/20/40
MDLH1239 60/0/0
MDLH1240 50/20/0
That's got extra "/0" entries where the sector 2/3 don't exist, but the formulas get longer and harder to read, to do that.
Edit: Adds the formulas for dealing with "/0"
Cell B2:
=SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A2,Sheet1!$C$2:$C$7,1)&IF(SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A2,Sheet1!$C$2:$C$7,2)>0,"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A2,Sheet1!$C$2:$C$7,2),"")&IF(SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A2,Sheet1!$C$2:$C$7,3)>0,"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A2,Sheet1!$C$2:$C$7,3),"")
Cell B3:
=SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A3,Sheet1!$C$2:$C$7,1)&IF(SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A3,Sheet1!$C$2:$C$7,2)>0,"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A3,Sheet1!$C$2:$C$7,2),"")&IF(SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A3,Sheet1!$C$2:$C$7,3)>0,"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A3,Sheet1!$C$2:$C$7,3),"")
Cell B4:
=SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A4,Sheet1!$C$2:$C$7,1)&IF(SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A4,Sheet1!$C$2:$C$7,2)>0,"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A4,Sheet1!$C$2:$C$7,2),"")&IF(SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A4,Sheet1!$C$2:$C$7,3)>0,"/"&SUMIFS(Sheet1!$D$2:$D$7,Sheet1!$A$2:$A$7,A4,Sheet1!$C$2:$C$7,3),"")
Output:
SiteId Bore
MDLH1238 10/20/40
MDLH1239 60
MDLH1240 50/20
What you would like to be able to do is to concatenate elements of an array using "/" as a separator. Unfortunately native Excel can't do this, but there are plenty of good VBA functions already written which will, e.g. the one described here.
So I would suggest this solution:-
=StringConcat("/",IF(Sheet1!A$2:A$7=A2,Sheet1!D$2:D$7,""))
starting in cell B2 of the second sheet and pulled down as necessary. This is an array formula and must be entered using CtrlShiftEnter.
In order to use the StringConcat function, you need to copy the code from the web page, press AltF11, select Insert|Module, then paste in the code.

Resources