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
pisca
Frequent Visitor

Concatenate Parent and Child Value

Hi, 

 

How to create New Column like this table?

topic_idtopic_pidtopicNew Column
10HardwareHardware
21ComputerHardware / Computer
31PrinterHardware / Printer
40Office365Office365
52WordOffice365 / Word
62ExcelOffice365 / Excel
72Power PointOffice365 / Power Point

 

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@pisca , Try a new column like

New column =
var _max = maxx(filter(Table, Table[topic_pid]=0 && [topic_id] <earlier([topic_id])),[topic_id])
return
if([topic_pid]<>0 , maxx(filter(Table, Table[topic_pid]=0 && [topic_id] =_max),[topic]) &"/" & [topic],[topic])

View solution in original post

Mariusz
Community Champion
Community Champion

Hi @pisca 

 

You can use this DAX column pattern for the below result.

New Column = 
VAR __getParentChildHierarchy = PATH( 'Table'[topic_id], 'Table'[topic_pid] )
VAR __selectFirstParent = PATHITEM( __getParentChildHierarchy, 1, INTEGER ) 
VAR __lookupTopicByID = 
    LOOKUPVALUE( 
        'Table'[topic], 
        'Table'[topic_id], __selectFirstParent 
    )
VAR __topic = 'Table'[topic]
RETURN 
IF( 
    NOT __lookupTopicByID == __topic, 
    __lookupTopicByID & " / " & __topic,
    __topic
)

 

 

image.png

 

This is if the topic_pid for office = 4, not 2 and you replace 0 with null so PATH() function works correctly

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

View solution in original post

5 REPLIES 5
Mariusz
Community Champion
Community Champion

Hi @pisca 

 

You can use this DAX column pattern for the below result.

New Column = 
VAR __getParentChildHierarchy = PATH( 'Table'[topic_id], 'Table'[topic_pid] )
VAR __selectFirstParent = PATHITEM( __getParentChildHierarchy, 1, INTEGER ) 
VAR __lookupTopicByID = 
    LOOKUPVALUE( 
        'Table'[topic], 
        'Table'[topic_id], __selectFirstParent 
    )
VAR __topic = 'Table'[topic]
RETURN 
IF( 
    NOT __lookupTopicByID == __topic, 
    __lookupTopicByID & " / " & __topic,
    __topic
)

 

 

image.png

 

This is if the topic_pid for office = 4, not 2 and you replace 0 with null so PATH() function works correctly

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

pisca
Frequent Visitor

Awesome, Thanks a lot..

amitchandak
Super User
Super User

@pisca , Try a new column like

New column =
var _max = maxx(filter(Table, Table[topic_pid]=0 && [topic_id] <earlier([topic_id])),[topic_id])
return
if([topic_pid]<>0 , maxx(filter(Table, Table[topic_pid]=0 && [topic_id] =_max),[topic]) &"/" & [topic],[topic])

Hi Amit, Nice solution. I've another challenge. Data Looks like the following.

NewsIDParentChild
N1AA1
N1AA2
N1AA3
N1BB1
N1BB2
N2CC1
N2CC2
N3CC3
N3CC4
N2DD1
N3DD2
N3DD3

 

Now my output is being presented into a table visual - wherein for each newsID N1, N2 and N3 I've 1 row to display. Against each NewsID - I need to display the Parent and their child IDs concatenated like:

NewsLinked Parent_Child
N1A(A1, A2,A3); B(B1,B2)
N2C(C1, C2); D(D1)
N3C(C3, C4); D(D2,D3)

Awesome, Thanks a lot..

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.

Top Solution Authors