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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
n00ne
Helper I
Helper I

count of active ppl

Hi all,

 

Again I would like to ask you for your help.

I have one table with empid and rise date looking as follows:

EmpID RiseDate
1          01 January 2022
2          01 January 2022
3          01 February 2022
2          01 March 2022
3          01 March 2022
4          01 April 2022
5          01 April 2022

 

With this I would like to have distinct count of people for each year. So in Jan I would like to have as a result 2, in Feb 3, in March 3 again because these are same people based on empid getting rise.

And then I have second table telling me if some1 is no longer working for us:

EmpID TerminationDate
3          01 April 2022

 

So for the results for April I would like to have 4, because 2 new people got rise but one of the person who got rise before april in same year is no longer with us, so he/she should not be counted anymore.

The solution should work only for each year separately as mentioned before.

 

I would be much appreciated for any tips how to solve this.

 

Thank you very much in advance for your help.

1 ACCEPTED SOLUTION

Hi,

Thank you for your explanation.

Please check the below and the attached file if it suits your requirement.

Thank you.

 

Distinct count in a year: =
VAR _emplist =
    CALCULATETABLE (
        SUMMARIZE ( Rise, Employee[EmpID] ),
        'Date'[Date] <= MAX ( 'Date'[Date] ),
        'Date'[Year] = MAX ( 'Date'[Year] )
    )
RETURN
    COUNTROWS (
        CALCULATETABLE (
            SUMMARIZE ( Rise, Employee[EmpID] ),
            'Date'[Date] <= MAX ( 'Date'[Date] ),
            'Date'[Year] = MAX ( 'Date'[Year] )
        )
    )
        - COUNTROWS (
            CALCULATETABLE (
                FILTER (
                    SUMMARIZE ( Termination, Employee[EmpID] ),
                    Employee[EmpID] IN _emplist
                ),
                'Date'[Date] <= MAX ( 'Date'[Date] ),
                'Date'[Year] = MAX ( 'Date'[Year] )
            )
        )


Microsoft MVP



If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.




LinkedInVisit my LinkedIn page




Outlook BookingSchedule a short Teams meeting to discuss your question



View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I suggest having a dim-date table like below.

 

Picture1.png

 

Distinct count in a year: =
COUNTROWS (
    CALCULATETABLE (
        SUMMARIZE ( Rise, Employee[EmpID] ),
        'Date'[Date] <= MAX ( 'Date'[Date] ),
        'Date'[Year] = MAX ( 'Date'[Year] )
    )
)
    - COUNTROWS (
        CALCULATETABLE (
            SUMMARIZE ( Termination, Employee[EmpID] ),
            'Date'[Date] <= MAX ( 'Date'[Date] ),
            'Date'[Year] = MAX ( 'Date'[Year] )
        )
    )


Microsoft MVP



If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.




LinkedInVisit my LinkedIn page




Outlook BookingSchedule a short Teams meeting to discuss your question



Hi, Thank you for your respond.

The solution will not work in situation when in termination table will be more rows but they will not be present in rise table i.e.

EmpID TerminationDate
3          01 April 2022

6          01 April 2022

 

Solution should cross-check if person from termination was present in respective year in rise table and then subtrack it from result.

Hi,

Thank you for your explanation.

Please check the below and the attached file if it suits your requirement.

Thank you.

 

Distinct count in a year: =
VAR _emplist =
    CALCULATETABLE (
        SUMMARIZE ( Rise, Employee[EmpID] ),
        'Date'[Date] <= MAX ( 'Date'[Date] ),
        'Date'[Year] = MAX ( 'Date'[Year] )
    )
RETURN
    COUNTROWS (
        CALCULATETABLE (
            SUMMARIZE ( Rise, Employee[EmpID] ),
            'Date'[Date] <= MAX ( 'Date'[Date] ),
            'Date'[Year] = MAX ( 'Date'[Year] )
        )
    )
        - COUNTROWS (
            CALCULATETABLE (
                FILTER (
                    SUMMARIZE ( Termination, Employee[EmpID] ),
                    Employee[EmpID] IN _emplist
                ),
                'Date'[Date] <= MAX ( 'Date'[Date] ),
                'Date'[Year] = MAX ( 'Date'[Year] )
            )
        )


Microsoft MVP



If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.




LinkedInVisit my LinkedIn page




Outlook BookingSchedule a short Teams meeting to discuss your question



Thank you for your help.

Really appreciated.

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors