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
alocoo
Frequent Visitor

Include slicer date value in a measure

Hi everyone,

I have a dimension table dim_hr_employment_details where there is the hire date and the termination date of each employee, and a DimDate (calendar) table. In my model there is an active relationship between both tables using the termination date of dim_hr_employment_details and the date of DimDate, and an inactive relationship using respectively the hire date and the date.

In my report, I have a slicer that simply uses the date from DimDate.

 

And when selecting e.g. 2022 in the slicer, I would like to compute a measure that counts the number of employees for which the slicer date value (in this case ; 01/01/2022) is between their hire date and termination date.

 

Could someone help me out with that?

Thanks a lot!

1 ACCEPTED SOLUTION

hi @alocoo 

 

Your logic is very clear. Not sure about your dataset. You may

1) create an isolate datetable

2) write a measure like this:

 

ActiveEmp = 
VAR _date = SELECTEDVALUE(DateTable[Date])
RETURN 
COUNTROWS(
    FILTER(
        TableName,
        TableName[HireDate]<=_date
            &&TableName[EndDate] >= _date
    )
)

 

3) plot a slicer with the date column from the datetable and another visual (e.g. Card) with the measure. 

 

I tried and it worked like this:

FreemanZ_0-1671453643266.png

 

FreemanZ_1-1671453671402.png

 

the sample dataset:

FreemanZ_2-1671453703919.png

 

the datetable:

FreemanZ_3-1671453732598.png

 

To use slicer value as filter boundary, the sliced table shall be isolated. Otherwise, the slicer filters a single value. 

View solution in original post

9 REPLIES 9
alocoo
Frequent Visitor

Hi @FreemanZ ,

so I would like to create a measure that includes the date that I select in my date slicer.

If I create a simple measure that counts the number of employees and I put it in a visual, when I select for example 2022 in my date slicer I will only have the number of employees whose termination date (or hire date if I use the inactive relationship) is 2022. But what I would like to have is a measure that counts the number of employees for which the value in my date slicer (e.g. 2022) is bigger than their hire date AND smaller than their termination date.

Thanks!

hi @alocoo 

 

Your logic is very clear. Not sure about your dataset. You may

1) create an isolate datetable

2) write a measure like this:

 

ActiveEmp = 
VAR _date = SELECTEDVALUE(DateTable[Date])
RETURN 
COUNTROWS(
    FILTER(
        TableName,
        TableName[HireDate]<=_date
            &&TableName[EndDate] >= _date
    )
)

 

3) plot a slicer with the date column from the datetable and another visual (e.g. Card) with the measure. 

 

I tried and it worked like this:

FreemanZ_0-1671453643266.png

 

FreemanZ_1-1671453671402.png

 

the sample dataset:

FreemanZ_2-1671453703919.png

 

the datetable:

FreemanZ_3-1671453732598.png

 

To use slicer value as filter boundary, the sliced table shall be isolated. Otherwise, the slicer filters a single value. 

Thanks a lot @FreemanZ, however as in my data model there is an active relationship between the end date and the date of the datetable, but an inactive one between the hire date and the date of the datetable, it returns blank when I create the measure you wrote. What should I do differently in the measure?

hi @alocoo 

you are welcome. Then create an new isolated date table for the slicer. 

@FreemanZ I've created another date table DimDate2 and here is now my formula :

 

VAR _date = SELECTEDVALUE(DimDate[Long Date])
VAR _date2 = SELECTEDVALUE(DimDate2[Long Date])
RETURN
COUNTROWS(
    FILTER(
        dim_hr_employment_details,
        dim_hr_employment_details[HireDate] <= _date2
        && dim_hr_employment_details[TerminationDate] >= _date
    )
)
 
But it returns blank. Is there something wrong in my measure?

hi @alocoo 

both DimDate and DimDate2 need to be isolated from the dim_hr_employment_details table. Is that so in your case?

Hi @FreemanZ, what do you mean exactly by isolated?

For the moment, my tables are like this...

alocoo_0-1671539120162.png

 

Hi @alocoo 

I mean delete all the relationships for the tables that you put into a slicer to get the filter boundaries.

FreemanZ
Super User
Super User

hi @alocoo 

could you further explain the logic of this part:

when selecting e.g. 2022 in the slicer, I would like to compute a measure that counts the number of employees for which the slicer date value (in this case ; 01/01/2022) is between their hire date and termination date.

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.