Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
arvbot_LE
Frequent Visitor

DAX Carton Backlog Calculation with maximum Capacity per Day

Hi Guys,

 

I struggle for a while with this topic now, if it is even possible to calculate in Power BI. 

The situation: 

I have a table with a carton quantity per Date. Each day there is a restriction on how many cartons can be processed (e.g. 100 cartons). If there are more cartons than can be processed, the quantity is taken to the next day. Having this backlog for one day, is no problem, but this scenario can happen multiple days in a row. Adding new backlog each day, that will be processed once the "new cartons" are below our maximum capacity.

 

DateCartons IncomingCartons ProcessedCartons Backlog
190900
211010010
313010040
410510045
59510040
650900

 

In Excel it is easy, as I can simply sum for the processed Cartons: MIN( 100, "Today Cartons Incoming" +  "Yesterday Cartons Backlog") and Backlog : "Today Cartons Incoming" +  "Yesterday Cartons Backlog" - Today Processed

 

but in DAX I am currently not able to exit my current mode of thinking. 

Let me know, if you need more details and thanks for your help.

5 REPLIES 5
Anonymous
Not applicable

Hi, @arvbot_LE 

Based on your description, I created the following dataset:

vjianpengmsft_0-1740722089415.png

Create the following two measures:

Measure = 
VAR _a = SUM('Table'[Cartons Incoming])
VAR _b = SUM('Table'[Cartons Processed])
VAR _c = _a -_b
RETURN _c
Measure 2 = CALCULATE([Measure],ALLSELECTED('Table'),'Table'[Date]<=SELECTEDVALUE('Table'[Date]))

Here are the results:

vjianpengmsft_1-1740722181829.png

 

Best Regards

Jianpeng Li

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

Hi @Anonymous ,

 

this is the "easy" approach, which I have already in place, but does not solve my issue.

My issue is, that my cartons processed is not a given number. It is dependent on my incoming cartons of each day and the backlog of cartons from all days before. 

It is a recursion, which I assume is not possible in DAX, but maybe ...

bhanu_gautam
Super User
Super User

@arvbot_LE Create a calculated column for the daily processed cartons:

Cartons Processed =
VAR MaxCapacity = 100
VAR IncomingCartons = 'Table'[Cartons Incoming]
VAR PreviousBacklog =
CALCULATE(
SUM('Table'[Cartons Backlog]),
FILTER(
'Table',
'Table'[Date] = EARLIER('Table'[Date]) - 1
)
)
RETURN
MIN(MaxCapacity, IncomingCartons + COALESCE(PreviousBacklog, 0))

 

Create a calculated column for the daily backlog:

Cartons Backlog =
VAR MaxCapacity = 100
VAR IncomingCartons = 'Table'[Cartons Incoming]
VAR PreviousBacklog =
CALCULATE(
SUM('Table'[Cartons Backlog]),
FILTER(
'Table',
'Table'[Date] = EARLIER('Table'[Date]) - 1
)
)
VAR ProcessedCartons =
MIN(MaxCapacity, IncomingCartons + COALESCE(PreviousBacklog, 0))
RETURN
IncomingCartons + COALESCE(PreviousBacklog, 0) - ProcessedCartons

 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






@bhanu_gautam , 

Thanks for the quick reply. I tried to implement these formulas. I understand mostly what you have written (never used COALESCE before) and are similar to what I tried so far.

 

Unfortunatly I do have a problem with the Carton backlog. In the variable for previous_backlog: I can't reference on the formula I am currently writing, so I exchanged it with the daily backlog, as I hadn't a better idea. For periods with 1 day backlog it works,

arvbot_LE_2-1740653150725.png

 

but the sample dataset below; I did the calculation by hand for comparison, this does not work properly now

sorry for the messy order of columns 🙂

arvbot_LE_0-1740652305262.png

arvbot_LE_1-1740652724863.png

I really apprechiate your experience. 

 

And it is possible that my approach is too complicated...

In the end I am looking for a stacked column chart, X axis as Date and as values once the processed cartons (today incoming + everything that could not be processed till this day) and second the total backlog I have left after what I processed today.

Hi, @arvbot_LE 

Please try below mention measures

day backlog = 
 var left_cartons = sum('Table'[Cartons incoming])-sum('Table'[Cartons Processed])
 RETURN
 IF(left_cartons<0,0,left_cartons)
Cartons backlog = 
SUMX(
    FILTER(ALL('Table'[Date],'Table'[Cartons incoming],'Table'[Cartons Processed]),'Table'[Date]<=MIN('Table'[Date])),
    var incoming = 'Table'[Cartons incoming]
    var processed =  'Table'[Cartons Processed]
    var result = incoming-processed
    RETURN result)

Dangar332_0-1741160986065.png

Best Regards,
Dangar

 

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



Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.