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

Cumulative total (last week)

Hello  -  Currently I have this measure which gives me the YTD cumulative total that I need, by week.   However, I would like to have another measure that gives me the cumulative total, but for the prior calendar week.   Just not sure how to modify this measure.    And just to confirm, I'm not trying to look 7 days back from today, and I am not looking for each "week's" cumulative total.  I am looking for the YTD total up to each week prior to the current week.     Any suggestions?  And thanks for any help!

 

Cumulative RMA Count =
VAR CurrentDate= MAX( 'Date Table'[Date])
RETURN CALCULATE([Distinct Count of RMAs], ALLEXCEPT('Date Table','Date Table'[Date]), 'Date Table'[Date]<=CurrentDate)
 
So, for example:   
 
Week Number     Cumulative YTD Total      Prior Calend Week YTD Total  (this is the column I need the new measure for)
Week 30                  32                                 25   (would be cumulative total as of week 29)
Week 31                  88                                 32  (cumulative total of all the prior weeks)
Week 32                  215                               88  (cumulative total of all the prior weeks)
Week 33                  250                               215  (cumulative total of all the prior weeks)
Week 34                  279                               250 (cumulative total of all the prior weeks)
 etc......
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hello @sevenhills    I had a chance to play around with the formula above and was able to make minor tweaks to get what I needed and correct the issue that was happening with your measure.    The issue was that the very last cumulative date in the previous week column was matching with the actual previous week's total as I mentioned in a previous post.    I've changed it to this, which now captures my last row correctly according to what I need.   Thanks for getting me on the right path!   Will mark your answer as a solution  (with minor tweaks) 😀

 

Prev Cumulative Week RMA Count =
VAR CurrentWeek = MAX('Date Table'[WeekEnding])
RETURN CALCULATE([Distinct Count of RMAs], ALLEXCEPT('Date Table','Date Table'[WeekEnding]),'Date Table'[WeekEnding]<= (CurrentWeek - 1) )


week over week cumul.jpg

View solution in original post

7 REPLIES 7
sevenhills
Super User
Super User

Just curious, wondering whether you tried using "-7"

 

Prev Cumulative RMA Count =
VAR CurrentDate= MAX( 'Date Table'[Date])
RETURN CALCULATE([Distinct Count of RMAs], ALLEXCEPT('Date Table','Date Table'[Date]), 'Date Table'[Date]<= (CurrentDate - 7) )

 

 

Anonymous
Not applicable

Hello @sevenhills    I had a chance to play around with the formula above and was able to make minor tweaks to get what I needed and correct the issue that was happening with your measure.    The issue was that the very last cumulative date in the previous week column was matching with the actual previous week's total as I mentioned in a previous post.    I've changed it to this, which now captures my last row correctly according to what I need.   Thanks for getting me on the right path!   Will mark your answer as a solution  (with minor tweaks) 😀

 

Prev Cumulative Week RMA Count =
VAR CurrentWeek = MAX('Date Table'[WeekEnding])
RETURN CALCULATE([Distinct Count of RMAs], ALLEXCEPT('Date Table','Date Table'[WeekEnding]),'Date Table'[WeekEnding]<= (CurrentWeek - 1) )


week over week cumul.jpg

Thank you and glad I was able to provide the right direction.

 

🙂 

Anonymous
Not applicable

@sevenhills    Your measure works for all of the prior weeks except the most recent one.  I think because it is looking 7 days back from today, instead of grabbing the full previous calendar week.  In other words, the last row below should show 2,132 in the 3rd column, and 17 for the difference (last column).   This would give me the full week of last week.   So, very close to what I need, but not quite exactly.  In the table I'd like to show the cumulative total as of this week, 2nd column, and then the full total (as of the end of the last calendar week, 3rd column).     Ideally, I would also use those values in a card visual as well.  For example, to show this week,  last week, and create a measure to show the difference.   

 

week over week cumul.jpg

Based on your reply, you need the (value upto) completed last week date.

 

What is the currentdate represents?

 

 

Please check for Week End Date ... 

https://bielite.com/blog/week-start-date-power-bi-dax/

Anonymous
Not applicable

CurrentDate is simply the current date.   Yes, correct, I need the value "up to" the prior calendar week. 

I see you are using year and week number. May I suggest one more way to achieve the same and better


https://forum.enterprisedna.co/t/previous-weeks-calculation/3559/2

 

Please tune the measure to your needs based on this link.

I will try your measure as follows: Adjust <= or =, as I dont know the  [Distinct Count of RMAs]

 

Previous Cumulative RMA Count = 
VAR Currentweek =
    SELECTEDVALUE ( 'Date Table'[Week Number] )
VAR CurrentYear =
    SELECTEDVALUE ( 'Date Table'[Year] )
VAR MAXweeknumber =
    CALCULATE ( MAX ( 'Date Table'[Week Number] ), ALL ( 'Date Table' ) )
RETURN
    SUMX (
        FILTER (
            ALL ( 'Date Table' ),
            IF (
                Currentweek = 1,
                'Date Table'[Week Number] <= MAXweeknumber
                    && 'Date Table'[Year] = CurrentYear - 1,
                'Date Table'[Week Number] <= Currentweek - 1
                    && 'Date Table'[Year] = CurrentYear
            )
        ),
        [Distinct Count of RMAs]
    )
 

 

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.