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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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