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
NowaBI
New Member

How to link data from two table with Formula requirement

Hi,

 

Any help will be greatly appreciated.I have tried to figure it out by myself but with no result 😞

 

I have two different table Travel and Expense. The only relationship is the Employee Unique ID.

Travel IDDeparture DateReturn DateEmployee ID
XXXXX113/04/201917/04/2019E1
XXXXX215/05/201915/05/2019E2
XXXXX315/05/201915/05/2019E3
XXXXX426/06/201926/06/2019E4
XXXXX527/06/201927/06/2019E5

 

Employee IDExpense DateNature
E115/04/2019Taxi
E115/04/2019Taxi
E115/04/2019Restaurant
E315/05/2019Taxi
E315/05/2019Hotel

 

What I want to do is linked all expense to a Travel.

For Example, for a travel from 1st October to 10 October named "Travel1". I want to link all expanses made by the employee that has been made from 1st October to 10 October (Taxi, Hotel, Restaurant, etc...). So for that I need to compare the date of the expense to the date of the travel and write in the Expense table the Travel Name.

 

Is it possible ?

1 ACCEPTED SOLUTION
sturlaws
Resident Rockstar
Resident Rockstar

Hi,

 

you can do this with both Power Query and Dax.

Power query:
Merge the Expense-table with the Travel-table on Employee ID. Create a column which is equal to 1 when Expense Date between Departure date and Return date, and filter this column on 1. Remove all columns except Employee ID, Expense Date, Nature and Travel ID

Dax:
New column the Expense-table:

TravelIdDax =
CALCULATE (
    SELECTEDVALUE ( Travel[Travel ID] );
    FILTER (
        Travel;
        Expanse[Employee ID] = Travel[Employee ID]
            && Expense[Expense Date] >= Travel[Departure Date]
            && Expense[Expense Date] <= Travel[Return Date]
    )
)


If you want to create a relationship between the tables on Travel ID, you should use power query, otherwise you will get a circular dependency error

View solution in original post

2 REPLIES 2
sturlaws
Resident Rockstar
Resident Rockstar

Hi,

 

you can do this with both Power Query and Dax.

Power query:
Merge the Expense-table with the Travel-table on Employee ID. Create a column which is equal to 1 when Expense Date between Departure date and Return date, and filter this column on 1. Remove all columns except Employee ID, Expense Date, Nature and Travel ID

Dax:
New column the Expense-table:

TravelIdDax =
CALCULATE (
    SELECTEDVALUE ( Travel[Travel ID] );
    FILTER (
        Travel;
        Expanse[Employee ID] = Travel[Employee ID]
            && Expense[Expense Date] >= Travel[Departure Date]
            && Expense[Expense Date] <= Travel[Return Date]
    )
)


If you want to create a relationship between the tables on Travel ID, you should use power query, otherwise you will get a circular dependency error

Hi,

 

Thank you very much for your quick answer ! You solved my problem 🙂

Helpful resources

Announcements
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.

Top Kudoed Authors