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

running total in calculated column

Hi all,

 

My data model contains a table with planned changes in stock per item. I want to add a column to this table which contains the accumulated stock changes for this item until the date of the current row. I am sure there must be an easy way to do this, but I haven't found the right way yet. Can anyone help me?

 

Regards,

Theo

1 ACCEPTED SOLUTION

@TheoM

 

OK, try this:

 

RunningTotal =
CALCULATE (
    SUM ( Table1[Movement] ),
    Table1[Date] <= EARLIER ( Table1[Date] ),
    ALLEXCEPT ( Table, Table1[Item] )
)

It's always good to show your sample data also on table/text format so that it can be readily copied

 

View solution in original post

4 REPLIES 4
AlB
Super User
Super User

Hi @TheoM

 

You need to show the structure of your data model and sample data to make things easier for people answering.

What do you mean by 'accumulated stock changes'?? The sum? An example based on your sample data would certainly help.

 

NewColumn =
CALCULATE (
    SUM ( Table1[Stock] ),
    FILTER ( Table1, Table1[Date] < EARLIER ( Table1[Date] ) )
)

but you provide too little info

Hi @AlB,

Thanks for your quick reply!

Here is simplified structure of my fact table. It contains various items which have multiple planned changes. There can be several changes on the same item at the same date (see line 4 and 5). In order to calculate the planned stock level at the date shown on the current row, I want to sum all changes until the date in the current row. The Running Total column shows the desired result. FYI: date format is d-m-yyyy

I hope you can help me with this.

 

 Data model.JPG

 

 

@TheoM

 

OK, try this:

 

RunningTotal =
CALCULATE (
    SUM ( Table1[Movement] ),
    Table1[Date] <= EARLIER ( Table1[Date] ),
    ALLEXCEPT ( Table, Table1[Item] )
)

It's always good to show your sample data also on table/text format so that it can be readily copied

 

Hi @AlB

 

That did the job! Tanks for your help and your advice regarding additional info to the problem.

 

Regards, Theo

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.