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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

calculation with dates

Hi, I have a table with employees date joined by team and date left by team. As a result, employees end up in several rows. For example employed by team A from 1-1-2020 to 31-7-2021 and employed by team B from 8-1-2021 to present. Now I also have a table with written hours per day per project. And I have a date table. How can I get a list of the written time in hours per project from each team. The date written from the table hours should look at table employees and look based on the date where in which team they were. How do I do that within Power BI? Do I use Dax or add a calculated column? Some screenshots of the colums below.

 

Table employee

Name employeedate startdate endteam
Margret1-1-202324-1-2023A
Margret25-1-202315-2-2023B
Margret16-2-202330-4-2023C
Margret1-5-2023 D
Pierre1-1-202331-5-2023C
Pierre1-6-2023 A
Tom1-1-20235-3-2023C
Tom6-3-202330-4-2023B

 

Table working hours:

Name employeedateworking hours
Magret5-1-20233
Magret8-1-20235
Magret15-1-20236
Magret16-1-20232
Magret25-1-20236
Magret29-1-20234
Magret17-2-20238
Magret18-2-20234
Magret8-3-20238
Magret15-3-20238
Magret16-3-20236
Magret19-3-20234
Magret28-3-20238
Magret17-4-20237
Magret24-4-20233
Magret27-4-20239
Magret26-5-20237
Pierre5-1-20233
Pierre8-1-20235
Pierre15-1-20236
Pierre16-1-20232
Pierre25-1-20236
Pierre29-1-20234
Pierre17-2-20238
Pierre18-2-20234
Pierre8-3-20238
Pierre15-3-20238
Pierre16-3-20236
Pierre19-3-20234
Pierre28-3-20238
Pierre17-4-20237
Pierre24-4-20233
Pierre27-4-20239
Pierre26-5-20237
Tom5-1-20233
Tom8-1-20235
Tom15-1-20236
Tom16-1-20232
Tom25-1-20236
Tom29-1-20234
Tom17-2-20238
Tom18-2-20234
Tom8-3-20238
Tom15-3-20238
Tom16-3-20236
Tom19-3-20234
Tom28-3-20238
Tom17-4-20237
Tom24-4-20233
Tom27-4-20239
Tom26-5-20237
1 ACCEPTED SOLUTION

Hi @Anonymous 

for Test measure use version below ) was on wrong place. Adding "working hours" to second table - not clear what you want. You already have it some table?

 

Test =
VAR _startdate=SELECTEDVALUE(formatie[date start])
VAR _enddate=SELECTEDVALUE(formatie[date end])
VAR _employee=SELECTEDVALUE(formatie[Name employee])
VAR _Result=
    CALCULATE(
        [Workin_hours],
        FILTER('working hours',
        'working hours'[date]>=_startdate && 'working hours'[date]>=_enddate && 'working hours'[Name employee]=_employee
    )
)
RETURN _result
 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






View solution in original post

14 REPLIES 14
Anonymous
Not applicable

Hi @some_bih , thank you for you answer. The empty date field means that the employee is still working within team ...
You solution does not work. I get the message that the syntaxis for RETURN is notcorrect. Do you know what goes wrong?

 
Test =
VAR _startdate=SELECTEDVALUE(formatie[date start])
VAR _enddate=SELECTEDVALUE(formatie[date end])
VAR _employee=SELECTEDVALUE(formatie[Name employee])
VAR _Result=
    CALCULATE(
        [Workin_hours],
        FILTER('working hours',
        'working hours'[date]>=_startdate && 'working hours'[date]>=_enddate && 'working hours'[Name employee]=_employee
    )
RETURN _result
)



If i want the team added to the second table "working hours". How can I do that? 

Hi @Anonymous 

for Test measure use version below ) was on wrong place. Adding "working hours" to second table - not clear what you want. You already have it some table?

 

Test =
VAR _startdate=SELECTEDVALUE(formatie[date start])
VAR _enddate=SELECTEDVALUE(formatie[date end])
VAR _employee=SELECTEDVALUE(formatie[Name employee])
VAR _Result=
    CALCULATE(
        [Workin_hours],
        FILTER('working hours',
        'working hours'[date]>=_startdate && 'working hours'[date]>=_enddate && 'working hours'[Name employee]=_employee
    )
)
RETURN _result
 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Anonymous
Not applicable

Hi @some_bih , I have the DAX formular below. I want in my second table a new column with the team a employee is part of at the date he worked. I think there needs something on the red questionmarks. Or do you have an other solution?

Test =
VAR _startdaterooster=SELECTEDVALUE('table 1'[startdate])
VAR _enddaterooster=SELECTEDVALUE('table 1'[enddate])
VAR _medewerker=SELECTEDVALUE('table 1'[startdate])
VAR _Result=
   CALCULATE(?????
    FILTER('RB-BI_UREN',
        'table 2'[Date]>=_startdaterooster
        && 'table 2'[Date]<=_enddaterooster
        && 'table 2'[Date]=_medewerker)
    )
RETURN _result

Hi @Anonymous I assume employee belong to some team and there is some table. This table should be connected with relationship and we will see the result. In what table we could find this?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Anonymous
Not applicable

Hi som_bih, the problem is the emplyee has several lines because it belognes during time to sevral teams. you get a many to many relationship, els it would be easy. 

To get the right team at time hours worked it should look at the date en then find the right team.

Hi @Anonymous still, one employee belong to only one team at certain day? Or...





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Anonymous
Not applicable

Hi some_bih, that is right.

Do you know how I  can add a column to the table below?  

Table working hours:

Name employeedateworking hours
Magret5-1-20233
Magret8-1-20235
Magret15-1-20236
Magret16-1-20232
Magret25-1-20236
Magret29-1-20234
Magret17-2-20238
Magret18-2-20234
Magret8-3-20238
Magret15-3-20238
Magret16-3-20236

 

There is a many to many relationship between the table "working hours"  and "employee"/

For every line in the new column it need to  look in the table "employee" at which team the employee belongs at a certain day. 

 

Do you have a suggestion?

Hi @Anonymous please share file with me so I can see overall model. Describe wanted solution so I can check what I can do.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Anonymous
Not applicable

@some_bih , How can I share the pbix file with you?

@Anonymous try DM(right upper corner)





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Anonymous
Not applicable

yes, that is right. 

 

Hi @Anonymous  accept it as solution so other member could use it. thank you





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Anonymous
Not applicable

Thanx

 

some_bih
Super User
Super User

Hi @Anonymous  during testing, I found 2 issues in your sample:

1) blank end date - I inserted 31.12.2023 to have valid test data and appling data on real date
2) Margret in one table & Magret  in second table: I overvrite Margret to be in both tables

3) not data for Pierre 1.6.2023 - blank end data (31.12.2023 after my insert as in 1)) so it is not shown in results 

I created 2 measures as below. Adjust Sheet3 and Sheet1 to your table name. 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

Workin_hours = SUM(Sheet3[working hours]) 
Test =
VAR _startdate=SELECTEDVALUE(Sheet1[date start])
VAR _enddate=SELECTEDVALUE(Sheet1[date end])
VAR _employee=SELECTEDVALUE(Sheet1[Name employee])
VAR _Result=
    CALCULATE(
        [Workin_hours],
        FILTER(Sheet3,
        Sheet3[Date]>=_startdate && Sheet3[Date]<=_enddate && Sheet3[Name employee]=_employee)
    )
RETURN _Result

some_bih_0-1687357030485.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






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.