Forum Discussion

PowerBINL's avatar
PowerBINL
New Member
4 years ago
Solved

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...
  • johnt75's avatar
    4 years ago

    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
            )
        )

     

     

     

  • johnt75's avatar
    johnt75
    4 years ago

    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]))