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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Lubeno78
New Member

Calculation based on multiple values from slicer

Hello,

 

I'm trying to get number of active employees per month(s). I have folowing formula:

 

ActiveEmployees per month = 
VAR _EndOfMonth =
SELECTEDVALUE(EndMonth[EndMonth]
VAR _calculation =
CALCULATE(
DISTINCTCOUNT( HC[ID] ),
Filter(
HC,
HC[Starting Date] < _EndOfMonth
&& HC[Ending Date] >= _EndOfMonth 
)
)
RETURN
IF ( ISBLANK ( _calculation ), 0, _calculation 
 
This formula works perfectly, except one thing - when I choose several months from slicer, result is always 0 (zero).
What to change to get correct calculation per one month + correct calculation when several month were chosen?
 
Thank You!
2 ACCEPTED SOLUTIONS
tamerj1
Super User
Super User

Hi @Lubeno78 
Replace SELECTEDVALUE with MAX

ActiveEmployees per month =
VAR _EndOfMonth =
    MAX ( EndMonth[EndMonth] )
VAR _calculation =
    CALCULATE (
        DISTINCTCOUNT ( HC[ID] ),
        FILTER (
            HC,
            HC[Starting Date] < _EndOfMonth
                && OR ( ISBLANK ( HC[Ending Date] ), HC[Ending Date] >= _EndOfMonth )
        )
    )
RETURN
    IF ( ISBLANK ( _calculation ), 0, _calculation )

View solution in original post

@Lubeno78 
I hope this will do the trick. Create 2 measures 

ActiveEmployees per month =
VAR _EndOfMonth =
    MAX ( EndMonth[EndMonth] )
VAR _calculation =
    CALCULATE (
        DISTINCTCOUNT ( HC[ID] ),
        FILTER (
            HC,
            HC[Starting Date] < _EndOfMonth
                && OR ( ISBLANK ( HC[Ending Date] ), HC[Ending Date] >= _EndOfMonth )
        )
    )
RETURN
    IF ( ISBLANK ( _calculation ), 0, _calculation )

 

ActiveEmployees RT =
VAR StartDate =
    MIN ( EndMonth[EndMonth] )
VAR EndDate =
    MAX ( EndMonth[EndMonth] )
RETURN
    CALCULATE (
        [ActiveEmployees per month],
        EndMonth[EndMonth] >= StartDate,
        EndMonth[EndMonth] <= EndDate
    )

 

View solution in original post

5 REPLIES 5
Lubeno78
New Member

...hahaha, so easy! 🙂 Thank you very much @tamerj1 !

@Lubeno78 

No I think this is wrong it will only return the last month. I will update tou with the correct solution 

@Lubeno78 
I hope this will do the trick. Create 2 measures 

ActiveEmployees per month =
VAR _EndOfMonth =
    MAX ( EndMonth[EndMonth] )
VAR _calculation =
    CALCULATE (
        DISTINCTCOUNT ( HC[ID] ),
        FILTER (
            HC,
            HC[Starting Date] < _EndOfMonth
                && OR ( ISBLANK ( HC[Ending Date] ), HC[Ending Date] >= _EndOfMonth )
        )
    )
RETURN
    IF ( ISBLANK ( _calculation ), 0, _calculation )

 

ActiveEmployees RT =
VAR StartDate =
    MIN ( EndMonth[EndMonth] )
VAR EndDate =
    MAX ( EndMonth[EndMonth] )
RETURN
    CALCULATE (
        [ActiveEmployees per month],
        EndMonth[EndMonth] >= StartDate,
        EndMonth[EndMonth] <= EndDate
    )

 

Thank You again, @tamerj1 !! 

tamerj1
Super User
Super User

Hi @Lubeno78 
Replace SELECTEDVALUE with MAX

ActiveEmployees per month =
VAR _EndOfMonth =
    MAX ( EndMonth[EndMonth] )
VAR _calculation =
    CALCULATE (
        DISTINCTCOUNT ( HC[ID] ),
        FILTER (
            HC,
            HC[Starting Date] < _EndOfMonth
                && OR ( ISBLANK ( HC[Ending Date] ), HC[Ending Date] >= _EndOfMonth )
        )
    )
RETURN
    IF ( ISBLANK ( _calculation ), 0, _calculation )

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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