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
aellison
Helper I
Helper I

Active Employees for Previous Month vs Previous Year/Month

I am trying to get a visual completed that looks like the following:

Personnel

2019-Nov

2018-Nov

Difference Count

Difference Percent

Local Employees

1024

865

159

18.38%

Remote Employees

5349

5184

165

3.18%

 

From data that looks like the following:

PersonnelTypeHireDateTerminationDate
SteveLocal1/1/2018 
JimLocal2/5/20182/1/2019
JillRemote3/6/2018 
BillRemote2/1/20195/1/2019
DebbieLocal5/1/2019 

 

I've tried to create this multiple ways and having no success. Can someone help me out with how to get this grid created in PowerBI?

 

Thank you,

 

2 ACCEPTED SOLUTIONS
v-lid-msft
Community Support
Community Support

Hi @aellison ,

 

We can create following measures and use them in table visual to meet your requirement:

 

LastMonth = 
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        'Table',
        [HireDate]
            < DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 )
            && OR (
                [TerminationDate] >= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 1 ),
                ISBLANK ( [TerminationDate] )
            )
    )
)

 

LastMonthOfLastYear = 
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        'Table',
        [HireDate]
            < DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ) - 1, 1 )
            && OR (
                [TerminationDate] >= DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), 1 ),
                ISBLANK ( [TerminationDate] )
            )
    )
)

 

Difference Count = [LastMonth] - [LastMonthOfLastYear]

 

Difference Percent = DIVIDE([Difference Count] , [LastMonthOfLastYear] , 0)

 

18.jpg19.jpg


If it doesn't meet your requirement, Please show the exact expected result based on the Tables that we have shared.


Best regards,

 

Community Support Team _ Dong Li
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

Hi @aellison ,

 

Sorry for late reply, we can create a spreate date table as silcer:

 

SlicerDateTable = CALENDAR(MIN(MIN('Table'[HireDate]),MIN('Table'[TerminationDate])),Max(Max('Table'[HireDate]),MAX('Table'[TerminationDate])))

 

Then we can use create two measures to meet your requirement:

 

LastMonthOfLastYearOfSelectedDay = 

var SelectedDay = MAX('SlicerDateTable'[Date])
return
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        'Table',
        [HireDate]
            < DATE ( YEAR ( SelectedDay ) - 1, MONTH ( SelectedDay ) - 1, 1 )
            && OR (
                [TerminationDate] >= DATE ( YEAR ( SelectedDay ) - 1, MONTH ( SelectedDay ), 1 ),
                ISBLANK ( [TerminationDate] )
            )
    )
)

 

LastMonthOfSelectedDay = 
var SelectedDay = MAX('SlicerDateTable'[Date])
return 
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        'Table',
        [HireDate]
            < DATE ( YEAR (SelectedDay ), MONTH ( SelectedDay ) - 1, 1 )
            && OR (
                [TerminationDate] >= DATE ( YEAR ( SelectedDay ), MONTH ( SelectedDay ), 1 ),
                ISBLANK ( [TerminationDate] )
            )
    )
)

 

1.jpg

 


If it doesn't meet your requirement, Please show the exact expected result based on the Tables that you have shared.


Best regards,

 

Community Support Team _ Dong Li
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
v-lid-msft
Community Support
Community Support

Hi @aellison ,

 

We can create following measures and use them in table visual to meet your requirement:

 

LastMonth = 
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        'Table',
        [HireDate]
            < DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 )
            && OR (
                [TerminationDate] >= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 1 ),
                ISBLANK ( [TerminationDate] )
            )
    )
)

 

LastMonthOfLastYear = 
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        'Table',
        [HireDate]
            < DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ) - 1, 1 )
            && OR (
                [TerminationDate] >= DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), 1 ),
                ISBLANK ( [TerminationDate] )
            )
    )
)

 

Difference Count = [LastMonth] - [LastMonthOfLastYear]

 

Difference Percent = DIVIDE([Difference Count] , [LastMonthOfLastYear] , 0)

 

18.jpg19.jpg


If it doesn't meet your requirement, Please show the exact expected result based on the Tables that we have shared.


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Hi @aellison ,

 

Sorry for late reply, we can create a spreate date table as silcer:

 

SlicerDateTable = CALENDAR(MIN(MIN('Table'[HireDate]),MIN('Table'[TerminationDate])),Max(Max('Table'[HireDate]),MAX('Table'[TerminationDate])))

 

Then we can use create two measures to meet your requirement:

 

LastMonthOfLastYearOfSelectedDay = 

var SelectedDay = MAX('SlicerDateTable'[Date])
return
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        'Table',
        [HireDate]
            < DATE ( YEAR ( SelectedDay ) - 1, MONTH ( SelectedDay ) - 1, 1 )
            && OR (
                [TerminationDate] >= DATE ( YEAR ( SelectedDay ) - 1, MONTH ( SelectedDay ), 1 ),
                ISBLANK ( [TerminationDate] )
            )
    )
)

 

LastMonthOfSelectedDay = 
var SelectedDay = MAX('SlicerDateTable'[Date])
return 
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        'Table',
        [HireDate]
            < DATE ( YEAR (SelectedDay ), MONTH ( SelectedDay ) - 1, 1 )
            && OR (
                [TerminationDate] >= DATE ( YEAR ( SelectedDay ), MONTH ( SelectedDay ), 1 ),
                ISBLANK ( [TerminationDate] )
            )
    )
)

 

1.jpg

 


If it doesn't meet your requirement, Please show the exact expected result based on the Tables that you have shared.


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-lid-msft  ... what I ended up with is VERY close to what you replied back with here. The only real difference is instead of using MAX, I used SELECTEDVALUE to force the user to select one specific date instead of a range. 

 

Counts of Previous Month:= 
VAR selected_date = SELECTEDVALUE('Date'[Date])
RETURN
CALCULATE (
    DISTINCTCOUNT('psa vw_PersonnelCombined'[EmpId]),
    FILTER (
        'psa vw_PersonnelCombined',
        [HireDate]
            < DATE ( YEAR ( selected_date ), MONTH ( selected_date ) - 1, 1 )
            && OR (
                [TerminationDate] >= DATE ( YEAR ( selected_date ), MONTH ( selected_date ), 1 ),
                ISBLANK ( [TerminationDate] )
            )
    )
)

 

and

 

Counts of Previous Year-Month:= 
VAR selected_date = SELECTEDVALUE('Date'[Date])
RETURN
CALCULATE (
    DISTINCTCOUNT('psa vw_PersonnelCombined'[EmpId]),
    FILTER (
        'psa vw_PersonnelCombined',
        [HireDate]
            < DATE ( YEAR ( selected_date ) - 1, MONTH ( selected_date ) - 1, 1 )
            && OR (
                [TerminationDate] >= DATE ( YEAR ( selected_date ) - 1, MONTH ( selected_date ), 1 ),
                ISBLANK ( [TerminationDate] )
            )
    )
)

 

Thank you again for your continued assistance. It is very much appreciated.

 

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.