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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
LeiteFel
Regular Visitor

Divide Expenses into months

I have a a table of employees and their yearly salaries, all employees have a 1 year contract. I need to divide their salaries into the 12 months after they have started working (This date is on a column).

I need a bar chart that will have monthly expenses, summing all the salaries that will be payed each month.

How do I do it?

Example, lets say employee A has started in june 2023 and employee B on august 2023, the chart of monthly expenses need to look like this:

LeiteFel_0-1720806541900.png

 

1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @LeiteFel ,

 

There are multiple ways to achive your required output and one of them is as follows:

I first created a dummy table like below which shows the yearly salary and the start date for 1 year contract employees.  

DataNinja777_0-1720841076676.png

 

I then wrote a dax measure like below to split the yearly salary into monthly salary.  

 

Generated Table =
VAR ds =
    SUMMARIZE (
        'Salary table',
        'Salary table'[Employee name],
        'Salary table'[Start Date],
        'Salary table'[Yearly Salary]
    )
VAR gs =
    GENERATESERIES ( 1, 13 )
VAR result =
    GENERATE ( ds, VAR salary = [Yearly Salary] RETURN gs )
RETURN
    ADDCOLUMNS (
        DISTINCT ( result ),
        "eomonth", EOMONTH ( [Start Date], [Value] - 1 ),
        "beginning of month",
            EOMONTH ( [Start Date], [Value] - 2 ) + 1,
        "End Date", EDATE ( [Start Date], 12 ) - 1
    )

 

As the salary part required prorating for days and gets a bit complicated, I created a calculated column instead of combining in one table measure above.  

 

Monthly salary =
VAR PCT_Start_Month = ( [eomonth] - [Start Date] ) / ( [eomonth] - [beginning of month] )
VAR PCT_End_Month = ( [End Date] - [beginning of month] + 1 ) / ( [eomonth] - [beginning of month] )
RETURN
    (
        IF ( [Value] = 1, PCT_Start_Month, IF ( [Value] = 13, PCT_End_Month, 1 ) )
    ) * [Yearly Salary] / 12

 

 

The generated table from the above mesure and calculated column is shown below:

DataNinja777_1-1720841475594.png

I then created a calculated calendar table and the employee name dimension table and created relationship with the fact tables:

DataNinja777_2-1720841553523.png

The resultant visualiation of the numerical output is as shown below:

DataNinja777_3-1720841665272.png

 

Your required output of stacked column chart is shown below.  

DataNinja777_4-1720841711316.png

The point I need to mention regarding this solution is instead of using 12 to generateseries, we are using 13, because I thought most of the employees are not starting from 1st of the month, and the month 1 and month 13 monthly salaries need to be prorated for this reason. 

DataNinja777_5-1720841992809.png

A quick accuracy check of the output using an employee example who joined on the 1st of the month confirms that this formula properly works to produce correct output in such case, too.

DataNinja777_7-1720843033529.png

 

I attach an example pbix file below:

Best regards,

View solution in original post

2 REPLIES 2
DataNinja777
Super User
Super User

Hi @LeiteFel ,

 

There are multiple ways to achive your required output and one of them is as follows:

I first created a dummy table like below which shows the yearly salary and the start date for 1 year contract employees.  

DataNinja777_0-1720841076676.png

 

I then wrote a dax measure like below to split the yearly salary into monthly salary.  

 

Generated Table =
VAR ds =
    SUMMARIZE (
        'Salary table',
        'Salary table'[Employee name],
        'Salary table'[Start Date],
        'Salary table'[Yearly Salary]
    )
VAR gs =
    GENERATESERIES ( 1, 13 )
VAR result =
    GENERATE ( ds, VAR salary = [Yearly Salary] RETURN gs )
RETURN
    ADDCOLUMNS (
        DISTINCT ( result ),
        "eomonth", EOMONTH ( [Start Date], [Value] - 1 ),
        "beginning of month",
            EOMONTH ( [Start Date], [Value] - 2 ) + 1,
        "End Date", EDATE ( [Start Date], 12 ) - 1
    )

 

As the salary part required prorating for days and gets a bit complicated, I created a calculated column instead of combining in one table measure above.  

 

Monthly salary =
VAR PCT_Start_Month = ( [eomonth] - [Start Date] ) / ( [eomonth] - [beginning of month] )
VAR PCT_End_Month = ( [End Date] - [beginning of month] + 1 ) / ( [eomonth] - [beginning of month] )
RETURN
    (
        IF ( [Value] = 1, PCT_Start_Month, IF ( [Value] = 13, PCT_End_Month, 1 ) )
    ) * [Yearly Salary] / 12

 

 

The generated table from the above mesure and calculated column is shown below:

DataNinja777_1-1720841475594.png

I then created a calculated calendar table and the employee name dimension table and created relationship with the fact tables:

DataNinja777_2-1720841553523.png

The resultant visualiation of the numerical output is as shown below:

DataNinja777_3-1720841665272.png

 

Your required output of stacked column chart is shown below.  

DataNinja777_4-1720841711316.png

The point I need to mention regarding this solution is instead of using 12 to generateseries, we are using 13, because I thought most of the employees are not starting from 1st of the month, and the month 1 and month 13 monthly salaries need to be prorated for this reason. 

DataNinja777_5-1720841992809.png

A quick accuracy check of the output using an employee example who joined on the 1st of the month confirms that this formula properly works to produce correct output in such case, too.

DataNinja777_7-1720843033529.png

 

I attach an example pbix file below:

Best regards,

Hi @DataNinja777 

This has completely solved my problem. Thank you for such a detailed response!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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