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
hello carmae
I might be misunderstood your need, but let me offer some ways to enlighten your problem.
if you need to show sum of each 'Type', then matrix visual might be your answer.
besides that, what i got from your description, looks like you want to do cumulative sum of 'Quantity' but the value become zero if sum value is negative.
Cumulative =
var _Sum=
SUMX(
FILTER(
'Table',
'Table'[Date Item]<=EARLIER('Table'[Date Item])
),
'Table'[Quantity]
)
Return
IF(
_Sum<0,
0,
_Sum
)
Hope this will help.
Thank you.
Thanks for your reply. I'll try to better explain my issue: on 30/08 the quantity is zero. Then on 31/08 20 units get added to inventory. Then on 01/09 2 units are forecasted to be sold. So the quantity on 01/09 should be 18, not 5.
Maybe it's clearer if I explain that we do not keep back orders. So forecasted sales on days with zero inventory should not cumulate.
Hope I managed to explain myself, English is not my native tongue, as you can easily guess! 😄