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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.