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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
PowerBINL
New Member

Calculating cumulative backlog with multiple instances per order

Hi all,

 

I am trying to calculate the cumulative backlog based on the order ID. Orders are both planned and fulfilled, although fulfilment (production) of the order does not have to be on the same day. 

 

Two fact tables basically exist in my model:

- Planning table with order ID, order qty, and deadline 

- Production table with order ID, Qty produced and production date.

 

I want to calculate the total backlog of all the orders that were not fulfilled in time. Orders that are produced before the deadline are also fine and are not penalized or something. Backlog is calculated on a day basis

 

To illustrate: 

 

Planning: 

  • Order A1, Qty = 100, Deadline = 20-03-2022
  • Order B2, Qty = 30, Deadline = 21-03-2022

Production: 

  • Order A1, Qty = 20, Date = 19-03-2022 (orders can be produced before deadline)
  • Order A1, Qty = 50, Date = 20-03-2022
  • Order A1, Qty = 10, Date = 21-03-2022
  • Order A1, Qty = 20, Date = 22-03-2022
  • Order B1, Qty = 10, Date = 21-03-2022
  • Order B1, Qty = 10, Date = 21-03-2022
  • Order B1, Qty = 10, Date = 22-03-2022

 

Which leads to the following, when one would build in Excel:

casperv12_0-1648817089639.png

 

I have multiple (combinations) of proposed solutions from other questions, but have not managed to create the figure in PowerBI. I sincerely hope you guys can help! Looking forward to a respons.




2 ACCEPTED SOLUTIONS
johnt75
Super User
Super User

You can create a measure like

 

 

Backlog =
VAR currentDate =
    MAX ( 'Date'[Date] )
RETURN
    SUMX (
        'Planning',
        IF (
            SELECTEDVALUE ( 'Planning'[Deadline] ) > currentDate,
            0,
            VAR currentQty =
                SELECTEDVALUE ( 'Planning'[Qty] )
            VAR totalProduced =
                CALCULATE (
                    SUMX ( RELATEDTABLE ( 'Production' ), 'Production'[Qty] ),
                    REMOVEFILTERS ( 'Date' ),
                    'Production'[Date] <= currentDate
                )
            RETURN
                currentQty - totalProduced
        )
    )

 

 

 

View solution in original post

Not sure why its not working at the aggregate level, but I was able to get a working aggregate with

Total Backlog = IF( ISINSCOPE( 'Planning'[Order ID]), [Backlog],
var summaryTable = ADDCOLUMNS( SUMMARIZE( 'Planning',Planning[Order ID]), "@val", [Backlog])
return SUMX( summaryTable, [@val]))

View solution in original post

10 REPLIES 10
johnt75
Super User
Super User

You can create a measure like

 

 

Backlog =
VAR currentDate =
    MAX ( 'Date'[Date] )
RETURN
    SUMX (
        'Planning',
        IF (
            SELECTEDVALUE ( 'Planning'[Deadline] ) > currentDate,
            0,
            VAR currentQty =
                SELECTEDVALUE ( 'Planning'[Qty] )
            VAR totalProduced =
                CALCULATE (
                    SUMX ( RELATEDTABLE ( 'Production' ), 'Production'[Qty] ),
                    REMOVEFILTERS ( 'Date' ),
                    'Production'[Date] <= currentDate
                )
            RETURN
                currentQty - totalProduced
        )
    )

 

 

 

Hi John,


Thank you for the quick response. 

I have three follow-up questions based on your proposals:

1. Does it assumes a third date table with relationsship as below? Or should it relate based on orderID

2. In which table should the measure be created?

3. The SUMX function you wrote has three arguments, which I am not able to recreate. How to deal with it?


Looking forward to your reply.

 

casperv12_0-1648820535690.png

 

My solution assumes that there is no relationship from the Date table to either of the 2 tables, and a one-to-many relationship on orderID between planning and production.

It doesn't make any difference which table the measure is created on, it could go on either. Sometimes people like to have a separate table just for measures.

There should only be 2 arguments to the SUMX, I missed a closing ) after SELECTEDVALUE(Planning[Deadline])

Hi John,

 

Thanks. Could you insert the ) at the right position in your initial post? It still provides me with an error

Edited now. I'd missed out an entire CALCULATE as well.

Thanks. It provides me with the figure below. It does work, but does not gives the desired/expected result. Is there any way I can share the Pbix file, maybe it makes it easier (WeTransfer?).

casperv12_0-1648823109374.png

 

 

 

Yes, you can share the file. Dropbox, Google Drive, OneDrive, whatever.

Thank you.

 

Are you able to acces the file?


It does seem to work for individual orders b.t.w.!

casperv12_0-1648823777626.png

 

 

Not sure why its not working at the aggregate level, but I was able to get a working aggregate with

Total Backlog = IF( ISINSCOPE( 'Planning'[Order ID]), [Backlog],
var summaryTable = ADDCOLUMNS( SUMMARIZE( 'Planning',Planning[Order ID]), "@val", [Backlog])
return SUMX( summaryTable, [@val]))

This seems to be the solution. Thank you John! I could not have solved this

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.