Forum Discussion
Calculating cumulative backlog with multiple instances per order
- 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 ) ) - 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]))
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
- johnt754 years ago
Super User
Edited now. I'd missed out an entire CALCULATE as well.
- PowerBINL4 years agoNew Member
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?).
- johnt754 years ago
Super User
Yes, you can share the file. Dropbox, Google Drive, OneDrive, whatever.