Forum Discussion
Pablo7777
3 years agoNew Member
Match 2 tables by multiple columns (dates issue)
Hi, I have a two tables like below. 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 I...
johnt75
3 years agoSuper 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