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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
ThePBIMaster
Advocate II
Advocate II

Filtering a Table by Selecting a Date and Returning Rows where the Date is between Two Dates

Hi All,

 

I have a table with Employee Number ID, their start date, leave date and IDs for their division, location, and department.

 

If an employee starts on 01/01/2022 and moves to a different division on 31/03/2022, then their leave date for that role is the 31/03/2022 and they start their new role on 01/04/2022. This will add an extra row on the table with the same Employee Number ID (e.g. 86 below). Please note example below where employee number ID starts on the 04/11/2019 (2nd row of 86), leaves their first role on 08/03/2020 and starts their new role in Division 4 on 09/03/2020 (1st row of 86). 

 

ThePBIMaster_0-1664468631719.png

 

I want an end user to be able to select a date in a slicer to filter this table so that only rows of data where the selected date is on or after the Start Date and on or before the Leave Date. This allows the end user to see how many employees where in each division/location/department at any point in time.

 

I'm trying to do something similar to this user - 

https://community.powerbi.com/t5/Desktop/Select-one-date-to-filter-data-between-two-dates/td-p/12272...

but instead of showing one value, I need to show three table visuals (one each for division, location, and department) with a sum of employees in each category.

 

Thanks in advance!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file whether it suits your requirement.

Jihwan_Kim_1-1664528504090.png

 

Jihwan_Kim_0-1664528483991.png

 

Employee count measure: =
CALCULATE (
    COUNTROWS ( DISTINCT ( Employee[Employee Number ID] ) ),
    FILTER (
        Employee,
        Employee[Start Date] <= MAX ( 'Calendar'[Date] )
            && OR (
                Employee[Leave Date] >= MIN ( 'Calendar'[Date] ),
                Employee[Leave Date] = BLANK ()
            )
    )
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file whether it suits your requirement.

Jihwan_Kim_1-1664528504090.png

 

Jihwan_Kim_0-1664528483991.png

 

Employee count measure: =
CALCULATE (
    COUNTROWS ( DISTINCT ( Employee[Employee Number ID] ) ),
    FILTER (
        Employee,
        Employee[Start Date] <= MAX ( 'Calendar'[Date] )
            && OR (
                Employee[Leave Date] >= MIN ( 'Calendar'[Date] ),
                Employee[Leave Date] = BLANK ()
            )
    )
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


@Jihwan_Kim 

 

Thank you! Working well 🙂

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.