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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
sonalisaha2310
Helper II
Helper II

Concatenate multiple columns without repeating the duplicate values , please help

I have a multiple columns named as overall , sub1  given, sub2  given , sub3  return

Overallsub1   Givensub2  Givensub 3  Return
Bag   
BagBottlePurse 
 BagBag 
 HeadsetMonitor 
NotebookDiary  
Bag, Notebook,Bottle  Bag
Diary   

I want to concatenate (overall + sub1 given + sub2  given ) - sub3 return , If overall , sub1given,sub2given contains the value as in sub3 return then the new column should elimate that value.  Also if overall , sub1 given , sub2 given contains the same string then it should write the string only one time ,The result should look like below

Overall Accessories 
Bag
Bag,Bottle,Purse
Bag
Headset,Monitor
Notebook,Diary
Notebook,Bottle


Thank you

Regards,

Sonali Saha

1 ACCEPTED SOLUTION
barritown
Super User
Super User

Hi @sonalisaha2310,

Here is a way to solve it with DAX:

barritown_0-1709581959630.png

DAX code in plain text for convenience (see also the attached file):

Result = 
VAR curRow = SUBSTITUTE ( [Overall], " ", "" )
VAR curRowH = SUBSTITUTE ( curRow, ",", "|" )
VAR nItems = PATHLENGTH ( curRowH )
VAR res = IF ( NOT ISBLANK ( nItems ), 
    VAR _tbl1 = SUMMARIZE ( ADDCOLUMNS ( GENERATESERIES ( 1, nItems ), "sub", PATHITEM ( curRowH, [Value] ) ), [sub] )
    VAR _tbl2 = DISTINCT ( UNION ( _tbl1, { [sub1 Given], [sub2 Given] } ) )
    VAR _tbl3 = FILTER ( _tbl2, NOT ISBLANK ( [sub] ) && [sub] <> [sub3 Return] )
    RETURN CONCATENATEX ( _tbl3, [sub], "," ),
    VAR _tbl4 = FILTER ( DISTINCT ( { [sub1 Given], [sub2 Given] } ), NOT ISBLANK ( [Value] ) && [Value] <> [sub3 Return] ) 
    RETURN CONCATENATEX ( _tbl4, [Value], "," ) )
RETURN res

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

 

View solution in original post

5 REPLIES 5
barritown
Super User
Super User

Hi @sonalisaha2310,

Can you share with me how you see the expected output?

Hello @barritown ,
I have written calculated column measure with the query that  you have provided 
Now suppose the table looks like below

NameAccessories(Calculated Column Measure)
ABag,Monitor,Mouse
BMouse
CMonitor,Bag

The result should be 

NameAccessories (Calculated Column Measure)
ABag
AMonitor
AMouse
BMouse
CMonitor
CBag

 

Please note, i have tried to split it with delimiter from power query the column is not getting displayed if i open power query , please help me in splitting with delimiter and expand it in rows as shows above.

Hi @sonalisaha2310,

Sure, if you created a table or a column in DAX, you won't see it in Power Query.

Here is a way to create a new table with expanded rows via DAX:

barritown_0-1710188280455.png

I didn't remove temporary columns in order to let you see how this code works - you can get rid of them with the help of SELECTCOLUMNS.

Here is the same code as plain text:

Table3 = 
VAR _tbl1 = ADDCOLUMNS ( ADDCOLUMNS ( Table2, "Accesories H", SUBSTITUTE ( [Accessories(Calculated Column Measure)], ",", "|" ) ), 
                         "No of Items", 
                         PATHLENGTH ( [Accesories H] ) )
VAR maxLen = MAXX ( _tbl1, [No of Items] )
VAR _tbl2 = FILTER ( CROSSJOIN ( GENERATESERIES ( 1, maxLen ), _tbl1 ), [No of Items] >= [Value] )
VAR _tbl3 = ADDCOLUMNS ( _tbl2, "Item", PATHITEM ( [Accesories H], [Value] ) )
RETURN _tbl3

The playground PBIX file is also attached.

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

barritown
Super User
Super User

Hi @sonalisaha2310,

Here is a way to solve it with DAX:

barritown_0-1709581959630.png

DAX code in plain text for convenience (see also the attached file):

Result = 
VAR curRow = SUBSTITUTE ( [Overall], " ", "" )
VAR curRowH = SUBSTITUTE ( curRow, ",", "|" )
VAR nItems = PATHLENGTH ( curRowH )
VAR res = IF ( NOT ISBLANK ( nItems ), 
    VAR _tbl1 = SUMMARIZE ( ADDCOLUMNS ( GENERATESERIES ( 1, nItems ), "sub", PATHITEM ( curRowH, [Value] ) ), [sub] )
    VAR _tbl2 = DISTINCT ( UNION ( _tbl1, { [sub1 Given], [sub2 Given] } ) )
    VAR _tbl3 = FILTER ( _tbl2, NOT ISBLANK ( [sub] ) && [sub] <> [sub3 Return] )
    RETURN CONCATENATEX ( _tbl3, [sub], "," ),
    VAR _tbl4 = FILTER ( DISTINCT ( { [sub1 Given], [sub2 Given] } ), NOT ISBLANK ( [Value] ) && [Value] <> [sub3 Return] ) 
    RETURN CONCATENATEX ( _tbl4, [Value], "," ) )
RETURN res

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

 

Hello @barritown  , Thank you so much this worked as column measure , can you also please include the logic of splitting the text suing comma delimiter and expand it in the form of rows ?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.