how to map/pull column in 1 sheet based on another to repeating values in excel? - excel

I have excel sheet with repeating ids
id jun19
1 3
2 2
3 7
1 3
2 2
3 7
1 3
2 2
3 7
i want to append another column 'jul19' from another sheet.
that jul19 sheet has all and even more ids:
id jul19
1 4
2 6
3 45
4 7
5 9
it should take only those that have the id and pull values from column 'jul19'.
the end result is this:
id jun19 jul19
1 3 4
2 2 6
3 7 45
1 3 4
2 2 6
3 7 45
1 3 4
2 2 6
3 7 45
how to do this? how to pull corresponding values from column "jul19" based on the id?
I tried to do this in pandas, but failed.

Assuming table1 is in A1:B10, table2 is in D1:E6, & table3 is in G1:I10. put :
=INDEX(E:E,MATCH(G2,D:D,0)) in I2
and drag downwards. ref : https://exceljet.net/index-and-match
Hope it helps. ( :

Related

Deleting a row with VBA in Excel gives invalid reference in another table

I have an Excel Workbook with 2 sheets. Each sheet contains a formatted table.
The tables start at row2 and feature an internal numbering in columnA achieved by the formulas
=Row()-Row(talble1)+1 and =Row()-Row(talble2)+1
sheet2:
In table2/columnB I concatenate 2 of the internal row indices from table1 using the formulas
table2/internal row1: =CONCATENATE(sheet1!A2;";";sheet1!A3;";")
table2/internal row2: =CONCATENATE(sheet1!A4;";";sheet1!A5;";")
table2/internal row3: =CONCATENATE(sheet1!A6;";";sheet1!A7;";")
table2/internal row4: (...)
It looks like this:
sheet1/table1: sheet2/table2:
A B C A B C
1 1
2 1 2 1 1;2
3 2 3 2 3;4
4 3 4 3 5;6
5 4 5
6 5 6
7 6 7
8 8
9 9
If I "manually" delete the 2 rows with internal indices 3 and 4 in table1, the numbering automatically adjusts. Also, the references in internal row2/columnB of table2 become invalid, which makes total sense. The formula of internal row3 in table2 automatically adjusts to the deletion in table1 and remains valid.
It then looks like this:
sheet1/table1: sheet2/table2:
A B C A B C
1 1
2 1 2 1 1;2
3 2 3 2 invalid
4 3 4 3 3;4
5 4 5 4
6 6 5
7 7 6
8 8
9 9
Now comes the issue:
If I do the deletion described above using a VBA macro, the references in internal row3 of table2 become invalid as well! When I check the formula I see that it still references cells A6 and A7 which don't exist anymore in table1.
I used the code
sheet1.ListObjects("table1").DataBodyRange.Rows(4).Delete Shift:=xlUp
sheet1.ListObjects("table1").DataBodyRange.Rows(3).Delete Shift:=xlUp
It looks like this:
sheet1/table1: sheet2/table2:
A B C A B C
1 1
2 1 2 1 1;2
3 2 3 2 invalid
4 3 4 3 invalid
5 4 5 4
6 6 5
7 7 6
8 8
9 9
What is the explanation for the different behaviour of deleting a row in table1 manually or by VBA code?
I also recorded macros when deleting the rows manually and I could not detect anything that explains why my macro code leads to the invalid references in internal row3 of table2.

Excel - Shift starting column right by x

In excel I have a dataset. This represents how much stock of 2 products is sold in the first, second, third, etc... month of the product being on the shelves (starts in A1):
Month 1 2 3 4 5 6 7 8 9 10 11 12
Product 1 3 5 2 1 6 1 2 4 7 2 1 5
Product 2 2 1 5 6 2 8 2 1 2 3 4 9
However, the first product sales do not always occur in month 1. They occur in month X. Is there a way (not VBA or copy and paste) of shifting the entries right by 'x' so they align with the month.
Example for data above
Product 1 starts in month 2
Product 2 starts in month 5
Month 1 2 3 4 5 6 7 8 9 10 11 12
Product 1 0 3 5 2 1 6 1 2 4 7 2 1 5
Product 2 0 0 0 0 2 1 5 6 2 8 2 1 2 3 4 9
*0 not required (great if possible), but more for illustration
Thanks
I have created a simple example that does the same job. The shown formula is copied over the shown cells in the row of new data. (The number '2' in the formula refers to the column number of the starting data cell which is column B, hence 2.)

How to multiple column join in one column in excel (I Want Formula)

HOW TO JOIN MULTIPLE COLUMN IN ONE COLUMN
TABLE 1 TABLE 2 TABLE 3
1 2 5
2 4 3
3 5 3
4 5 1
I WANT TO
1
2
3
4
2
4
5
5
5
3
3
1
If your data is like below, enter the formula in the first row of any column and drag down until there is no value left over,
=IF(ROW()<=COUNTA(A:A),INDEX(A:A,ROW()),IF(ROW()<=COUNTA(A:B),INDEX(B:B,ROW()-COUNTA(A:A)),IF(ROW()>COUNTA(A:C),"",INDEX(C:C,ROW()-COUNTA(A:B)))))

Excel - How do I create a cumulative sum column within a group?

In Excel, I have an hours log that looks like this:
PersonID Hours JobCode
1 7 1
1 6 2
1 8 3
1 10 1
2 5 3
2 3 5
2 12 2
2 4 1
What I would like to do is create a column with a running total, but only within each PersonID so I want to create this:
PersonID Hours JobCode Total
1 7 1 7
1 6 2 13
1 8 3 21
1 10 1 31
2 5 3 5
2 3 5 8
2 12 2 20
2 4 1 24
Any ideas on how to do that?
In D2 and fill down:
=SUMIF(A$2:A2,A2,B$2:B2)
Assuming that your data starts in cell A1, this formula will accumulate the hours until it finds a change in person ID.
=IF(A2=A1,D1+B2,B2)
Put the formula in cell D2, and copy down for each row of your data.

Data fill in specific pattern

I am trying to fill data in MS Excel. I am given following pattern:
1 2
1
1
2 5
2 5
2
3
3 6
3
4
4
5 4
And I want my output in following format:
1 2
1 2
1 2
2 5
2 5
2 5
3 6
3 6
3 6
4
4
5 4
I tried using if(b2,b2,c1) in column 3. but that doesn't solve the problem for a=3 and a=4.
Any idea how to do this in Excel?
With sorting thus:
(the effect of which in this case is merely to move 6 up once cell) and a blank row above:
=IF(AND(A2<>A1,B2=""),"",IF(B2<>"",B2,C1))
In C2 and copied down should get the result you ask for from the data sample provided.

Resources