Forum Discussion
Complex conditional summing
Hi ClaudioF,
Thank you for reaching out to the Microsoft fabric community forum. Thank you techies, for your inputs on this issue.
You're certainly not alone in finding sequential stock allocation logic challenging in DAX, as it is not inherently procedural.
The positive news is that what you're aiming to achieve is feasible in Power BI using a calculated column. Here's the approach that works:
- Create a running total of the QtyRequested per order, sorted by OrderID.
- Compare this cumulative quantity to your total available stock (e.g., 21 units).
- If the cumulative total is less than or equal to the stock, mark the order as "Available"; otherwise, mark it as "Not Available".
Here’s a simplified version of the DAX formula you can use for a calculated column:
Status =
VAR Stock = 21
VAR CumQty =
CALCULATE (
SUM ( Orders[QtyRequested] ),
FILTER (
Orders,
Orders[OrderID] <= EARLIER ( Orders[OrderID] )
)
)
RETURN
IF ( CumQty <= Stock, "Available", "Not Available" )
Just make sure your table has a proper OrderID or sort column to maintain row order, and you can adjust the stock reference if it comes from another table.
If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.
Thank you for using Microsoft Community Forum.
Hi ClaudioF,
May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.
Thank you.
- v-kpoloju-msft1 year agoCommunity Support
Hi ClaudioF,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.- v-kpoloju-msft1 year agoCommunity Support
Hi ClaudioF,
I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.
Thank you.