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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Filipe_Pacheco
New Member

How to sum the last 5 rows separated by categories in power bi using DAX syntax

Hi everyone, I'm trying to sum the last 5 rows in a table for each row and divided by category, such as the example below that I did in Excel. The expected result is the column D 'RUNNING_SUM'.

 

If I would write this in SQL, I would use SUM OVER PARTITION. 

 

Could you anwser that for me?

 

.Example in Excel how to do itExample in Excel how to do it

1 ACCEPTED SOLUTION

hi @Filipe_Pacheco 

try like:

Coulmn = 
VAR _fam = [Fam]
VAR _year = [YEAR]
RETURN
SUMX(
    FILTER(
        TableName,
        TableName[Fam] = _fam
           &&TableName[Year] >=_year-4
           &&TableName[Year]<=_year
    ),
    TableName[Value]
)

 

FreemanZ_0-1678282226371.png

 

View solution in original post

4 REPLIES 4
FreemanZ
Super User
Super User

hi @Filipe_Pacheco 

could you provide the expected result directly?

Hi @FreemanZ , I edited the post, but the expected result is the Column D 'RUNNING_SUM'.

hi @Filipe_Pacheco 

try like:

Coulmn = 
VAR _fam = [Fam]
VAR _year = [YEAR]
RETURN
SUMX(
    FILTER(
        TableName,
        TableName[Fam] = _fam
           &&TableName[Year] >=_year-4
           &&TableName[Year]<=_year
    ),
    TableName[Value]
)

 

FreemanZ_0-1678282226371.png

 

That one was hard, congratulations, overwhelming 👏

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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