Forum Discussion
calculated column to display comma separated values as the text lookup value for each value
I have two tables, one lists the text string values and an ID, the other has a comma separated list of ID's, i want to display a concatenated text list in a single cell based on the ID's in the main table, so:
Table 1
ID Text Value
Table 2
Lookup value to Table 1 = comma separated IDs
what we need is comma separated text values.
I believe what you want is a VALUES and CONCATENATEX formula
10 Replies
- Greg_Deckler
Community Champion
I believe what you want is a VALUES and CONCATENATEX formula
- Phil_Seamark
Microsoft Employee
Hi jlynch
I think I follow what you need, but just to be sure, can you please mock up a small sample of fake data for your two tables including your expected result. We can try and help you with the middle part. :)
- MarcelBeug
Community Champion
This is my interpretation and Power Query solution:
CSTV query code:
let Source = Table2, // Get nested lists of ID numbers SplitToIDNumbers = Table.TransformColumns(Source,{},each List.Transform(Text.Split(_,","),Number.From)), // Add index as a grouping for the IDs after expansion AddedIndex = Table.AddIndexColumn(SplitToIDNumbers, "Index", 0, 1), ExpandedIDs = Table.ExpandListColumn(AddedIndex, "IDs"), // Get the Text Values from table1 MergedWithTable1 = Table.NestedJoin(ExpandedIDs,{"IDs"},Table1,{"ID"},"NewColumn",JoinKind.LeftOuter), // Expand the nested tables ExpandedTextValues = Table.ExpandTableColumn(MergedWithTable1, "NewColumn", {"Text Value"}, {"Text Value"}), // Use Transform - Group By to create base code (e.g. use group function "Sum" for the text values, then adjust the code to Text.Combine Grouped = Table.Group(ExpandedTextValues, {"Index"}, {{"Text Values", each Text.Combine([Text Value],","), type text}}), RemovedIndex = Table.RemoveColumns(Grouped,{"Index"}) in RemovedIndex:
- jlynchFrequent Visitor
Marcel...
the example is perfect, the solutions I'm not sure of, I'm in Power BI, I don't know M so I'm not sure, do I go to the Query Editor and there enter the formulas you indicated, is this a measure or a column? Sorry to be a bit slow on this one, but I think the process is just beyond my skill level?
- jlynchFrequent Visitor
Marcel below has interpretted what i need accurately, I'm going to attempt his solution but it's a bit more of a code solution than I'm used to.
- MarcelBeug
Community Champion
Coincidentally I just recorded a video for another question in which I demonstrate the same technique for concatenating the text values.