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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.