Create a column "looking up" from another column

gxm204

New Member
Joined
Nov 20, 2015
Messages
29
Hi, For this example (as shown below) I have a `year` column and I would like to create a `decade` column based on those values.

In "classic Excel" I'd probably create a lookup table. What would be the best Power Query strategy for this? Make a separate lookup table and then do a left join? Or is there a way to do it all in one?

Thanks all!

2019-12-23_12-23-17.png
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
post a link to shared file with source data and expected result not a picture
 
Upvote 0
I don't think you need a lookup at all.
Just try this formula (for an entry in cell A1):
=LEFT(A1,3)&"0-"&LEFT(A1,3)&"9:"&LEFT(A1,3) & "0's"
 
Upvote 0
What would be the best Power Query strategy for this?
I apologize. I was distracted and talking to someone while I was replying and obviously did not read the question as closely as I should have.
 
Upvote 0
@Joe4 OK maybe that was a bad example to use ?‍♂️ but I do like using `LEFT()` in this example!
Let's say for example I have a list of teams. I want to create a column based on their league, but don't have a lookup table handy, should I make one? Or is there some kind of function in PQ that would create the groupings for me? Maybe it's just an IF statement.
 
Upvote 0
Unfortunately, I do not know Power Query (sadly, my workplace won't let me download it, and I don't have that much time at home), but Sandy does, so hopefully he will be able to help you (your question seems to be pretty straightforward).
 
Upvote 0
I created a table with years and the Mcode for that file is:
VBA Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Middle([Year],2,1))
in
    #"Added Custom"

Second Table looks like below:

Book1
AB
221920's
331930's
441940's
551950's
661960's
771970's
881980's
991990's
1002000's
1112010's
Sheet3


Mcode for that table:
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}})
in
    #"Changed Type"

Mcode to merge tables:
Code:
let
    Source = Table.NestedJoin(Table1, {"Custom"}, Table2, {"Column1"}, "Table2", JoinKind.LeftOuter),
    #"Expanded Table2" = Table.ExpandTableColumn(Source, "Table2", {"Column2"}, {"Table2.Column2"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Table2",{"Custom"})
in
    #"Removed Columns"

Result
Book1
AB
1YearTable2.Column2
219211920's
319221920's
419231920's
519301930's
619351930's
719361930's
819401940's
919411940's
1019521950's
1119531950's
1219621960's
1319631960's
1419711970's
1519721970's
1619741970's
1719851980's
1819861980's
1919951990's
2019961990's
2120002000's
2220012000's
2320052000's
2420152010's
2520162010's
2620192010's
Sheet5
 
Upvote 0

Forum statistics

Threads
1,226,126
Messages
6,189,149
Members
453,526
Latest member
anyrandomtech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top