Forum Discussion
Future inventory level
- Anonymous2 years ago
Hi, carmae
Yes, if you want to group and accumulate data, you only need to go one more step to group by Item.let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fdIxDsMgDIXhuzCnAmxCyBF6hihjx269v8ryiBKePaJPWGD9xxHev883hyWkFiVHSVL6IadwLncT2Esn02FlsgJbJ1rHNZmsOiM35ynNubcPq0/TZL9Fx1rksZY9pmzd6yaOqfWHbtbKOl0rm606IzfnKc2Zea0sDxOnFhirBcZqgZGvg1gtMFYLjNUCY7XAWC3i1AJjtYhTC4zVAmO1wKyVGbXAWC0wVguM1QK71XL+AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t, #"Date Item" = _t, Quantity = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", type text}, {"Date Item", type date}, {"Quantity", Int64.Type}}), FX = (values as list) as list => let GRTList = List.Generate( () => [GRT = values{0}, i = 0], each [i] < List.Count(values), each let nextGRT = if [GRT] > 0 then [GRT] + values{[i] + 1} else values{[i] + 1} in [GRT = nextGRT, i = [i] + 1], each [GRT] ) in GRTList, // Group by Item and apply transformations Grouped = Table.Group( #"Changed Type", {"Item"}, { {"Transformed", each let dateitemlist = List.Buffer([Date Item]), quantitylist = List.Buffer([#"Quantity"]), result = Table.FromColumns( {dateitemlist, quantitylist, List.Transform(FX(quantitylist), each if _ < 0 then 0 else _)}, {"Date Item", "Quantity", "Output"} ) in result } } ), #"Expanded Transformed" = Table.ExpandTableColumn(Grouped, "Transformed", {"Date Item", "Quantity", "Output"}, {"Date Item", "Quantity", "Output"}) in #"Expanded Transformed"Best Regards,
Yang
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
Seems to work like magic! Unfortunately I'm not that good in M so I should study this piece of code.
Would you be so kind to help me go further? Since I will do this for more than one item how should I modify this to work with several items.
As an example I think you could add a column "Item code", duplicate rows and assign "Item1" to half of them and "Item2" to the remaining.
Thanks again, you're helping me a lot.
C.