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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
mroshchenko
Frequent Visitor

How to add “previous year” filter to the measure

Hello everyone.

I have an “Opening Staff” measure, which shows the number of employees at the beginning of each calendar year. I need to add a “previous year” filter to this measure to get a number of employees at the beginning of the previous year. Adding the filer “previous year” (YEAR ( TODAY () ) – 1) from the Date column to the visuals does not work for my goal, because I need separate measures for future calculations.

 

Original measure, which works well

Opening staff =

VAR BeginningOfPeriod = MIN('Date'[Date])

RETURN

CALCULATE (

DISTINCTCOUNT (EM[Employee]), EM[Type] in {"A"},

FILTER (EM, EM[HireDate] < BeginningOfPeriod && (

EM[TerminationDate] >= BeginningOfPeriod

|| ISBLANK ( EM[TerminationDate]  ))))

 

I tried to add PREVIOUSYEAR filter, but the measure still shows number for all years

Opening staff Prev Year=

VAR BeginningOfPeriod = MIN('Date'[Date])

Return CALCULATE (

    DISTINCTCOUNT ( EM[Employee] ), EM[Type] in {"A"},

    FILTER(FILTER(EM,

            EM[HireDate] < BeginningOfPeriod && (

             EM[TerminationDate] >= BeginningOfPeriod

             || ISBLANK ( EM[TerminationDate] ))),

 PREVIOUSYEAR('Date'[Year])))

 

This does not work

Opening staff Prev Year=

VAR BeginningOfPeriod = MIN('Date'[Date])

VAR PrevYear = YEAR ( TODAY () ) – 1

VAR OpenStaff = CALCULATE (

    DISTINCTCOUNT ( EM[Employee] ), EM[Type] in {"A"},

    FILTER (EM, EM[HireDate] < BeginningOfPeriod && (

    EM[TerminationDate] >= BeginningOfPeriod

    || ISBLANK ( EM[TerminationDate]  ))))

RETURN

  OpenStaff in {PrevYear}

 

Please help.

Thank you.

1 ACCEPTED SOLUTION
mroshchenko
Frequent Visitor

The previous year condition has been achieved by

VAR BeginningOfPeriodPrevYear = MIN('Date'[Date]) - 365

View solution in original post

4 REPLIES 4
mroshchenko
Frequent Visitor

The previous year condition has been achieved by

VAR BeginningOfPeriodPrevYear = MIN('Date'[Date]) - 365

Ashish_Mathur
Super User
Super User

Hi,

Does this work?

=calculate([opening staff],previousyear(calendar[date]))


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

calculate([opening staff],previousyear(calendar[date])) - does not show the error, but it is empty in the visual, does not present any number. 

Hi,

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.