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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
joshua1990
Post Prodigy
Post Prodigy

CALCULATING COLUMN Rolling 20week Sales

Hi experts!

I have a Dimensional Table that contains all Articles for each department:

ArticleDepartment
ABC1
EDFG2

 

Then I have a transactional table:

Year-WeekArticleSales
2022-01ABC500
2022-02ABC600
2022-03ABC400

 

Now I would like to add a calculated column into the dimensional table that shows me all Sales for each Article for the past 20 weeks.

I now, I general we would do that as a simple Dax Measure in a matrix visual.

But here is the ask as a calculated column. How would you do that?

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @joshua1990 

 

You can try the following methods. I simulated some data briefly and hope it will meet your requirements.

Column:

Year-Week = YEAR([Date])&"-"&WEEKNUM([Date],2)

vzhangti_0-1649061254794.png

Rolling 20 week sales = 
VAR N1 =
    SUMMARIZE (
        FILTER ( Transactional, [Year-Week] <= MAX ( Transactional[Year-Week] ) ),
        [Date],
        "Sum",
            CALCULATE (
                SUM ( Transactional[Sales] ),
                FILTER ( Transactional, [Article] = EARLIER ( Dimensional[Article] ) )
            )
    )
VAR N2 =
    TOPN ( 20, N1, [Date], DESC )
RETURN
    SUMX ( N2, [Sum] )

vzhangti_1-1649061319878.png

Please see the attachment for details.

 

Best Regards,

Community Support Team _Charlotte

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

2 REPLIES 2
v-zhangti
Community Support
Community Support

Hi, @joshua1990 

 

You can try the following methods. I simulated some data briefly and hope it will meet your requirements.

Column:

Year-Week = YEAR([Date])&"-"&WEEKNUM([Date],2)

vzhangti_0-1649061254794.png

Rolling 20 week sales = 
VAR N1 =
    SUMMARIZE (
        FILTER ( Transactional, [Year-Week] <= MAX ( Transactional[Year-Week] ) ),
        [Date],
        "Sum",
            CALCULATE (
                SUM ( Transactional[Sales] ),
                FILTER ( Transactional, [Article] = EARLIER ( Dimensional[Article] ) )
            )
    )
VAR N2 =
    TOPN ( 20, N1, [Date], DESC )
RETURN
    SUMX ( N2, [Sum] )

vzhangti_1-1649061319878.png

Please see the attachment for details.

 

Best Regards,

Community Support Team _Charlotte

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

johnt75
Super User
Super User

Assuming that you have a date table with a start of week column, you could add a column as

Rolling 20 week sales = 
var startDate = LOOKUPVALUE('Date'[start of week], 'Date'[Date], TODAY())
return CALCULATE( SUMX( RELATEDTABLE( 'Transactions'), 'Transactions'[Sales]),
'Date'[Date] >= startDate
)

This would be recalculated whenever the data is refreshed

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.