I have 1 workbook with 2 worksheets.
The first screenshot shows Worksheet A, the second screenshot shows Worksheet B
I would like to match the corresponding quantity to the corresponding grade in Worksheet A based on the Columns "Line", "Sub-Line", "Category", "Occasion", "Sub-Cat" and "Grade" in Worksheet B.
Question: How to get the corresponding quantity?
Many thanks!
Since you already have a concatenation of the search criteria in SheetB!F:F you might use this formula if you have Excel 365 (much earlier versions won't have the TEXTJOIN function).
=VLOOKUP(J2, SheetB!$F$2:$K$1000, MATCH(I2,SheetB!$F$1:$K$1, 0), FALSE)
Witness that the MATCH function includes F1, which must not have any of the captions found in G1:K1. $K$1000 is an arbitrary row number intended to be larger than anything you need. For use in my own project, I would create a dynamic named range instead of SheetB!$F$2:$K$1000.
This is a little heavy and perhaps someone can make an easier approach, but let's give it a go. NB: This requires Excel 2019 or 365.
You can put this into your QTY column in WORKSHEET A:
=SUM(TRANSPOSE(MMULT(SIGN(SEQUENCE(1,5)),TRANSPOSE(--(B5:F5=WorksheetB!$A$3:$E$14)))=5)*INDEX(WorksheetB!$G$3:$K$14,,MATCH(G5,WorksheetB!$G$2:$K$2,0))
That's hard to read, so here it is again with formatting (it works with formatting all the same):
=SUM( TRANSPOSE( MMULT( SIGN( SEQUENCE( 1, 5) ),
TRANSPOSE(--(B5:F5=WorksheetB!$A$3:$E$14) ) ) = 5 )
* INDEX( WorksheetB!$G$3:$K$14,,MATCH( G5, WorksheetB!$G$2:$K$2,0) ) )
Seems there would be an easier way, but it does not come to me at the moment.
As a side note - what you are doing looks very much like something that could be done in Power Query. It would make quick work of doing such match-ups and aggregations and if there is a lot more that you want to do with these data, it would support that as well.
You can use INDEX and MATCH for this:
=INDEX('Worksheet B'!$G$4:$K$26,MATCH(1,($B5='Worksheet B'!$A$4:$A$26)*($C5='Worksheet B'!$B$4:$B$26)*($E5='Worksheet B'!$C$4:$C$26)*($D5='Worksheet B'!$D$4:$D$26)*($F5='Worksheet B'!$E$4:$E$26),0),MATCH($I5,'Worksheet B'!$G$3:$K$3,0))
The formula needs to be entered with ctrl+shift+enter as it's an array formula.
It indexes the quantities in 'Worksheet B'!$G$4:$K$2 and returns the row number of where the value in Worksheet A of the line, sub-line, occasion, category, sub-cat matches the value in the resembling column in Worksheet B and the indexed column number of where the grade value in Worksheet A equals the header in Worksheet B'!$G$3:$K$3.
This worked for me!
=VLOOKUP(CONCAT(B10,"-",C10,"-",E10,"-",F10,"-",D10),'Worksheet2'!$F$4:$K$26,MATCH('Worksheet1'!M10,'Worksheet2'!$F$3:$K$3,0),FALSE)
Cheers
Related
I have an Excel sheet with two columns. The first column holds names. I also have a list of names as text file, now added as second sheet.
For each row, I want to set the second cell to a fixed value if the value of the first cell is present in the list. Other rows should remain unchanged.
I was told to consider VLOOKUP but could not make up a formula.
I'm using Excel for Microsoft 365
first sheet:
column M is the one to be changed
second sheet:
The expected output would simple have entries in column M to be IN instead of OUT.
Try COUNTIF:
=IF(COUNTIF(List!A:A,A1),"IN","OUT")
You can do it with MATCH if the Second Sheet is in the same workbook. If it is in a separate workbook, it will still work, but only of the other workbook is open.
=IF( ISNUMBER( MATCH( A2,Sheet2!$A$2:$A$7, 0 ) ), "IN", "OUT" )
Alternatively, if you don't want to do VBA, you can pull the text file into a table in your workbook that is hidden into the data model and then reference it, but that is a long trip and can only be done on an installation that supports Power Query.
Formula would be somethin like
=VLOOKUP(K3,Table1,2)
Where Table1 is your look up, K3 is the value to look up (index) and 2 is the second column you want to return
[
I have an excel document with two sheets, data and edu-plan. The sheet data has the following information:
The sheet edu-plan looks like this:
My question is: how do i create an excel formula that checks if the target group on the specific row in edu-plan! has the course name in question on the same row as the target group in sheet data!, i.e. if Sales and Sales course is on the same row in the sheet data!?
In reality, the data sheet as a couple of hundred rows and will change over time, so i am trying to develop a formula that i can apply easily on all rows/columns in edu-plan!.
The desired result in edu-plan would look like this:
A pivot table might be a good way to go.
If you would like to do it by formula, then you can just use a COUNTIFS
=IF(COUNTIFS(data!$A$2:$A$10,$A2,data!$B$2:$B$10,B$1),"X","")
A possible way to solve your issue with an array formula:
Write in B2 of sheet edu-plan
{=IFERROR(IF(MATCH('edu-plan'!$A2&'edu-plan'!B$1,data!$A$2:$A$6&data!$B$2:$B$6,0)>0,"x",""),"")}
Since it is an array formula, you need to hit shift + ctr + enter.
Here is the formula broken down:
MATCH('edu-plan'!$A2&'edu-plan'!B$1,data!$A$2:$A$6&data!$B$2:$B$6,0)
checks whether the combination of row header and column header is in the data table. MATCH returns the index of the found combination. Since we are not interested in the location, we only ask IF(MATCH > 0, "x", "") to write an "x" if a match was found. If MATCH finds nothing, it returns an error, which is why we add an IFERROR(VALUE, "") around the construct.
In my excel sheet i have the following function:
=IF(AD51="European";
IF(P51<50.000.000; 0,05%;
IF(P51<75.000.000; 0,045%;
IF(P51<100.000.000; 0,04%;
IF(P51<125.000.000; 0,037%;
IF(P51<150.000.000; 0,035%;
IF(P51<200.000.000; 0,034%;
IF(P51<250.000.000; 0,033%;
IF(P51<300.000.000; 0,032%;
IF(P51<400.000.000; 0,031%;
IF(P51<500.000.000; 0,03%;0,025)
)
)
)
)
)
)
)
)
);"American")
Well, I need to replace this in an extra sheet in order to avoid this kind of IF function in a cell.
Here the table:
My question is, how to get the result in the marked cells below:
I need to check if the ID is existing in CalcSheet (Screenshot1) and then to check in which rank the Volume value is categorized in MasterSheet (Screenshot2). Finished the table have to return the %-value of the CalcSheet.
EDIT: I tried it with VLOOKUP(A2;Ranking;3) but I get always the
same procent => 0,03. For your information, Ranking is the range of
the Screenshot1 that I named it.
Complex Lookups in Excel
Solution to your problem using SUMIFS
Updated MasterSheet
CalcSheet with Formula
Formula in CalcSheet!C2:
=SUMIFS(MasterSheet!$D$2:$D$11,MasterSheet!$A$2:$A$11,A2,MasterSheet!$E$2:$E$11,E2,MasterSheet!$C$2:$C$11,">"&B2,MasterSheet!$B$2:$B$11,"<="&B2)
Explanation
VLOOKUP is quite limited in its ability to pick up values. This neat trick with SUMIFS allows fairly complex lookup based on multiple conditions. The trick here is to first ensure that you select one and only cell using conditions and then sum over that one cell.
In this case, we sum over column D in MasterSheet. The conditions are:
MasterSheet Column A matches CalcSheet Column A
MasterSheet Column E matches CalcSheet Column E
MasterSheet Column C is greater than CalcSheet Column B
MasterSheet Column B is less or equal to CalcSheet Column B
Please mark this as answer if this solves your problem.
Update in response to OP's comment
Like the above 4 conditions. You can choose up-to 127 ranges and corresponding conditions in Sumifs in Excel 2016. Check this link in Office Documentation.
I need to count the number of cells in which 'CRITERIA 1' is satisfied, 'CRITERIA 2' is satisfied and 'CRITERIA 3' falls within the set of values contained in column E.
I am currently using the following formula:
=SUM(COUNTIFS(A2:A11,"TRUE",B2:B11,"TRUE",C2:C11,{"2","4","6","9","10"}))
But in my real table, the list of data within 'CRITERIA 3' is longer and more complicated and I would prefer to reference the cells in column E rather than the specific data, i.e. something like:
=SUM(COUNTIFS(A2:A11,"TRUE",B2:B11,"TRUE",C2:C11,{"E2:E6"}))
Please note that the data contained in this example is different to the data in my real table. The real table is considerably longer and more complex than this table.
Any suggestions?
Decided to put my comment as an answer so I can show a picture that it works:
You are close. The Range is an array so no need for the {""} wrapper
Just use:
=SUM(COUNTIFS(A2:A11,"TRUE",B2:B11,"TRUE",C2:C11,E2:E6))
This is an array formula and must be confirmed with Ctrl-Shift-Enter.
You could try SUMPRODUCT
=SUMPRODUCT((A2:A11="TRUE")*(B2:B11="TRUE")*(E2:E6="2"))
Using COUNTIFS the only way I'd know of to check a value is in a list is to create a dummy column that has that check and make that column Criteria3 instead of the actual value.
Going from your example, you'd drop in the following formula in Column D (set text to white so the workbook doesn't look ugly):
=IF(COUNTIF(E$2:E$6, C2)>0, 1, "")
Then your Criteria3 updates such that you have:
=SUM(COUNIFS(A2:A11, "TRUE", B2:B11, "TRUE", D2:D11, 1))
If that's non-ideal, the only other way I can think of would be to use a macro to get that SUM for you.
I know how to make a named range in Excel.
I have a spreadsheet, with various columns going across as parameters, and then finally a formula in the last cell. This is repeated many times in each row, with each row having a different set of data, and the formula updated to reference the correct row index.
However, the formula looks like (three rows worth):
=G2*(10*D2 + 20*E2 + 5*F2)
=G3*(10*D3 + 20*E3 + 5*F3)
=G4*(10*D4 + 20*E4 + 5*F4)
I would like to use named ranges, but I can't find a way to do something like
=Count * (10*var1 + 20*var2 + 5*var3)
where count, var1, var2, and var3 automatically update to be the particular column of the current row. I can create a named range for every cell, but that isn't helpful. I can name range the column, but then I can't find a way to put an offset into the formula.
Also the whole point of this is readability, so if it ends up being some nasty complex formula function call, that probably doesn't help too much.
Simple, at least when using Excel 2010:
name your column: select full column, enter name
use column name in formula; Excel will combine the referenced column with the current row to access a single cell.
Using the example from Alex P:
select column D by clicking the column header containing the "D", enter name "input1" into name field, and press Enter.
repeat for columns E to F, using "input2" and "input3", respectively.
Do not define additional names defining names "input1" [...] as in example above!
use the formula as given in the example above
Attention:
Using named columns this way, you cannot access any other row as the one your formula is in!
At least I'm not aware of the possibility to express something like <ColName>(row+1)...
I would suggest creating a Table. Select your range A1:H4, then go to the Tables widget > New > Insert Table with Headers (on Mac). This will mark A2:H4 as body of the table, and A1:H4 as header.
From that, you get:
Whatever you put into the header column will define the name for this column automatically, e.g. Count, Radius, Density, Height
You can then write your formula using =[#Count]*(10*[#Radius] + 20*[#Density] + 5*[#Height])
When you change the formula in cell H2, Excel will automatically "copy down" this formula to all cells in column H. So no more accidental inconsistencies in the formulas.
When you need to add another row, simply click the last cell (in our example H4) and hit Tab. Excel adds another row, and also makes sure to "copy down" your formula into the new row.
If you need a total row, add it with the Total Row checkbox in the Tables widget. Excel adds a total row automatically. If you click any cell in the total row, you can change the "total formula" with the "▼▲" button, for example to calculate the Average instead of the Sum of the column.
If you have a long table and scroll down so that the header is not visible anymore, Excel automatically displays the column header instead of the column names (Count instead of G for example).
I can really recommend the video You Suck at Excel with Joel Spolsky which explains all of that.
Suppose I have the following numbers set up in columns D to F in rows 2 to 4:
D E F G
2 10 15 20
3 1 2 3
4 20 30 40
Now suppose I want the value in column D to be known as input1, column E to be input2, and column F to input3:
In Insert > Name > Define...
input1 RefersTo =OFFSET(Sheet1!$D$2,0,0,COUNT(Sheet1!$D:$D),1)
input2 RefersTo =OFFSET(Sheet1!$E$2,0,0,COUNT(Sheet1!$E:$E),1)
input3 RefersTo =OFFSET(Sheet1!$F$2,0,0,COUNT(Sheet1!$F:$F),1)
Now if I write my formula in column G as follows I should get correct answers:
G2 =(10*input1+20*input2+30*input3) // 1000
G3 =(10*input1+20*input2+30*input3) // 140
G5 =(10*input1+20*input2+30*input3) // 2000
I haven't fully reviewed the previous answers, but I think this is closer to what #Jason Coyne the OP was looking for. So, I hope I get a lot of up votes. ;-)
Excel allows your formula to refer to tables and columns by name if you "Format as Table". Here is an article titled Using structured references with Excel tables that goes into detail.
FWIW, it looks like this feature has been available since Excel 2007.
Here is a screenshot of an example:
You should be able to see the formula in E2 is =[#Count] * (10*[#Var1] + 20*[#Var2] + 5*[#Var3]) which is pretty close to what #jason-coyne wanted to type.
I don't like that you are forced to pick a style (or define a new one if you don't see a style you like). The good news is you can reformat the cells all you wish without undoing the "tableness".
It insists on turning on auto-filter. But, auto filter is easy to turn off (see the Filter Button checkbox under the Table Tools Design menu).
It also insists on having non-empty, unique values in the header row (Which kinda makes sense). If you delete a header cell, or insert a column, Excel will invent a new, unique name and stuff it in for you. D'oh!
If you want a column to not have a header, you can enter an apostrophe (') followed by one or more blanks. Remember header values need to be unique, so keep adding blanks if you want more than one column without a header.
If you would like to download the sample workbook in the screenshot, here is a link: https://filebin.ca/3vfaSDn4NLEA/SampleWorkbook.xlsx
Adding to Alex P's answer:
Instead of using =OFFSET(Sheet1!$D$2,0,0,COUNT(Sheet1!$D:$D),1) as the formula for input1, I recommend to use =Sheet1!$D$2:INDEX(Sheet1!$D:$D,COUNT(Sheet1"$D:$D))
It produces the same result, but it is non-volatile, i.e., only recalculate when a predecessor cell changes. This is much better in a larger model!
If you're using VBA, then you can select the whole column and name it, say MyCol, in the name box (upper left input box). The in your code you can refer to a cell in the column MyCol (line 12) using the following code:
Cells(12, Range("MyCol").Column)
You might be able to use the row() function. This returns the current row that you are in. So depending on the layout of the spreadsheet you can use it like this:
=offset(NamedColumn1, row()-1)
The -1 is because you are saying how many rows to move down from row 1 which if you are in row 1 you want to be 0.
Use the Excel feature called named references.
To name a cell or range of cells
select that cell or range of cells
Enter its name in the Name Box ( its left of the formula widget and has the cell name )
You can't use names that conflict with cell names, like k0.
The named cells can be used if formulas. E.g.,
=pi*radius*radius
I'd like to propose a slight variation of the cell reference made by Dror. This will work as well:
Range("MyCol").Rows(12)