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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

DAX mesure depens on calendar and dates

Hi, 
I have two tables and Calendar_table

Table 1

ProjectSiteStart dateEnd dateDuration
11221201.05.202310.07.202310
11221211.07.202302.09.20238
11221203.09.202313.12.202314
11331302.02.202302.06.202317
11331303.06.202312.09.202314
11331313.09.202315.11.20239
11331401.04.202325.06.202312
11331426.06.202305.10.202314
11331406.10.202313.12.202310

 

Table 2

 

PersonProjectSiteStart date appointment siteEnd dateappointment site
Name11221201.05.202310.09.2023
Name11331302.02.202313.09.2023
Name11331401.04.202326.06.2023
Name211221211.09.2023 
Name211331314.09.2023 
Name211331426.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

1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @Anonymous ,

 

To calculate the actual Duration for each Person and Site based on the Calendar_table date selection, we can use DAX to:

  1. Filter the data for the selected date range.
  2. Intersect the appointment period with the project duration period.
  3. Return the overlapping duration for each person and site.

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

  • March 2023
    • Name → Site 13 → Returns 17 (Project active for Name, duration overlaps with Calendar_table).
    • Name2 → Site 13 → Returns null (No overlapping duration for the date).
  • November 2023
    • Name → Site 13 → Returns null (Appointment ended for the date).
    • Name2 → Site 13 → Returns 9 (Project active for Name2 in November 2023).

Best regards,

 

View solution in original post

2 REPLIES 2
DataNinja777
Super User
Super User

Hi @Anonymous ,

 

To calculate the actual Duration for each Person and Site based on the Calendar_table date selection, we can use DAX to:

  1. Filter the data for the selected date range.
  2. Intersect the appointment period with the project duration period.
  3. Return the overlapping duration for each person and site.

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

  • March 2023
    • Name → Site 13 → Returns 17 (Project active for Name, duration overlaps with Calendar_table).
    • Name2 → Site 13 → Returns null (No overlapping duration for the date).
  • November 2023
    • Name → Site 13 → Returns null (Appointment ended for the date).
    • Name2 → Site 13 → Returns 9 (Project active for Name2 in November 2023).

Best regards,

 

Anonymous
Not applicable

Thanks a lot! It's work!

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.