Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Concatenate string from relating rows

Dear All,

I have a use case where I would like to create description strings for a travel company about road trips.

 

Summary table:

Road trip IDDescription string
Travel1Milano-Geneva-Paris
Travel2Berlin-Amsterdam-Brussels

 

Raw data table

Road trip IDStop indexStop place
Travel11Milano
Travel12Geneva
Travel13Paris
Travel21Berlin
Travel22Amsterdam
Travel23Brussels

 

How can I create the descirption string in the summary table?

 

Thank you for your support in advance!

1 ACCEPTED SOLUTION
camargos88
Community Champion
Community Champion

@Anonymous ,

 

Check this new code:

Summary = 
    ADDCOLUMNS(
        VALUES('Table'[Road trip ID]), 
        "Desc", CONCATENATEX(FILTER('Table', 'Table'[Road trip ID] = EARLIER('Table'[Road trip ID])), 'Table'[Stop place], "-", 'Table'[Stop index], ASC) 
    )

 

Concatenex has a sort by parameter.



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

6 REPLIES 6
v-yangliu-msft
Community Support
Community Support

Hi  @Anonymous ,

 

Here are the steps you can follow:

1. Create calculcated table.

Row data table =
SUMMARIZE(
    'Table',
    'Table'[Road trip ID],
    "Description string",CONCATENATEX(FILTER('Table','Table'[Stop index]<='Table'[Stop index]),'Table'[Stop place],"-"))

2.  Result.

v-yangliu-msft_0-1605662103360.jpeg

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

camargos88
Community Champion
Community Champion

@Anonymous ,

 

Check this new code:

Summary = 
    ADDCOLUMNS(
        VALUES('Table'[Road trip ID]), 
        "Desc", CONCATENATEX(FILTER('Table', 'Table'[Road trip ID] = EARLIER('Table'[Road trip ID])), 'Table'[Stop place], "-", 'Table'[Stop index], ASC) 
    )

 

Concatenex has a sort by parameter.



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Anonymous
Not applicable

Thank you very much!

AlB
Super User
Super User

Hi @Anonymous 

I assume you have the summary table in place with the Road trip ID column. If so:

Description string =
CONCATENATEX (
    CALCULATETABLE (
        DISTINCT ( RawTable[Stop place] ),
        FILTER (
            ALL ( RawTable[Road Trip ID] ),
            RawTable[Road Trip ID] = SummaryTable[Road Trip ID]
        )
    ),
    RawTable[Stop place],
    "-"
)

This can also be done in Power query, and it would be probably better.

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

camargos88
Community Champion
Community Champion

@Anonymous ,

 

You can use this mcode:

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCilKLEvNMVTSUQJh38ycxLx8pVgdZAkjIHZPzUstS0STMAbigMSizGIkcSOoSU6pRTmZeWgSIOyYW1ySWpSSmIsmBzLMqai0uDg1B2heLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Road trip ID" = _t, #"Stop index" = _t, #"Stop place" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Road trip ID", type text}, {"Stop index", Int64.Type}, {"Stop place", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Road trip ID"}, {{"Rows", each Table.Sort(_, "Stop index"), type table}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Text.Combine([Rows][Stop place], "-")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Rows"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Custom", type text}})
in
    #"Changed Type1"

 

 

Capture.PNG

 

 

This is a DAX solution:

 

Summary = ADDCOLUMNS(VALUES('Table'[Road trip ID]), "Desc", CONCATENATEX(FILTER('Table', 'Table'[Road trip ID] = EARLIER('Table'[Road trip ID])), 'Table'[Stop place], "-"))
 
Capture.PNG


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Anonymous
Not applicable

Hi @camargos88 ,

 

I tried your proposed DAX and it works almost perfectly. However it does not consider the stop index, which determines the sequence of the locations in the string.

 

Do you have any idea how to adjust the DAX?

 

Thank you very much!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.