question

Will-4655 avatar image
0 Votes"
Will-4655 asked Will-4655 commented

Power Query new custom column from another table

Hi all,

I have something similar to the following tables:

Table1:
60264-image.png
...

Table2:
60229-image.png
...

And would like to add [Weight] as a new column to table2 based off [Product] in table2 starting with [Product] in table1. I have the following but can't seem to get it to work:
Table.SelectRows(
table1[Product],
Text.StartsWith([Product],table1[Product])
)

Any help would be greatly appreciated

Thank you

power-query-not-supported
image.png (2.7 KiB)
image.png (2.4 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Lz-3068 avatar image
1 Vote"
Lz-3068 answered Will-4655 commented

Hi @Will-4655

With the data you exposed the following does it - code for Table2:

 let
     Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
     ChangedTypes = Table.TransformColumnTypes(Source,{
                 {"Product", type text}, {"Category", Int64.Type}}),
     AddedWeight = Table.AddColumn(ChangedTypes, "Weight",
         (tbl2) => Table.First(
             Table.SelectRows(Table1, each Text.StartsWith(tbl2[Product], [Product]))
         )[Weight],
         Int64.Type
     )
 in
     AddedWeight


Corresponding sample avail. here


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Great, thanking you!

0 Votes 0 ·