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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

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
Microsoft Employee
Microsoft 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
Microsoft Employee
Microsoft 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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.