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

Rolling sum of sales for three years

Hi,

 

I would like to calculate a rolling sum of sales for three years, the current and two previuos ones. An example is below:

venice23_0-1675195118856.png

 

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @Anonymous 

try like:
NewCalculatedColumn =
VAR _year = [Year]
RETURN
SUMX(
    FILTER(
        TableName,
        TableName[Year] IN {_year, _year-1, _year-2}
    ),
    TableName[Sales]
)
 
FreemanZ_0-1675218119433.png

 

View solution in original post

4 REPLIES 4
FreemanZ
Super User
Super User

hi @Anonymous 

try like:
NewCalculatedColumn =
VAR _year = [Year]
RETURN
SUMX(
    FILTER(
        TableName,
        TableName[Year] IN {_year, _year-1, _year-2}
    ),
    TableName[Sales]
)
 
FreemanZ_0-1675218119433.png

 

Anonymous
Not applicable

Hi @FreemanZ ,

I am just trying to finilise my query. How would the measure look like if one more colomn, i.e. 'colour', had to be introduced?

 

venice23_0-1675354238845.png

 

Anonymous
Not applicable

This solution works well for me, thank you!

hi @Anonymous 

or you can plot a table visual with the Year column and a measure like:
Measure =
VAR _year = MAX(TableName[Year])
RETURN
SUMX(
    FILTER(
        ALL(TableName),
        TableName[Year] IN {_year, _year-1, _year-2}
    ),
    TableName[Sales]
)
FreemanZ_1-1675218204011.png

 

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.

Top Solution Authors