Skip to main content
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.

Frequent Visitor

Urgent Need help with dax for days of supply

Days of Supply =

// Get the current week and inventory for the current row

VAR __week = MAX('Inventory'[Week])

VAR __inventory = VALUES(Inventory[Inventory])

// Create a table of all weeks less than the current week

VAR __table = FILTER(ALL(Inventory),[Week]>__week)

// Add our current inventory from above to each row

VAR __table1 = ADDCOLUMNS(__table,"__start",__inventory)

// Add a running total of demand to each row

VAR __table2 = ADDCOLUMNS(__table1,"__demand",SUMX(FILTER(__table1,[Week]<=EARLIER([Week])),[Demand]))

// Add the difference in start versus the running total of demand to each row

VAR __table3 = ADDCOLUMNS(__table2,"__left",[__start] - [__demand])

// Create a table that only has the positive rows

VAR __table4 = FILTER(__table3,[__left]>=0)

// With only the positive rows, the MIN is the last row before demand runs out

VAR __min = MINX(__table4,[__left])

// Therefore, our base days is the number of rows in this table * 7

VAR __baseDays = COUNTROWS(__table4)*7

// Grab the MAX value of the negative rows, this is the row right after our inventory runs out

VAR __max = MAXX(FILTER(__table3,[__left]<0),[__left])

// Divide the row right before the invetory ran out by the sum of the absolute values of right before and after

// the inventory ran out. This is the percentage of days in that week before inventory ran out. multiply this by 7

// and this is the number of days in that week before inventory ran out

VAR __extraDays = __min / (__min + ABS(__max)) * 7


__baseDays + __extraDays

i want the days of supply column to be same as desired result can some one help me with the same




New Member

Hi @Kunal8886 we would be happy to help you out if you still need!

Super User
Super User

If you need urgent help please contact one of the Microsoft Partners in your area.


Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to

Please show the expected outcome based on the sample data you provided.

Want faster answers?

Helpful resources

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


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