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
rack201
Frequent Visitor

Cumulative total based on non unique dates AND text filter

Hi - my table has non-unique dates and I'm trying to calculate a running total for a given date AND text filter pair.  My data looks the equivalent of something like the  below and what I'm aiming for is something like:

 

RunningTotal = calculate(sum('Table'[Revenue]) where WeekEndingDate <= Earlier(WeekEndingDate) AND Store = Store

 

Cumulative Revenue should calculate the running total of revenue for the row 'Store' up to the row 'WeekEndingDate'

 

Maybe I need ALLEXCEPT or ALLSELECTED but I can't quite get it to work.  I've tried as many relative examples as I could find.

 

WeekEndingDateStoreRevenueCumulative Revenue
7-Mar-21Strawberry Lane$7.74 
14-Mar-21Strawberry Lane$7.71 
21-Mar-21Strawberry Lane$8.27 
28-Mar-21Strawberry Lane$1.65 
4-Apr-21Strawberry Lane$3.15 
11-Apr-21Strawberry Lane$0.67 
18-Apr-21Strawberry Lane$6.68 
25-Apr-21Strawberry Lane$7.03 
2-May-21Strawberry Lane$2.88 
9-May-21Strawberry Lane$2.10 
16-May-21Strawberry Lane$3.46 
23-May-21Strawberry Lane$6.15 
30-May-21Strawberry Lane$1.28 
6-Jun-21Strawberry Lane$1.78 
13-Jun-21Strawberry Lane$7.74 
11-Apr-21High St$0.14 
18-Apr-21High St$8.35 
25-Apr-21High St$3.09 
2-May-21High St$7.47 
9-May-21High St$3.30 
16-May-21High St$1.69 
23-May-21High St$7.32 
30-May-21High St$8.19 
6-Jun-21High St$0.20 
13-Jun-21High St$0.20 
28-Mar-21Mountain View$5.70 
4-Apr-21Mountain View$8.82 
11-Apr-21Mountain View$9.32 
18-Apr-21Mountain View$3.61 
25-Apr-21Mountain View$3.80 
2-May-21Mountain View$3.78 
9-May-21Mountain View$5.51 
16-May-21Mountain View$6.56 
23-May-21Mountain View$8.85 
30-May-21Mountain View$6.20 
6-Jun-21Mountain View$6.35 
13-Jun-21Mountain View$7.87 
1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

Hi @rack201 

 

Try this code to add a column to your table:

Cumulative Revenue =
VAR _Date =
    FIRSTNONBLANK ( 'Table'[WeekEndingDate], "" )
RETURN
    CALCULATE (
        SUM ( 'Table'[Revenue] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Store] ),
            'Table'[WeekEndingDate] <= _Date
        )
    )

 

Output :

VahidDM_0-1630888254760.png

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

Appreciate your Kudos ✌️!!

View solution in original post

3 REPLIES 3
qwertzuiop
Advocate III
Advocate III

Hello guys 😀

 

Code works perfektly thanks 💪
But any idea how to manipulate the code to calculate the average instead of sum?

 

Thanks for your contribution

 

Cheers

qwertzuiop

VahidDM
Super User
Super User

Hi @rack201 

 

Try this code to add a column to your table:

Cumulative Revenue =
VAR _Date =
    FIRSTNONBLANK ( 'Table'[WeekEndingDate], "" )
RETURN
    CALCULATE (
        SUM ( 'Table'[Revenue] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Store] ),
            'Table'[WeekEndingDate] <= _Date
        )
    )

 

Output :

VahidDM_0-1630888254760.png

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

Appreciate your Kudos ✌️!!

Brilliant - Thank you VahidDM.. 

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