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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Dynamically calculate employee count in column using previous month data

Hi Team,

I need one help and will really appreciate your efforts to solve this!!

I need to build one report as  below , the ask is to calculate employee count for every month by using employee count from previous month, and add new joinee and subtract discontinued employee in current month. For initial start the employee base is coming from one Anual Input file for each country and new joinee data is coming from another file at monthly level. We have formula to calculate #employees discontinued each month

The formula to calculate Employee count every Month is - 

Sum(Employee base for country from Annual file)+ New Joinee from Monthly File - Discontinued Employee
**Discontinued Employee is calculated as (Employee base for that country from Annual file) * Attrition Rate for that country divided by 12 ( to get data for that 1 month)

For next month iteration, we need to use employee base from previous month not from Annual file

Expected Output for Country = Croatia where Employee base is 86 and Attrition Rate is 12% 

Example Calculation for Jan 2024 = 86(Annual File) + 7 (Monthly File) - (86*0.12/12) = 92 

For Feb = 92 (Data from Jan month) +7 (Monthly File) - (92*0.12/12)= 98

Jan-24Feb-24Mar-24Apr-24May-24Jun-24Jul-24Aug-24Sep-24Oct-24Nov-24Dec-24
            9298104109114119124129134139144149

 

 

Sample Data for Reference

Annual File

CountryAttrition RateEmployee (Base Count)
Croatia12%86
Austria13%100
Belgium15%75

 

Monthly Data for New Joinee

CountryMonth Year# Joinee
CroatiaJan-247
CroatiaFeb-247
CroatiaMar-247
CroatiaApr-247
CroatiaMay-247
CroatiaJun-247
CroatiaJul-247
CroatiaAug-247
CroatiaSep-247
CroatiaOct-247
CroatiaNov-247
CroatiaDec-247
AustriaJan-246
AustriaFeb-246
AustriaMar-246
AustriaApr-246
AustriaMay-246
AustriaJun-246
AustriaJul-246
AustriaAug-246
AustriaSep-246
AustriaOct-246
AustriaNov-246
AustriaDec-246
BelgiumJan-246
BelgiumFeb-246
BelgiumMar-246
BelgiumApr-246
BelgiumMay-246
BelgiumJun-246
BelgiumJul-246
BelgiumAug-246
BelgiumSep-246
BelgiumOct-246
BelgiumNov-246
BelgiumDec-246

 

2 REPLIES 2
Anonymous
Not applicable

Thanks ! Really appreaciate it !

It does render the result correctly but it's kind of lengthy one when the month year is increased till Dec 2029. Is there any way to do it dynamically using some iteration/recursion in M query or may be by using window fuction "Offset"

Anonymous
Not applicable

Hi @Anonymous ,
Depending on the information you provided, you can follow these steps below:
1.Merge Queries in Power Query.

vyifanwmsft_0-1709618010800.png


2.Add new columns.

Month = MONTH('Monthly Data for New Joinee'[Month Year])
Expected Output =
VAR _support = ( 1 - ( 'Monthly Data for New Joinee'[Annual File.Attrition Rate] / 12 ) )
VAR _1 = 'Monthly Data for New Joinee'[Annual File.Employee (Base Count)] * _support + 'Monthly Data for New Joinee'[# Joinee]
VAR _2 = _1 * _support + 'Monthly Data for New Joinee'[# Joinee]
VAR _3 = _2 * _support + 'Monthly Data for New Joinee'[# Joinee]
VAR _4 = _3 * _support + 'Monthly Data for New Joinee'[# Joinee]
VAR _5 = _4 * _support + 'Monthly Data for New Joinee'[# Joinee]
VAR _6 = _5 * _support + 'Monthly Data for New Joinee'[# Joinee]
VAR _7 = _6 * _support + 'Monthly Data for New Joinee'[# Joinee]
VAR _8 = _7 * _support + 'Monthly Data for New Joinee'[# Joinee]
VAR _9 = _8 * _support + 'Monthly Data for New Joinee'[# Joinee]
VAR _10 = _9 * _support + 'Monthly Data for New Joinee'[# Joinee]
VAR _11 = _10 * _support + 'Monthly Data for New Joinee'[# Joinee]
VAR _12 = _11 * _support + 'Monthly Data for New Joinee'[# Joinee]
RETURN
    IF (
        'Monthly Data for New Joinee'[Month] = 1,
        _1,
        IF (
            'Monthly Data for New Joinee'[Month] = 2,
            _2,
            IF (
                'Monthly Data for New Joinee'[Month] = 3,
                _3,
                IF (
                    'Monthly Data for New Joinee'[Month] = 4,
                    _4,
                    IF (
                        'Monthly Data for New Joinee'[Month] = 5,
                        _5,
                        IF (
                            'Monthly Data for New Joinee'[Month] = 6,
                            _6,
                            IF (
                                'Monthly Data for New Joinee'[Month] = 7,
                                _7,
                                IF (
                                    'Monthly Data for New Joinee'[Month] = 8,
                                    _8,
                                    IF (
                                        'Monthly Data for New Joinee'[Month] = 9,
                                        _9,
                                        IF (
                                            'Monthly Data for New Joinee'[Month] = 10,
                                            _10,
                                            IF ( 'Monthly Data for New Joinee'[Month] = 11, _11, _12 )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )

 Final output:

vyifanwmsft_1-1709618081509.png

How to Get Your Question Answered Quickly - Microsoft Fabric Community

If it does not help, please provide more details with your desired out put and pbix file without privacy information.

 

Best Regards,

Ada Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

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.