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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
hassanh_2
New Member

DAX Function to Create a Column Based on condition / filter in another column

Hello,

Im trying to create a new column that returns a value from another table based on condition / filter.

 

As you see I have the following 2 tables. I want to create a new column in Table 2, in that column I need to return the "Sales Person" of the first Log_ID.

 

(Note: in my relationship model there is an Inactive relationship by "Acct Nr.") 

 

hassanh_2_0-1669711772320.png

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @hassanh_2 
Please try

NewColumn =
MAXX (
    TOPN (
        1,
        CALCULATETABLE ( Table2, USERELATIONSHIP ( Table1[Acct Nr], Table2[Acct Nr] ) ),
        Table2[Log_ID], ASC
    ),
    Table2[Sales Person]
)

View solution in original post

5 REPLIES 5
hassanh_2
New Member

Is there a way though to create it as a Column so I can use it as a Parameter dimension in other visuals?

 

@hassanh_2 

What is the direction of the relationship between the two tables? Can you provide a screenshot?

hassanh_2
New Member

I created the same function as a measure and it worked. Thank you!

tamerj1
Super User
Super User

Hi @hassanh_2 
Please try

NewColumn =
MAXX (
    TOPN (
        1,
        CALCULATETABLE ( Table2, USERELATIONSHIP ( Table1[Acct Nr], Table2[Acct Nr] ) ),
        Table2[Log_ID], ASC
    ),
    Table2[Sales Person]
)

Hi, Thanks!

It seems you switched the Table Numbers but I tried both ways and the new column didnt return any value!

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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