Forum Discussion
Only Return Work Order Numbers After Amount Is Distributed
Not sure how its returning negative numbers at all. Can you share some sample data via dropbox or Google Drive or similar ?
Hey John,
You can find a sample dataset here. I just pulled out a few item codes for you to look at, the one I already mentioned and two more. Also attached a screengrab of what im expecting the other two to look like just like I did for WO 00-201604. Let me know if this link works for you, if not I can try to do it through Google Drive.
Thanks again for the help, we are really stumped!
- Anonymous3 years agoNot applicable
It appears that link isnt working, here it is in google drive: https://drive.google.com/drive/folders/1Vtg1ziC7lYcPFPIDSZ-XKQWSPVyQdd-Q?usp=sharing
- johnt753 years agoSuper User
OK, one of the issues is that the date isn't a low enough granularity to do comparisons on, because there are multiple orders for the same item on the same day. You need another column, preferably numeric, which is unique for each row and can be used to determine the order. If you don't have one in the source data you can create one in Power Query. I did it by sorting the table by date and then work order with the M code below
let Source = Excel.Workbook(File.Contents(""), null, true), Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data], #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"WorkOrder", type text}, {"PreviousIndexNumber", Int64.Type}, {"LinkToNextLine", Int64.Type}, {"Revision", type text}, {"StepNumber", Int64.Type}, {"UM", type text}, {"ItemDescription", type text}, {"Whse", Int64.Type}, {"ComponentItemNumber", type text}, {"QtyParent", Int64.Type}, {"UMconversion", Int64.Type}, {"UnitCost", type number}, {"ScrapPercent", Int64.Type}, {"ExtdQtyRequired", Int64.Type}, {"QtyIssued", Int64.Type}, {"QtyCommitted", Int64.Type}, {"DirectCosts", Int64.Type}, {"FixedOvhdCosts", Int64.Type}, {"VariableOvhdCosts", Int64.Type}, {"StdFixedOverheadAmount", Int64.Type}, {"StdVarOverheadAmount", Int64.Type}, {"WODueDate_CC", type date}, {"OrderStatus", type text}}), #"Sorted Rows" = Table.Sort(#"Changed Type",{{"WODueDate_CC", Order.Ascending}, {"WorkOrder", Order.Ascending}}), #"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 1, 1, Int64.Type) in #"Added Index"Its just the last 2 steps you need really.
Once you have that column you can change the measure to be
Shortfall = SUMX( 'WO2_WorkOrderMaterialDetail', VAR QuantityOnHand = RELATED( 'IM_ItemWarehouse'[QuantityOnHand] ) VAR RequiredAmount = 'WO2_WorkOrderMaterialDetail'[QtyCommitted] VAR CurrentIndex = 'WO2_WorkOrderMaterialDetail'[Index] VAR PreviouslyUsed = CALCULATE( SUM( 'WO2_WorkOrderMaterialDetail'[QtyCommitted] ), ALLEXCEPT( 'WO2_WorkOrderMaterialDetail', 'WO2_WorkOrderMaterialDetail'[ComponentItemNumber] ), 'WO2_WorkOrderMaterialDetail'[Index] < CurrentIndex ) VAR AvailableStock = MAX( QuantityOnHand - PreviouslyUsed, 0 ) RETURN MAX( RequiredAmount - AvailableStock, 0 ) )This now uses the new index column and I also tweaked the return statement so that it won't return negative numbers.
- Anonymous3 years agoNot applicable
So this works perfectly for us, issue is that this is so demanding it crashes every visual I try to put it in (matrix or table). Could you think of any other route to go about this? Any advicce would be helpful, thank you!