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

Match 2 tables by multiple columns (dates issue)

Hi,
I have a two tables like below.

Pablo7777_1-1689064889745.png

 


I need to calculate Total Costs for every Project. (hours spent * hourly cost)

To do that I have to match these tables by multiple columns (Project ID + execution date must be between 'date from' and 'date to').
The second part (dates matching) is the main issue for me.
I tried usind TREATAS function, but I don't know how to include condition with the dates.
The solutions must be in DAX.

 

I attach the sample pbix file:
https://drive.google.com/file/d/17Ik6TosY5m1lLQ_MmLJSOcwevJGmJ3Sr/view?usp=sharing

 

Any help would be much appreciated!

3 REPLIES 3
Pablo7777
New Member

Do you have another solution where there are more than 1 row per project in costs for any given date?

What additional criteria would you use to determine which row to use ?

johnt75
Super User
Super User

You can use

Total Costs = SUMX(
	'TimeSpent',
	VAR CurrentProject = 'TimeSpent'[Project ID]
	VAR HoursSpent = 'TimeSpent'[Hours Spent]
	VAR CurrentDate = 'TimeSpent'[Execution date]
	VAR HourlyCost =
		SELECTCOLUMNS(
			FILTER(
				'Costs',
				'Costs'[Project ID] = CurrentProject
					&& 'Costs'[Date from] <= CurrentDate
					&& 'Costs'[Date to] >= CurrentDate
			),
			"@value", 'Costs'[Hourly Cost]
		)
	RETURN
		HourlyCost * HoursSpent
)

as long as you only have 1 row per project in costs for any given date

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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