Forum

Dynamically creatin...
 
Notifications
Clear all

Dynamically creating concatenated column

8 Posts
4 Users
0 Reactions
92 Views
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

Hello Guys,

i have table :

Screenshot_128.png

And now i am building Table1 query where i want to add additional custom - concatenated columns based on ListOfTables table. 

Screenshot_129.png
As you can see concatenation column (Key) is made only from Col1&Col2&Col3 because in ListOfTables table there is no more Concatenated colums listed for the specific table. 

How to build dynamic solution for the issue?

It would be nice to create a dynamic list based on Table name from ListOfTables and matching columns from used table, in our example Table1. 

In Other words, 
How to dynamically add Key column concatenated with columns listed in ListOfTables into specific query? 

Please help,
Jacek

 
Posted : 25/02/2021 6:59 am
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

Anyone can help?

Best,
Jacek

 
Posted : 26/02/2021 4:10 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Jacek,

I don't really understand what you are trying to do.

Can you try to explain it again with some real tables and columns?

Regards

Phil

 
Posted : 26/02/2021 8:06 am
(@mynda)
Posts: 4761
Member Admin
 

Hi Jacek,

I think the problem with the example is that the data in the columns is the same as the column headers. It's also not clear whether you want to refer to column numbers or real column names because the example uses column names with numbers.

Perhaps some more realistic example data will help us infer what you really want. It would also be good to have some background information on why you want to do this as the solution you're requesting might not be the most efficient.

Mynda

 
Posted : 26/02/2021 7:13 pm
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

Hi Guys,

thank you.
All what i need is to refer to column names and use them dynamically in concatenation column. 

So instead of writing manually string in concatenated formula: "=[Col1] & "-" & [Col2] & "-" & [Col3]" i want to create list of column names dynamically and use the list in concatenated formula to not do this manually. 

I hope it is clear now.

So how to provide dynamic list from table header names in order to use them in a list in concatenated formula syntax?

please ask if something is not understandable. 

Best,
Jacek

 
Posted : 27/02/2021 5:51 am
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

Anyone can help?

Best,
Jacek

 
Posted : 02/03/2021 1:16 am
(@debaser)
Posts: 837
Member Moderator
 

I'd imagine this can be simplified, but it's been a long day!

 

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Col1", type text}, {"Col2", type text}, {"Col3", type text}}),
#"Added Custom1" = Table.AddColumn(#"Changed Type", "TableName", each "Table1"),
#"Merged Queries" = Table.NestedJoin(#"Added Custom1",{"TableName"},ListOfTables,{"TableName"},"ListOfTables",JoinKind.LeftOuter),
#"Added Custom" = Table.AddColumn(#"Merged Queries", "Key", each Table.ToList(Table.SelectColumns([ListOfTables], {"ColumnsToConcatenate"}))),
#"Added Custom2" = Table.AddColumn(#"Added Custom", "Custom", each Text.Combine(Record.FieldValues(Record.SelectFields(_, [Key])), ","))
in
#"Added Custom2"

 
Posted : 02/03/2021 12:53 pm
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

O wow this is awesome! 

Working like a charm, thank you so much!

Best,
Jacek

 
Posted : 03/03/2021 4:15 am
Share: