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
abogdanov
Helper I
Helper I

sum of values for every previous week

Hello, I'm trying to put together a formula to calculate a sum of values C for every previous week. so for the week 41 it should be a sum of all C under week 40, for week 42 the sum of C of the week 41 and so on. I've looked online but haven't found anything helpful

 

abogdanov_2-1604508645905.png

 

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @abogdanov,

Here is a measure expression about calculating cumulative total on the rolling weeks based on the current year and week number, you can try it if meets your requirement:

Rolling Week =
VAR currDate =
    MAX ( Table[Date] )
RETURN
    CALCULATE (
        SUM ( Table[Amount] ),
        FILTER (
            ALLSELECTED ( Table ),
            WEEKNUM ( Table[Date], 1 ) < WEEKNUM ( currDate, 1 )
                && YEAR ( Table[Date] ) = YEAR ( currDate )
        )
    )

BTW, if you also need to split these calculations based on the current category, you can add them into that formula with values functions:

Rolling Week =
VAR currDate =
    MAX ( Table[Date] )
RETURN
    CALCULATE (
        SUM ( Table[Amount] ),
        FILTER (
            ALLSELECTED ( Table ),
            WEEKNUM ( Table[Date], 1 ) < WEEKNUM ( currDate, 1 )
                && YEAR ( Table[Date] ) = YEAR ( currDate )
        ),
        VALUES ( Table[Category1] )
    )

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @abogdanov,

Here is a measure expression about calculating cumulative total on the rolling weeks based on the current year and week number, you can try it if meets your requirement:

Rolling Week =
VAR currDate =
    MAX ( Table[Date] )
RETURN
    CALCULATE (
        SUM ( Table[Amount] ),
        FILTER (
            ALLSELECTED ( Table ),
            WEEKNUM ( Table[Date], 1 ) < WEEKNUM ( currDate, 1 )
                && YEAR ( Table[Date] ) = YEAR ( currDate )
        )
    )

BTW, if you also need to split these calculations based on the current category, you can add them into that formula with values functions:

Rolling Week =
VAR currDate =
    MAX ( Table[Date] )
RETURN
    CALCULATE (
        SUM ( Table[Amount] ),
        FILTER (
            ALLSELECTED ( Table ),
            WEEKNUM ( Table[Date], 1 ) < WEEKNUM ( currDate, 1 )
                && YEAR ( Table[Date] ) = YEAR ( currDate )
        ),
        VALUES ( Table[Category1] )
    )

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
amitchandak
Super User
Super User

@abogdanov , if you are looking for a measure refer my blogs

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

 

in case you are lookung for colum. Try like

 

E = sumx(filter(Table, [date] =earlier([Date]) -7),[C])

 

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.