Forum Discussion
Get earliest date when condition fulfilled
Hi,
I have a technical problem that I cannot solve...
In my model I have two tables. one for Orders and one for Production records.
The table of orders contains, among other data, also the required quantity and the estimated date for shipment.
The table of production contains the production events in related to the different orders - quantities and their date.
For example I have order X for 6,000 units to be delivered at Aug 1, 2018 and at the Production table I can find the following related records for production:
- 2,000 units at July 25
- 3,000 units at July 26
- 1,000 units at Aug 2.
- 200 units at Aug 3 (an extra quantity).
For each order I would like to get the date that all required quantity of the order as been manufactured.
This shall be the earliest date that the fulfill the condition that all required units were produced.
(earliest date since we might produce an extra units).
At the example mentioned above the expected date shall be Aug 2
Any idea how it can be done ? by DAX or Power Query ? can it be a calculated column?
Thanks in advance.
2 Replies
- StachuCommunity Champion
assuming following tables structure
OrderOrder Quantity DeliveryDate X 6000 01/08/2018 Y 500 02/07/2018 Production
Order ProductionDate Quantity X 25/07/2018 2000 X 26/07/2018 3000 X 02/08/2018 1000 X 03/08/2018 200 Y 03/06/2018 300 Y 04/06/2018 300 Y 24/06/2018 300 this code will work as calculated column in Order
ProducedDate = VAR RequestedQuantity = 'Order'[Quantity] VAR AccumulatedProduction = ADDCOLUMNS ( Production, "ProducedQuantity", CALCULATE ( SUM ( Production[Quantity] ), FILTER ( Production, Production[Order] = EARLIER ( Production[Order] ) && Production[ProductionDate] <= EARLIER ( Production[ProductionDate] ) ) ) ) VAR CompletedProduction = FILTER ( AccumulatedProduction, [ProducedQuantity] >= RequestedQuantity ) RETURN CALCULATE ( FIRSTDATE ( Production[ProductionDate] ), CompletedProduction )EDIT - I assume there is join between the tables on Order
- ShukshukFrequent Visitor
Hi Stachu,
Thank you very much on your prompt reply.
Unfortunately this yield to me error of "there is not enough memory to complete the operation" so I cannot use this solution...
I think I need to provide some more info:
1. the table of production has many many records (it is large table...)
2. the relation between orders to production is one to many (many production records related to a single order)
3. I already have the following 2 measures:
- At Production table I have
Cumulative Production = CALCULATE ( [Total Production] ,FILTER (ALLSELECTED( Production ),Production[Date] <= MAX ( Production[Date] )) )
- At Orders table I have
Order Cumulative Production = CALCULATE([Cumulative Production], FILTER(Production,Production[Date] <= LASTDATE(Orders[RequiredDate])))
Any other solution ?
Thanks in advance