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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Data modelling question

Hi,

I have one specific requirement in Power BI that I am unable to figure out.

I have an 'Employees' table in my data model which consists of the following columns and sample data,

 

2.png

 

 

 

 

 

 

 

 

 

In the 'reportsTo' column, we have employee IDs of the managers, but instead of IDs, I want the names of the managers to show up (in a different column).

In SQL, I can achieve this by using self join to connect the Employees table to itself on the condition reportsTo = employeeNumber.

 

1.png

 

 

 

 

 

 

 

 

 

 

How can I achieve the same results using Power BI?

 

Thanks,

Sourav

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey @Anonymous ,

 

my table looks like this:

image.png

I use this DAX statement to create a calculated column:

reportsto name = 
var reportsto_id  = 'Table'[reportsto]
return
CALCULATE(
    FIRSTNONBLANK('Table'[name] , 0) 
    , FILTER(
        ALL('Table')
        , 'Table'[id] = reportsto_id
    )
)

Now the table looks like this:

image.png

Hopefully this is what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

3 REPLIES 3
TomMartens
Super User
Super User

Hey @Anonymous ,

 

my table looks like this:

image.png

I use this DAX statement to create a calculated column:

reportsto name = 
var reportsto_id  = 'Table'[reportsto]
return
CALCULATE(
    FIRSTNONBLANK('Table'[name] , 0) 
    , FILTER(
        ALL('Table')
        , 'Table'[id] = reportsto_id
    )
)

Now the table looks like this:

image.png

Hopefully this is what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

Hi Tom,

Thanks for your help, the formula is working 🙂.

I was just wondering why the formula is not working without defining a 'var' and using 'return'. Is it not possible to achieve the same resultset by using only CALCULATE or some other DAX function? Just curious.

 

Thanks,

Sourav

Hey @Anonymous ,

 

you have to be aware that creating a calculated column always starts with a Row Context - the current row, using CALCULATE always transforms the values of the current row into a filter context, this step during the evaluation of CALCULATE is called context transition. As soon as context transition happens it's no longer possible to access the values from the outer row context without special consideration. This can be achieved by either using variables that are defined before context transition happens or using the function EARLIER(...).

I'm using variables in this example for the following reasons:

  • personally, I find the usage of variables more readable than using EARLIER
  • using variables outside a table iterator function like FILTER(...) allows the caching of values, anf for this reason performs faster than using the function EARLIER that will be evaluated every iteration.

Hopefully this adds to your understanding why I have been using variables.

 

Regards,

Tom 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.