March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
Register NowGet certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now
Hi,
I have two tables and Calendar_table
Table 1
Project | Site | Start date | End date | Duration |
1122 | 12 | 01.05.2023 | 10.07.2023 | 10 |
1122 | 12 | 11.07.2023 | 02.09.2023 | 8 |
1122 | 12 | 03.09.2023 | 13.12.2023 | 14 |
1133 | 13 | 02.02.2023 | 02.06.2023 | 17 |
1133 | 13 | 03.06.2023 | 12.09.2023 | 14 |
1133 | 13 | 13.09.2023 | 15.11.2023 | 9 |
1133 | 14 | 01.04.2023 | 25.06.2023 | 12 |
1133 | 14 | 26.06.2023 | 05.10.2023 | 14 |
1133 | 14 | 06.10.2023 | 13.12.2023 | 10 |
Table 2
Person | Project | Site | Start date appointment site | End dateappointment site |
Name | 1122 | 12 | 01.05.2023 | 10.09.2023 |
Name | 1133 | 13 | 02.02.2023 | 13.09.2023 |
Name | 1133 | 14 | 01.04.2023 | 26.06.2023 |
Name2 | 1122 | 12 | 11.09.2023 | |
Name2 | 1133 | 13 | 14.09.2023 | |
Name2 | 1133 | 14 | 26.06.2023 |
Table 2 has many-to-many connection with Table 1, where Table 2 ---> Table 1 (not both) by Site
I need mesure depens on Calendar_table - which returns actual Duration (period Start Date-End Date) and actual appointment Site for Person.
For example,
Choose in Calendar_table - March 2023
Name - Site 13 - returns 17
Name2 - Site 13 - returns null
Calendar_table - November 2023
Name - Site 13 - returns null
Name2 - Site 13 - returns 9
Hi @dariaglb ,
To calculate the actual Duration for each Person and Site based on the Calendar_table date selection, we can use DAX to:
Steps to Create the Measure
Here’s a DAX measure to compute the Actual Duration:
Actual Duration =
VAR SelectedDate = MAX(Calendar_table[Date]) -- The selected date from the Calendar table
VAR AppointmentPeriod =
FILTER(
Table2,
Table2[Start date appointment site] <= SelectedDate &&
(ISBLANK(Table2[End dateappointment site]) || Table2[End dateappointment site] >= SelectedDate)
)
VAR ProjectPeriod =
FILTER(
Table1,
Table1[Start date] <= SelectedDate &&
Table1[End date] >= SelectedDate
)
VAR MatchingPeriods =
FILTER(
GENERATE(AppointmentPeriod, ProjectPeriod),
Table2[Project] = Table1[Project] &&
Table2[Site] = Table1[Site]
)
RETURN
SUMX(MatchingPeriods, Table1[Duration])
Expected Output
Best regards,
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
Check out the November 2024 Power BI update to learn about new features.
User | Count |
---|---|
26 | |
21 | |
11 | |
11 | |
11 |
User | Count |
---|---|
60 | |
31 | |
22 | |
19 | |
19 |