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
kamiluc
Helper I
Helper I

Create a new column from non related table

Hi,

I'm trying to create a new column in a table that will be based on another table which is not related.

The first table contains a user_ID which I want to lookup in the second table and bring the value for the employment status, but bring the value for the latest one.

 

Risks

Risk IDRisk_Owner_User_IDRisk Owner Employment Status (new column I need)
1AActive (currently getting "Inactive")
2BActive

 

Employee History

Employee IDUser_IDEmployee StatusValid_To
123AInactive1/1/2020
456AActive31/12/9999
789BActive

31/12/2023

 

My new column in risks table should include the Employee_Status for the latest Valid_To date.

 

I created this which is giving me some false-positives, and I've tried a few variations with no luck so far (the IF() is because some records don't have a user_ID and I was getting incorrect values in those):

 

Risk Owner Employment Status =
IF(
    Risks[Risk_Owner_UserID]<>"",
        CALCULATE(
            MAX(Employee_History[Employee_Status]),
            FILTER(Employee_History, MAX(Employee_History[ValidTo]) && Risks[Risk_Owner_UserID] = Employee_History[UserID]
            )
        ),
    ""
)
 
Thanks!
1 ACCEPTED SOLUTION

Thank you @Jihwan_Kim 

I reproduced the expression in my project but still had false-positives.  I don't fully understand what the TREATAS() does, but then I created a table with your CALCULATETABLE() to see what it was producing and it's the latest record for each User_ID.  What I believe it was missing was a link to the current User_ID in my risks table, so I included a CALCULATE() in the expression which appears to work now.

Risk Owner Employment Status =
IF (
    Risks[Risk_Owner_User_ID] <> "",
        CALCULATE(
            MAXX (
                CALCULATETABLE (
                    'Employee History',
                    TREATAS (
                        GROUPBY (
                            'Employee History',
                            'Employee History'[User_ID],
                            "@maxdate", MAXX ( CURRENTGROUP (), 'Employee History'[Valid_To] )
                        ),
                        'Employee History'[User_ID],
                        'Employee History'[Valid_To]
                    )
                ),
                'Employee History'[Employee Status]
            ),
        FILTER('Employee History', 'Employee History'[User_ID] = Risks[Risk_Owner_User_ID])
    ),
    ""
)

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

Please check the attached pbix file and the below picture.

 

Picture1.png

 

Risk Owner Employment Status =
IF (
    Risks[Risk_Owner_User_ID] <> "",
    MAXX (
        CALCULATETABLE (
            'Employee History',
            TREATAS (
                GROUPBY (
                    'Employee History',
                    'Employee History'[User_ID],
                    "@maxdate", MAXX ( CURRENTGROUP (), 'Employee History'[Valid_To] )
                ),
                'Employee History'[User_ID],
                'Employee History'[Valid_To]
            )
        ),
        'Employee History'[Employee Status]
    ),
    ""
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thank you @Jihwan_Kim 

I reproduced the expression in my project but still had false-positives.  I don't fully understand what the TREATAS() does, but then I created a table with your CALCULATETABLE() to see what it was producing and it's the latest record for each User_ID.  What I believe it was missing was a link to the current User_ID in my risks table, so I included a CALCULATE() in the expression which appears to work now.

Risk Owner Employment Status =
IF (
    Risks[Risk_Owner_User_ID] <> "",
        CALCULATE(
            MAXX (
                CALCULATETABLE (
                    'Employee History',
                    TREATAS (
                        GROUPBY (
                            'Employee History',
                            'Employee History'[User_ID],
                            "@maxdate", MAXX ( CURRENTGROUP (), 'Employee History'[Valid_To] )
                        ),
                        'Employee History'[User_ID],
                        'Employee History'[Valid_To]
                    )
                ),
                'Employee History'[Employee Status]
            ),
        FILTER('Employee History', 'Employee History'[User_ID] = Risks[Risk_Owner_User_ID])
    ),
    ""
)

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.