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 sales last week vs this week

Hi all,

 

I am calculating Cumulative sales for last week to compare with cumulative this week sales but I am not getting right output.

 

Cumulative Sales last week =
CALCULATE (
[Total Sales Last Week],
FILTER (
ALL( PBIDateTable[Week number] ),
PBIDateTable[Week number] < MAX ( PBIDateTable[Week number] )
)
)image.png

1 ACCEPTED SOLUTION
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

 By my test, you could create the two measure to calculate Cumulative sales for last week and cumulative this week sales by slicer.

 

Cumulative Sales of this week =
CALCULATE (
    SUM ( PBIDatetable[Sales] ),
    DATESBETWEEN ( 'Table'[Date], MAX ( 'Table'[Date] ) - 7, MAX ( 'Table'[Date] ) ),
    FILTER (
        ALL ( PBIDatetable ),
        'PBIDatetable'[Accountlevel] = MAX ( 'PBIDatetable'[Accountlevel] )
            && WEEKNUM ( 'PBIDatetable'[date] ) = WEEKNUM ( MIN ( 'PBIDatetable'[date] ) )
    )
)
Cumulative Sales last_week =
VAR startoflastweek =
    CALCULATE (
        MIN ( 'Table'[Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[WeekNum]
                = WEEKNUM ( MIN ( 'Table'[Date] ) ) - 1
        )
    )
RETURN
    CALCULATE (
        SUM ( PBIDatetable[Sales] ),
        DATESBETWEEN ( 'Table'[Date], startoflastweek, MIN ( 'Table'[Date] ) - 7 ),
        FILTER (
            ALL ( PBIDatetable ),
            'PBIDatetable'[Accountlevel] = MAX ( 'PBIDatetable'[Accountlevel] )
                && WEEKNUM ( 'PBIDatetable'[date] )
                    = WEEKNUM ( MIN ( 'PBIDatetable'[date] ) ) - 1
        )
    )

The picture of result is below.

 

Capture.PNG

 

You also could refer to my pbix file here.

 

If you need additional help please share some data sample and expected output. You can upload it to OneDrive or Dropbox and post the link here. Do mask sensitive data before uploading.)

 

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
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-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

 By my test, you could create the two measure to calculate Cumulative sales for last week and cumulative this week sales by slicer.

 

Cumulative Sales of this week =
CALCULATE (
    SUM ( PBIDatetable[Sales] ),
    DATESBETWEEN ( 'Table'[Date], MAX ( 'Table'[Date] ) - 7, MAX ( 'Table'[Date] ) ),
    FILTER (
        ALL ( PBIDatetable ),
        'PBIDatetable'[Accountlevel] = MAX ( 'PBIDatetable'[Accountlevel] )
            && WEEKNUM ( 'PBIDatetable'[date] ) = WEEKNUM ( MIN ( 'PBIDatetable'[date] ) )
    )
)
Cumulative Sales last_week =
VAR startoflastweek =
    CALCULATE (
        MIN ( 'Table'[Date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[WeekNum]
                = WEEKNUM ( MIN ( 'Table'[Date] ) ) - 1
        )
    )
RETURN
    CALCULATE (
        SUM ( PBIDatetable[Sales] ),
        DATESBETWEEN ( 'Table'[Date], startoflastweek, MIN ( 'Table'[Date] ) - 7 ),
        FILTER (
            ALL ( PBIDatetable ),
            'PBIDatetable'[Accountlevel] = MAX ( 'PBIDatetable'[Accountlevel] )
                && WEEKNUM ( 'PBIDatetable'[date] )
                    = WEEKNUM ( MIN ( 'PBIDatetable'[date] ) ) - 1
        )
    )

The picture of result is below.

 

Capture.PNG

 

You also could refer to my pbix file here.

 

If you need additional help please share some data sample and expected output. You can upload it to OneDrive or Dropbox and post the link here. Do mask sensitive data before uploading.)

 

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@v-piga-msft      Hello  -  This formula looks like something I could use but it seems to me it is not working properly.  

 

The cumulative result for the prior week is showing a "2"  in the table below, rather than the cumulative sum (14).  But I'm not exactly sure how to fix the formula to get the correct result.    Anyone know how to fix this?  

 

Thanks

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.