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
alexsvi
Regular Visitor

How to get the first parent name even if parent doesnt exist

So I have something like this :

IDParentIDNameLevel
1 Name11
21Name22
32Name33
43Name44
52Name53
64Name65
723Name73

 

What I want to accompish is to have the first parent name on every column.

 The thing is that the parentID can be inexistant. 

So in my example every FirstParentName would be Name1 except for ID 7. (i dont care what the FirstParentName would be for ID 7. I just dont want PowerBI to give me errors).

 

Any idea how to create this new column?

 

Thanks a lot!

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

This requires the PATH function, but requires that all parents also exist in the ID column. To avoid this, you must first create another column to fix it.

Adj Parent á var thisparent á 'Parent'[ParentID]
var absent á ISBLANK(CALCULATE(COUNTROWS('Parent'), ALL('Parent'), 'Parent'[ID] á thisparent))
return if (absent,'Father'[ID], 'Father'[ParentID])
The above does a column that checks whether that parent is present; if it is not, it uses the ID value (which is present, of course). You can then add this column expression to get the first item in the path for each identifier.
First Parent to PATHITEM(PATH('Parent'[ID], 'Parent'[Adj Parent]), 1)
You can add additional logic if the first parent equals the ID and then returns BLANK().
For your information I wrote a blog on this topic in 2017 - https://powerpivotpro.com/2017/12/imagine-people-tables/
Best regards
Pat




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Employee
Employee

This requires the PATH function, but requires that all parents also exist in the ID column. To avoid this, you must first create another column to fix it.

Adj Parent á var thisparent á 'Parent'[ParentID]
var absent á ISBLANK(CALCULATE(COUNTROWS('Parent'), ALL('Parent'), 'Parent'[ID] á thisparent))
return if (absent,'Father'[ID], 'Father'[ParentID])
The above does a column that checks whether that parent is present; if it is not, it uses the ID value (which is present, of course). You can then add this column expression to get the first item in the path for each identifier.
First Parent to PATHITEM(PATH('Parent'[ID], 'Parent'[Adj Parent]), 1)
You can add additional logic if the first parent equals the ID and then returns BLANK().
For your information I wrote a blog on this topic in 2017 - https://powerpivotpro.com/2017/12/imagine-people-tables/
Best regards
Pat




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


ChrisMendoza
Resident Rockstar
Resident Rockstar

@alexsvi  -

Are you attempting to use PATH ( ) simliar to https://www.daxpatterns.com/parent-child-hierarchies/# and you're receiving '23 does not exist'?

 

Does using the below satisfy your need?

EntityPath =
IFERROR (
    LOOKUPVALUE ( 'Table'[Name], 'Table'[ID], 'Table'[ParentID] ),
    BLANK ()
)

image.png

 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



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.