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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.