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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
cran
Helper I
Helper I

Lookup row information of a related id

Hi, 

 

I have a table that has

- col A: unique work ids,

- col B: users assigned to the Id

- col C: related workid. 

 

The related work Id also exists in the main unique work ids in column A as depending on the type of work of the Id in Col A it can may have a related id. 

 

So it looks as below

 

Col A unique idcol b useridcol c relatedid
1aa 
2bb3
3cc1
4dd 

 

How can I add a 4th column that brings through the userid of the relatedid in col C. 

 

As an example, for unique id 2, it's related id is 3, so I would like to bring the userid against 3 (user id cc) against the row that has unique id 2 

 

Hope that makes sense happy to provide more information but unfortunately can't provide actual data. 

 

Thank you 

1 ACCEPTED SOLUTION

@cran 

 

Use LOOKUPVALUE dax function. 

 

Example: col_d_related_userid = LOOKUPVALUE(Table1[col_b_userid], Table1[col_A_unique_id], Table1[col_c_relatedid])

 

document: https://learn.microsoft.com/en-us/dax/lookupvalue-function-dax

 

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


View solution in original post

4 REPLIES 4
cran
Helper I
Helper I

@rubayatyasmin thank you!

rubayatyasmin
Super User
Super User

Hi, @cran 

 

you can accomplish this using a calculated column and the RELATED function.

Here's the step-by-step process:

  1. You first need to create a relationship between col_A_unique_id and col_c_relatedid. In Power BI Desktop, go to "Model" view by clicking on the "Model" icon in the left pane.

  2. Now, drag "col_A_unique_id" to "col_c_relatedid" to create a relationship.

  3. After creating a relationship, go to "Data" view by clicking on the "Data" icon in the left pane.

  4. Select the table and click on "New column" under the "Modeling" tab.

  5. In the formula bar, type the following formula and hit Enter:

col_d_related_userid = RELATED(Table1[col_b_userid])

 

This formula will create a new column named "col_d_related_userid" that pulls the corresponding user id from column B based on the related id in column C. Note that, the RELATED function works only if there's an active direct or indirect relationship between the tables or if col_c_relatedid and col_A_unique_id are in the same table.

 

Remember that, if you have a row in col_c_relatedid that doesn't correspond to any row in col_A_unique_id, Power BI will return an error. This can be handled by using the IF and ISERROR functions to return a blank or some other value when an error occurs. Here's how you could adjust the formula:

 

col_d_related_userid = IFERROR(RELATED(Table1[col_b_userid]), BLANK())

 

This formula will return a blank if the RELATED function returns an error.

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Hi @rubayatyasmin 

 

Thank you for this - I should have mentioned both columns are in the same table. I can't create a relationship between 2 columns in the same table. 

 

Is there another way to calculate this if both columns are in the same table? Of not shoukd I then create a separate calculated table and then do the steps you have outlined above? 

 

Thank you

@cran 

 

Use LOOKUPVALUE dax function. 

 

Example: col_d_related_userid = LOOKUPVALUE(Table1[col_b_userid], Table1[col_A_unique_id], Table1[col_c_relatedid])

 

document: https://learn.microsoft.com/en-us/dax/lookupvalue-function-dax

 

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


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.