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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Thibaut_G
New Member

Date slicer based on two date fields

Hello,
I have a problem, I searched everywhere but I don't find any solution... 

I have an employees table, the employees can have multiple contracts linked to an office. There is a start_contract and end_contract fields. Beside I have a calendar table with an active relationship on the start_contract field and an inactive relationship on the end_contract one. The employees table looks like this:

employee_idstart_contractend_contractoffice_id
12017-06-30 17:30:002017-12-30 17:30:001
12017-12-30 17:30:002018-06-30 17:30:002
2 2017-06-30 17:30:002017-12-30 17:30:001
22018-06-30 17:30:002018-12-30 17:30:00 2


I need to know when the contract is "active" by comparing the start and end date to count the number of employees active at the date the end user will filter...
I tried many things but the results are not right.
I thought it was possible to do something like this but it doesn't seems to work:

 

 

 

Count employees = 
var selectedDate = SELECTEDVALUE(Dates[Date], now())
return COUNTROWS(GROUPBY( FILTER(Employees, Employees[start_contract] <= selectedDate && (Employees[end_contract] > selectedDate) || Employees[end_contract] = BLANK()), Employees[id]))

 

 

 

Right now my feeling is that it's not possible to do that with Power BI so maybe I should find a way on SQL side to get a table with only one date field and a boolean field like active_contract. 

Any help is welcome 

1 ACCEPTED SOLUTION
2 REPLIES 2
amitchandak
Super User
Super User

Thank you!!
Glad to see that the way I tried wasn't wrong, i didn't realize that I needed to use

max('Date'[Date])

 

Helpful resources

Announcements
September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.