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
Anonymous
Not applicable

Calculate salary last year and current year for an employee

Hello,

 

I have to calculate the salary for an employee for last year and the current year.

 

I have the below data.

paragchapre1_0-1632152963507.png

 

The output should be like this.

paragchapre1_1-1632153003111.png

 

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Please check if this is what you want:

Current Year =
VAR t1 =
    ADDCOLUMNS (
        'Table',
        "Month_Count",
            COUNTROWS (
                FILTER (
                    CALENDAR ( 'Table'[Start date], 'Table'[End date] ),
                    DAY ( [Date] ) = 1
                        && YEAR ( [Date] ) = YEAR ( TODAY () )
                )
            )
    )
VAR t2 =
    ADDCOLUMNS ( t1, "Salary_SUM", [Month_Count] * [Salary] )
RETURN
    SUMX ( t2, [Salary_SUM] )
Last Year =
VAR t1 =
    ADDCOLUMNS (
        'Table',
        "Month_Count",
            COUNTROWS (
                FILTER (
                    CALENDAR ( 'Table'[Start date], 'Table'[End date] ),
                    DAY ( [Date] ) = 1
                        && YEAR ( [Date] ) = YEAR ( TODAY () ) - 1
                )
            )
    )
VAR t2 =
    ADDCOLUMNS ( t1, "Salary_SUM", [Month_Count] * [Salary] )
RETURN
    SUMX ( t2, [Salary_SUM] )

Icey_0-1632473326958.png

 

 

Best Regards,

Icey

 

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

3 REPLIES 3
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Please check if this is what you want:

Current Year =
VAR t1 =
    ADDCOLUMNS (
        'Table',
        "Month_Count",
            COUNTROWS (
                FILTER (
                    CALENDAR ( 'Table'[Start date], 'Table'[End date] ),
                    DAY ( [Date] ) = 1
                        && YEAR ( [Date] ) = YEAR ( TODAY () )
                )
            )
    )
VAR t2 =
    ADDCOLUMNS ( t1, "Salary_SUM", [Month_Count] * [Salary] )
RETURN
    SUMX ( t2, [Salary_SUM] )
Last Year =
VAR t1 =
    ADDCOLUMNS (
        'Table',
        "Month_Count",
            COUNTROWS (
                FILTER (
                    CALENDAR ( 'Table'[Start date], 'Table'[End date] ),
                    DAY ( [Date] ) = 1
                        && YEAR ( [Date] ) = YEAR ( TODAY () ) - 1
                )
            )
    )
VAR t2 =
    ADDCOLUMNS ( t1, "Salary_SUM", [Month_Count] * [Salary] )
RETURN
    SUMX ( t2, [Salary_SUM] )

Icey_0-1632473326958.png

 

 

Best Regards,

Icey

 

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

Anonymous
Not applicable

I will check. Thank you.

amitchandak
Super User
Super User

@Anonymous , refer if this blog or attached file can help

 

How to divide/distribute values between start date or end date or count days across months/days: https://community.powerbi.com/t5/Community-Blog/How-to-divide-distribute-values-between-start-date-or-end-date/ba-p/1503785

 

 

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.