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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
drewmcspy
Frequent Visitor

Counting Leavers using var _min and var _max and count rows

Hi

 

I'm fairly new to PowerBI and need some help with a formula I have please.

 

Table Name: 'Staff Data'

 

What I'm trying to do it count the number of leavers on a staff list over a rolling 12 complete months period. Meaning, today is the 22nd February 2022 so if I refreshed the data it would count all rows of data which contained an leave date [Date Left] from 01/02/2021 (var _min) to 31/01/2022 (var _max). I also have a flag which determines whether each member of staff left voluntarily [Vol. Leaver].

The variables look correct to me so is there something incorrect with the way I am using the filter? 


Vol.LeaversLTM =
var _min = EDATE(EOMONTH(today(),-1),-12)+1
var _max = EOMONTH(today(),-1)
return COUNTROWS(CALCULATETABLE('Staff Data',FILTER('Staff Data',[Date Left] <= _max && 'Staff Data'[Date Left] >=_min),FILTER('Staff Data','Staff Data'[Vol. Leaver]= "yes")))

 

Thanks for any help you can give me.

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @drewmcspy ,

 

Try this:

Vol.LeaversLTM =
VAR _min =
    EDATE ( EOMONTH ( TODAY (), -1 ), -12 ) + 1
VAR _max =
    EOMONTH ( TODAY (), -1 )
RETURN
    COUNTROWS (
        FILTER (
            ALL ( 'Staff Data' ),
            'Staff Data'[Date Left] <= _max
                && 'Staff Data'[Date Left] >= _min
                && 'Staff Data'[Vol. Leaver] = "yes"
        )
    )

 

 

Best Regards,

Icey

 

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

4 REPLIES 4
Icey
Community Support
Community Support

Hi @drewmcspy ,

 

Try this:

Vol.LeaversLTM =
VAR _min =
    EDATE ( EOMONTH ( TODAY (), -1 ), -12 ) + 1
VAR _max =
    EOMONTH ( TODAY (), -1 )
RETURN
    COUNTROWS (
        FILTER (
            ALL ( 'Staff Data' ),
            'Staff Data'[Date Left] <= _max
                && 'Staff Data'[Date Left] >= _min
                && 'Staff Data'[Vol. Leaver] = "yes"
        )
    )

 

 

Best Regards,

Icey

 

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

tackytechtom
Super User
Super User

Hi @drewmcspy,

 

Does it work with this?

Vol.LeaversLTM =
var _min = EDATE(EOMONTH(today(),-1),-12)+1
var _max = EOMONTH(today(),-1)
return
CALCULATE (
COUNTROWS ( 'Staff Data' ),
FILTER ('Staff Data', 'Staff Data'[Date Left] <= _max && 'Staff Data'[Date Left] >= _min && 'Staff Data'[Vol. Leaver] = "yes")
)

 

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Hi @tackytechtom 

 

Thanks for your reply. Unfortunately it doesn't It produces the same result as my original filter. The figure should be about 200 but I'm getting 32. I can't see how.

 

mcspy

Hi @drewmcspy ,

 

Please can you share the data and the result you would like to achieve? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors
Top Kudoed Authors