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
madan27
Frequent Visitor

SUM current and Previous records

Hi,

 

I am having a table as below

 

YearDesignationSalary
2010Engineer50000
2010Sr.Engineer70000
2010A.Manager90000
2011Engineer55000
2011Sr.Engineer75000
2011A.Manager95000
2012Engineer65000
2012Sr.Engineer85000
2012A.Manager105000

 

In the table I am able to filter the records based on Designation (using Visual Level Filter option in Power BI)

 

For example I am filtered the designation as 'Enginner'

 

YearDesignationSalary
2010Engineer50000
2011Engineer55000
2012Engineer65000

 

Now I need to derive the result as below

 

YearDesignationSalarySum
2010Engineer500005000
2011Engineer55000105000
2012Engineer65000170000

 

I need to derive the SUM by adding the Current and Previous years salary. Kindly help me to get the above result table.

 

Thanks,

 

Corrected years.

1 ACCEPTED SOLUTION
Vvelarde
Community Champion
Community Champion

@madan27

 

Hi, try witt this DAX

 

Salary running total in Year =
CALCULATE (
    SUM ( 'Table1'[Salary] ),
    FILTER (
        ALLEXCEPT ( Table1, Table1[Designation] ),
        Table1[Year] <= MAX ( Table1[Year] )
    )
)



Lima - Peru

View solution in original post

6 REPLIES 6
v-ljerr-msft
Employee
Employee

Hi,

 

@Anonymous, I agree with @Vvelarde that madan27 needs to calculate the SUM by adding the Current and all Previous years' salary(not just the last previous year). Smiley Happy

 

@madan27, the formula provided @Vvelarde above should work in your scenario. Just replace "Table1" with your real table name, and use the formula to create a new measure, then show it on the Table visual with other corresponding columns.

 

r4.PNG

Regards

Vvelarde
Community Champion
Community Champion

@madan27

 

Hi, try witt this DAX

 

Salary running total in Year =
CALCULATE (
    SUM ( 'Table1'[Salary] ),
    FILTER (
        ALLEXCEPT ( Table1, Table1[Designation] ),
        Table1[Year] <= MAX ( Table1[Year] )
    )
)



Lima - Peru

Thanks @Vvelarde. I got the required ouput.  

Anonymous
Not applicable

@Vvelarde That is going to give a running total of ALL years.  I read the requirement as current year, plus 1 year ago?  I could be nuts, but if not...

 

Maybe something like... ?

 

Salary CY :=
CALCULATE (
    SUM ( Table1[Salary] ),
    FILTER (
        ALLEXCEPT ( Table1, Table1[Designation] ),
        Table1[Year] = MAX ( Table1[Year] )
    )
)

Salary PY := 
CALCULATE (
    SUM ( Table1[Salary] ),
    FILTER (
        ALLEXCEPT ( Table1, Table1[Designation] ),
        Table1[Year] = MAX ( Table1[Year] ) - 1
    )
)

Salary CY+PY := [Salary CY] + [Salary PY]

Phil_Seamark
Employee
Employee

Hi @madan27

 

In the expected output you have two Engineer records for 2011.  Should one of these be for 2012?

 

2012.png


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Yes Phil, your correct. Sorry for the typo....

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.