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
AGo
Post Patron
Post Patron

Stock cumulative total DAX

Hi! I'm trying to DAX a calculated column for the stock cumulative total by product. When present the first movement of the year of a product has Initial Inventory="Y" so the cumulative calculation resets and begins from that quantity value, if there's not a Initial inventory movement the calculation won't reset, how can I write this formula?

Another problem is that I could have multiple movements of the same product in the same date with the same moved quantity, I have to use a row index number logic?

Consider that this database has several years of data.

Cattura.JPG

Someone can please help me?

21 REPLIES 21

The formula doesn't work as a calculated column because of the different context (it will be calculated in the context of the current row only, that's why you get the amount itself).

Try this one as a calculated column:

CumulativeStockColumn = 
VAR MaxDate = [Date]
VAR CurrentProduct = [Product]
VAR InitialDate = MAXX(FILTER(ALL(Stock);Stock[Date]<=MaxDate && Stock[Product]=CurrentProduct &&Stock[Initial Inventory]="Y");Stock[Date])
RETURN
   SUMX(FILTER(ALL(Stock);Stock[Date]<= MaxDate && Stock[Date]>=InitialDate && Stock[Product] = CurrentProduct); Stock[Quantity])

The calculation is based on comparing the dates, so transactions on the same day will have the same cumulative result; unless there's a time component in the date as well.

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.