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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
FlorisMK
Helper I
Helper I

Demographic data at a slicer-selected point in time - how?

I'm creating an HR dashboard, which includes, among other things, a slicer to select the reporting year. So far, this works perfectly.

I'm now at the point where I want to create the demography page: what was the composition of our workforce (for instance, in terms of age and gender) at a given point in time?

My goal is to have my users select a year in the slicer, and have the demography visuals show the composition of our workforce on 1 January of that year. If they unselect the slicer value, the current workforce composition should be shown.

Source data is a full list of employees, with birth dates, genders, and contract start and end dates.

So the slicer should result in selecting employees with start dates before, and end dates after of blank; and it should also result in calculating the ages of the employees at the selected dates.

Creating the query is easy, but I have no idea how to use slicer input to both select the dataset based on contract dates, and use the date to calculate ages for demography statistics.

Where do I start?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @FlorisMK 

 

For your question, here is the method I provided:

 

Here's some dummy data

 

“Employee”

vnuocmsft_0-1721283726372.png

 

Create a simple date table:

 

DateTable = CALENDAR (DATE(2023,1,1), DATE(2023,12,31)) 

 

Create a measure to Calculate Age.

 

Age = DATEDIFF(SELECTEDVALUE('Employee'[BirthDate]), DATE(SELECTEDVALUE('DateTable'[Date].[Year]), 1, 1), YEAR) 

 

To filter the employees based on the slicer selection, you can create a measure like this:

Active Employees = 
CALCULATE( 
COUNTROWS(Employee), 
FILTER( 
Employee, 
Employee[StartDate] <= DATE(SELECTEDVALUE('DateTable'[Date].[Year]), 1, 1) 
&& 
(ISBLANK(Employee[EndDate]) || Employee[EndDate] >= DATE(SELECTEDVALUE('DateTable'[Date].[Year]), 1, 1)) 
) 
) 

 

Here is the result.

vnuocmsft_1-1721283888011.png

 

Regards,

Nono Chen

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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @FlorisMK 

 

For your question, here is the method I provided:

 

Here's some dummy data

 

“Employee”

vnuocmsft_0-1721283726372.png

 

Create a simple date table:

 

DateTable = CALENDAR (DATE(2023,1,1), DATE(2023,12,31)) 

 

Create a measure to Calculate Age.

 

Age = DATEDIFF(SELECTEDVALUE('Employee'[BirthDate]), DATE(SELECTEDVALUE('DateTable'[Date].[Year]), 1, 1), YEAR) 

 

To filter the employees based on the slicer selection, you can create a measure like this:

Active Employees = 
CALCULATE( 
COUNTROWS(Employee), 
FILTER( 
Employee, 
Employee[StartDate] <= DATE(SELECTEDVALUE('DateTable'[Date].[Year]), 1, 1) 
&& 
(ISBLANK(Employee[EndDate]) || Employee[EndDate] >= DATE(SELECTEDVALUE('DateTable'[Date].[Year]), 1, 1)) 
) 
) 

 

Here is the result.

vnuocmsft_1-1721283888011.png

 

Regards,

Nono Chen

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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Nice! Apologies, I was on vacation for three weeks. Glad to see that both the solution and its acceptance hava materialized in my absence 😄

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors