I have two Excel Tables with a 'lookup' column to merge against. I want to merge to a new table with all the lookup values expanded. If I were doing this in python or some such, the pseudo-code would be something like:
for unique day in Tbl1
row1 = day
row2 = ""
for event in Tbl1 day
v = event's lookup value in Tbl2
row1 += event + (len(v) - 1) blank columns
row2 += v
print(row1)
print(row2)
I'd like to avoid VBA, but would like to use new dynamic array functions (preferred) or power query (if necessary), but I can't figure out how to get the repeat to happen. The power query merges I've tried aren't complete.
The original data (where I've used abbreviations for my real data), has a number of events per day. The 'lookup' column shows the different levels of that event for that day.
Tbl1
day | event | lookup |
---|---|---|
1 | Re | eoni2 |
1 | Gr | eoni1 |
1 | We | eoni1 |
2 | Tn | eoneonii2 |
2 | Ga | eon1 |
2 | Gr | eoni1 |
Tbl2
lookup | c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 |
---|---|---|---|---|---|---|---|---|
eeononii | E | E | O | N | O | N | I | I |
eon1 | E | O | N | |||||
eoneonii2 | E | O | N | E | O | N | I | I |
eoni1 | E | O | N | I | ||||
eoni2 | E | E | O | O | N | N | I | I |
Tbl1
- Data will change: number of events per day, event value, what lookup value might be for an event.
- The 'event' may or may not repeat from one day to the next, but will be unique within a day.
- Order (top to bottom) should be maintained in resulting merge (left to right).
- Max number of days = 3.
Tbl2
- generally static and top to bottom order can be changed if needed.
- may contain entries that are not used by Tbl1.
- min of 3 and max of 8 values per row.
Tbl3 output
- ideally, the 'event' name would not repeat, as shown below, but can if it keeps formula cleaner.
- the number of columns for each day in output Tbl3 may not be the same, as shown, e.g. day 1 rows have 16 and day 2 rows have 15 here.
The output I want:
Tbl3
day | e1 | e2 | e3 | e4 | e5 | e6 | e7 | e8 | e9 | e10 | e11 | e12 | e13 | e14 | e15 | e16 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | Re | Gr | We | |||||||||||||
E | E | O | O | N | N | I | I | E | O | N | I | E | O | N | I | |
2 | Tn | Ga | Gr | |||||||||||||
E | O | N | E | O | N | I | I | E | O | N | E | O | N | I |
Thanks much.