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
WBADAM03
Frequent Visitor

Conditional column based on if a record exists in another table

Hey all,

I hope this is the right place to ask this question:

I have table1 that has a list of students.

I have table2 that has a table with student records.

I want to have a column in table1 that looks at table2 and, if a record/row exists in table2 with the username of the student, returns a specific column. If there is no record at all in table2 for the student based on their username, I want it to return null or NA.

I am not great at powerbi so I am having trouble.

I tried conditional column but it won't let me do a conditional based on the column of another table.

So if I have a student named Bob, if Bob's username is student3 (the key between the tables), if student3 is in table2 and the data value is "approved", I want newcolumn to return "approved".

If John's username is student5 and if student5 doesn't exist in table2, I want newcolumn to have a value of "NA" or null for his record in table1.

Does that make sense? 

Been having some trouble with this one

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @WBADAM03 ,

 

I created some dummy data for reference.

vstephenmsft_2-1693209362441.png

vstephenmsft_1-1693209332896.png

Table (1) has the student's names, Table (2) has the students' grades, and if the student in Table (1) has no grades in Table (2), then NA is returned.

Then you can create the following column to solve it.

Column = 
IF(
    'Table (1)'[Student] in SELECTCOLUMNS('Table (2)',"Student",[Student]),"Y","NA")

vstephenmsft_4-1693209881697.png

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

 

 

 

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @WBADAM03 ,

 

I created some dummy data for reference.

vstephenmsft_2-1693209362441.png

vstephenmsft_1-1693209332896.png

Table (1) has the student's names, Table (2) has the students' grades, and if the student in Table (1) has no grades in Table (2), then NA is returned.

Then you can create the following column to solve it.

Column = 
IF(
    'Table (1)'[Student] in SELECTCOLUMNS('Table (2)',"Student",[Student]),"Y","NA")

vstephenmsft_4-1693209881697.png

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

 

 

 

 

AlienSx
Super User
Super User

table2_rec = Record.FromList(table2[data_value], table2[key]),
find_key = Table.AddColumn(table1, "column", each Record.FieldOrDefault(table2_rec, [key], "NA"))
WBADAM03
Frequent Visitor

Hi, 

I am not sure I understand the question. 

Basically I want a column in table1 that looks at table2 to see if a record exists for the student using the student username (key that joins the table). If a record does exist in table2 for the student, I want to return an advisor record, like Bob Jones.

If I have a student named Dave Smith and he has a record in table2 with the username "student1", I want to return his advisor, Bob Jones, as a value in a column in table1.

If Dave Smith doesn't have a record in table2 with the username student1, I want to return null or NA

Does that make sense?

mussaenda
Super User
Super User

Hi @WBADAM03 

 

Can you please provide a data that users can copy and your expected output to help you better?

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.