Forum Discussion
Orderbook adjusted for previous periods differences
Dear BI Community,
I'm trying to create a BI report that shows the expected future amount (order book) we are going to sell. I have 4 tables:
Calendar table
Sales Contract table, which shows a list of all contract numbers and whether they are active or finished
Distribution table, which shows the monthly expected amount of tons that we expect to sell for each contract
Delivered table, which shows the monthly actual tons we delivered for each contract
The Calendar table is related to the Delivered and Distribution tables based on the date.
The Sales Contract table is related to the Delivered and Distribution tables based on the contract number.
I have used the formula below to calculate, on a monthly basis, whether my company has over- or under-delivered for each specific contract:
Now, what I'm really struggling with is that I want to adjust the current month with the cumulative under- or over-deliveries from previous periods. For example:
If, in periods before the current month, a specific contract has actually delivered 100 tons less than what was agreed (Distributed - Delivered = 100), then I want a formula that corrects the current month's distribution for that contract and increases it by 100 tons (so the original agreed amount + 100 tons).
Vice versa, if we have delivered 100 tons more than agreed, the distribution must be reduced by 100 tons in the current month.
Your help would be greatly appreciated.
Hi NLMV ,
You can create a BI report that adjusts the current month's order book based on the cumulative under or over-deliveries from previous periods with the following DAX formula. This measure will dynamically calculate the adjusted amount for each contract.
Adjusted Monthly Distribution = -- Calculate the originally planned amount for the current period (e.g., the current month) VAR CurrentMonthDistribution = SUM ( 'SalesContractDistribution'[Qty] ) -- Identify the first date of the current period to define the "past" VAR FirstDateOfCurrentPeriod = MIN ( 'Calendar'[Date] ) -- Calculate the cumulative difference between planned and delivered for all periods BEFORE the current one VAR CumulativePreviousDifference = CALCULATE ( SUM ( 'SalesContractDistribution'[Qty] ) - CALCULATE ( SUM ( 'SalesContractDelivery'[Qty] ), 'SalesContractDelivery'[Status] = "Delivered" ), FILTER ( ALL ( 'Calendar' ), 'Calendar'[Date] < FirstDateOfCurrentPeriod ) ) -- Return the current month's plan adjusted by the cumulative past difference. -- If there was an under-delivery (positive difference), it's added. -- If there was an over-delivery (negative difference), it's subtracted. RETURN CurrentMonthDistribution + CumulativePreviousDifferenceThis DAX measure operates by first capturing the originally planned distribution for the current period in a variable. It then determines the start date of this period to serve as an anchor point. The core of the logic lies in the CALCULATE function, which modifies the report's context. It calculates the total historical difference between planned and delivered quantities for all periods before the start of the current one. This is achieved by using FILTER with ALL('Calendar') to remove the current date context and apply a new one for all past dates. The final RETURN statement simply adds this cumulative past difference to the current month's plan. If you under-delivered in the past, the positive difference increases the current month's target; if you over-delivered, the negative difference reduces it.
To use this in your report, create a new measure and paste in the DAX code. You can then add this measure to a Matrix visual to see the results. For a comprehensive view, place the 'Sales Contract'[Contract Number] on the rows, the 'Calendar'[Year] and 'Calendar'[Month] on the columns, and then add your original distribution measure, your actual delivered measure, and this new Adjusted Monthly Distribution measure to the values field. This setup will provide a clear, side-by-side comparison of the original plan versus the dynamically adjusted plan for each contract over time.
Best regards,
5 Replies
- DataNinja777Super User
Hi NLMV ,
You can create a BI report that adjusts the current month's order book based on the cumulative under or over-deliveries from previous periods with the following DAX formula. This measure will dynamically calculate the adjusted amount for each contract.
Adjusted Monthly Distribution = -- Calculate the originally planned amount for the current period (e.g., the current month) VAR CurrentMonthDistribution = SUM ( 'SalesContractDistribution'[Qty] ) -- Identify the first date of the current period to define the "past" VAR FirstDateOfCurrentPeriod = MIN ( 'Calendar'[Date] ) -- Calculate the cumulative difference between planned and delivered for all periods BEFORE the current one VAR CumulativePreviousDifference = CALCULATE ( SUM ( 'SalesContractDistribution'[Qty] ) - CALCULATE ( SUM ( 'SalesContractDelivery'[Qty] ), 'SalesContractDelivery'[Status] = "Delivered" ), FILTER ( ALL ( 'Calendar' ), 'Calendar'[Date] < FirstDateOfCurrentPeriod ) ) -- Return the current month's plan adjusted by the cumulative past difference. -- If there was an under-delivery (positive difference), it's added. -- If there was an over-delivery (negative difference), it's subtracted. RETURN CurrentMonthDistribution + CumulativePreviousDifferenceThis DAX measure operates by first capturing the originally planned distribution for the current period in a variable. It then determines the start date of this period to serve as an anchor point. The core of the logic lies in the CALCULATE function, which modifies the report's context. It calculates the total historical difference between planned and delivered quantities for all periods before the start of the current one. This is achieved by using FILTER with ALL('Calendar') to remove the current date context and apply a new one for all past dates. The final RETURN statement simply adds this cumulative past difference to the current month's plan. If you under-delivered in the past, the positive difference increases the current month's target; if you over-delivered, the negative difference reduces it.
To use this in your report, create a new measure and paste in the DAX code. You can then add this measure to a Matrix visual to see the results. For a comprehensive view, place the 'Sales Contract'[Contract Number] on the rows, the 'Calendar'[Year] and 'Calendar'[Month] on the columns, and then add your original distribution measure, your actual delivered measure, and this new Adjusted Monthly Distribution measure to the values field. This setup will provide a clear, side-by-side comparison of the original plan versus the dynamically adjusted plan for each contract over time.
Best regards,
- v-kpoloju-msftCommunity Support
Hi NLMV,
Thank you for reaching out to the Microsoft Fabric Community Forum. Also, thanks to DataNinja777, for his inputs on this thread.Has your issue been resolved? If the response provided by the community member DataNinja777, addressed your query, could you please confirm? It helps us ensure that the solutions provided are effective and beneficial for everyone.
Hope this helps clarify things and let me know what you find after giving these steps a try happy to help you investigate this further.
Thank you for using the Microsoft Community Forum.- v-kpoloju-msftCommunity Support
Hi NLMV,
Hope you had a chance to try out the solution shared earlier. Let us know if anything needs further clarification or if there's an update from your side always here to help.Thank you.
- v-kpoloju-msftCommunity Support
Hi NLMV,
Just wanted to follow up one last time. If the shared guidance worked for you, that’s wonderful hopefully it also helps others looking for similar answers. If there’s anything else you'd like to explore or clarify, don’t hesitate to reach out.Thank you.
- Ashish_MathurSuper User
Hi,
Share the download link of an MS Excel workbook with your formulas written there. I will understand that logic and convert those Excel formulas to DAX measures.