I have two worksheets that have two columns of data. In column A of the Worksheets are the name of an item and in column B are the price of the item. Worksheet 1 has the price from last year and worksheet 2 has price from this year. The names of items in Worksheet 1 may or may not be in Worksheet 2.
I need a process that will match the names in each worksheet and if there is a match determine the price differential for that item. The price differential will go in column C in worksheet 2.
I have considered using an if-then function with a vlookup function but, I need to check for a match in all columns A from worksheet 1 and worksheet 2 for all the records. I believe a VB looping process may be more efficient.
Since it would appear to me you are only likely to require this once (or once a year) efficiency does not seem to be very significant, so formulae may serve.
Assuming labels (respectively: Item_Name and Price_O in Sheet1, Item_Name, Price_N and Diff in Sheet2) in Row1 then the following formulae (copied down to suit) should indicate where there is no match (with #N/A or, if there is, the price change relative to last year:
In Sheet1 C2: =IF(MATCH(A2,Sheet2!A:A,0)>0,"")
In Sheet2 C2: =B2-VLOOKUP(A2,Sheet1!A:B,2,FALSE)
Alternatively, a pivot table might provide a better overview, in combination with:
In Sheet2 H5: =IF(OR(ISBLANK(F5),ISBLANK(G5)),"No Match",G5-F5) (copied down to suit).
In Sheet2 E1 call up the PivotTable wizard (Alt+D, P if required) , select Multiple consolidation ranges and PivotTable, Next.
Select I will create the page fields, Next.
In Range select or insert Sheet1!$A:$B, Add, then Sheet2!$A$B, Add, Next, select Existing worksheet and enter =$E$3, Finish.
Right click on table and if necessary change Σ Values from Count of Value to Sum of Value (by left clicking on Count of Value, left clicking on Value Field Settings… and selecting Sum in Summarize by), OK.
Right click on the table, left click on PivotTable Options, left click on Totals & Filters and if necessary untick Show grand totals for rows, OK.
If necessary, right click on PriceN in the table, Sort, Sort Z-A.
Related
I was trying to build a periods model using Finicast. I am stuck at this step where I apply a formula to the cells with dimension 'Fcst' and 'Revenue' in my pivot table.
Based on my understanding, if I select Revenue cell for month of Jul22, the formula THIS("idx") should have been applied and the cell should contain the value 7 instead of 0. I have other formulas applied to this cell. But I have my rev_fcst formula top precedence to apply on this cell. Irrespective of which order I apply the formulas in, in this selection, the value for months & Revenue cells remain 0.
What am I missing here?
I have added images of my formula bar, pivot table, and dimensions
The formula bar
The rows highlighted by selecting Fcst and Revenue
periods table for reference
Looking at the image you posted, you have a set of "hardcoded" 0's for Jul22, Aug22 and Sep22. Click on those cells and press the Delete key to remove the hardcodes, and then the underlying formula will show-up again.
I have two sheets: flight control and total hours control. Link to sheets.
Flight Control:
Total Hours:
What I want: On Total Hours, Sum the Flight Time if:
Column Name(L.D.1) matches row on Line; row Pilot matches row Pilot; cell has a value of 1.
I'm using this for cell C2, and it works:
=SUMIFS('Flight Time'!B:B;'Flight Time'!A:A;B2;'Flight Time'!C:C;"1")
And it works, giving me this:
However, this isn't very practical. I have to redo the formula every time a new pilot is introduced. And if I move columns around, it stops working.
What I need: To base my conditions on a text search. Something like:
If column name in {Flight Time!C:F} matches string on {row in col Line}, and Pilot = Pilot, and cell value = 1, SUM
In other words, I need to scale this. The final product will have dozens of pilots and L.D.s, so I need to be able to move things around.
My answer is similar to player0's but it anticipates a Flight Time tab that expands infinitely sideways as well as down.
You would start a new tab and place this formula in cell A1.
=ARRAYFORMULA(QUERY(SPLIT(TRANSPOSE(TRIM(SPLIT(QUERY(TRANSPOSE(QUERY('Flight Time'!C1:1&"|"&'Flight Time'!A2:A&"|"&OFFSET('Flight Time'!C2;;;ROWS('Flight Time'!C2:C);COLUMNS('Flight Time'!C2:2))*'Flight Time'!B2:B&CHAR(10);;9^99));;9^99);CHAR(10);0;0)));"|";0;0);"select Col1,Col2, SUM(Col3) where Col3>0 group by Col1,Col2 label Col1'Line',Col2'Pilot',SUM(Col3)'Total Hours'"))
Sometimes in complicated formulas like this, it can be difficult to translate to your real sheet if you haven't placed the sample data in exactly the same layout on the sample as it is on your real sheet. If that is the case here, change the layout of the sample so that it better matches your real data, and I can try to update the formula.
use:
=ARRAYFORMULA(SPLIT(
TRANSPOSE(QUERY(TRANSPOSE(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(
IF(C2:F="",,"♠"&C1:F1&"♦"&A2:A&"♣♥"&B2:B),,999^99)),,999^99), "♠")), "♥"),
"select Col1,sum(Col2) group by Col1 label sum(Col2)''")),,999^99)), "♦♣"))
I have two sheets, sheet1, and sheet2. Column E of sheet2 contains a quantity and column K contains a text string (i.e. a key). Multiple rows in sheet2 contain the same text string with different quantities.
On sheet1 column B, I have a list of text strings. For each text string, I want to query sheet2 and sum up all the quantities in its E column where the value in the K column matches the text string.
Currently, I need x queries where x is the number of text strings in column B of sheet1.
Each current query in sheet1 looks like this:
Query in sheet1 cell A1 using text string in B1 of sheet1
=SUM(
QUERY(
'sheet2'!$A$2:INDIRECT(CONCATENATE("'sheet2'!O",'sheet2'!P1)), "select E where K="""&B1&""""
))
Query in A2 using text string in B2 of sheet1
=SUM(
QUERY(
'sheet2'!$A$2:INDIRECT(CONCATENATE("'sheet2'!O",'sheet2'!P1)), "select E where K="""&B2&""""
))
and so on...
Cell P1 of sheet2 contains the number of non-zero rows in sheet2
This works well, but the problem is that sheet2 contains 200,000 rows.
I have around 100 text strings to search for, so I am currently using 100 queries, each of which looks at 200K rows x 15 columns = 3 Million cells
Understandably it takes a long time for the sheet to update as all these queries re-run when sheet2 is updated.
Is it possible to consolidate all of these queries to one? In other words, tell the formula "I want you to perform the sum-query using each cell in the range B1:B100 as the variable x for K=x in the query and place the results in cells A1:A100 respectively"?
in some cases putting it into array may boost a bit the performance:
={SUM(QUERY('sheet2'!$A$2:INDIRECT(CONCATENATE("'sheet2'!O", 'sheet2'!P1)),
"select E where K="""&B1&""""));
SUM(QUERY('sheet2'!$A$2:INDIRECT(CONCATENATE("'sheet2'!O", 'sheet2'!P1)),
"select E where K="""&B2&""""))}
however, too many QUERY functions should be avoided to prevent the halt. the best performance belongs to DGET and alternatives include FILTER and SUMIF
This I hope as your single query, B8 must be change to the last row in sheet1
=arrayformula(vlookup({Sheet1!B1:B8},QUERY(Sheet2!A1:K,"select K, sum(E) where K<>0 group by K "),2,false))
I have 2 columns in a sheet that are referencing another dynamic sheet which has new rows added at the top all the time.
I want column A to be a copy of column A in Sheet1, so this works to put in cell A1:
={Sheet1!A:A}
However, I want column B to a formula applied to every row in column B of Sheet1. Problem is, when I put in a a formula, e.g.
=formula(B1)
then it changes to
=formula(B30)
when 29 new rows added
I want it to stay as B1, but it won't. If I use an absolute reference $B$1 then I can't copy the formula down the column.
Any wizards out there to help me out?
If you want to get the matching row from a column of another worksheet, then use INDEX and ROW, like so:
=FORMULA(INDEX(Sheet1!$B:$B, ROW(), 1))
This will always return the value in Column B of Sheet1, on the same Row as the formula is in on Sheet2 - even if you insert rows at the top of Sheet1
You can do "partially absolute reference" (I don't know the correct way of saying this).
You can lock only the column so would be =$A1 which means that it will never change the column but when you drag down the formula, it will change to =$A2, =$A3...
Or you can lock only the row typing =A$1 This way it will be locked on the row only.
You can do this also by pressing F4 several times: 1 time will lock both, the 2nd time will lock the row only, the 3rd time the column only and the 4th time will delete the locking.
the proper way would be to use INDIRECT like:
=INDIRECT("Sheet1!B1:B")
I would like to retrieve average daily milk from sheet 1 to sheet 2. Each row has a unique identification number. The average daily milk data exported to sheet 2 is linked to the unique ID Nr. In sheet 1 there are many more unique ID.Nr ( Rows) present than in sheet 2. How do I transfer the data from sheet 1 to sheet 2 in exact correlation to identification nr, without sorting the rows?
I have tried vlookup function but result is always NA. I belive it should be an array function, as it has too look for ID Nr. and cannot use position of cell.
Table Sheet1 is on a different Worksheet than Sheet 2 but on same File.
Vlookup should work just fine. The only thing is that you have to make sure that the Id Nr. in both sheets are the same type (In this case both should be strings since they have "_" in the text). This is how you should use the vlookup:
=VLOOKUP(A2,Sheet1!A:B,2,FALSE)
And then copy the formula all the way down in column B of sheet2
The solution is to use the index match function. The advantage in comparison to an lookup function is that it handles great amount of data better and also the reference number does not need to be on the far left column.