Forum Discussion
Dax logic not working
Hi ClaudioF ,
To confirm if the issue is related to the source, you can export the data from the internal source to an Excel file and use it in a non-working dashboard, then see if the issue persists.
You can also:
Check that the field types (numeric, text, date, etc.) are the same in both the Excel source and the internal source; there may be null values or formatting irregularities in Excel.
Confirm that the table relationships and sorting rules in the two data models are identical.
If you have any other questions please feel free to contact me.
Best Regards,
Yang
Community Support Team
If 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!
- ClaudioF1 year ago
Helper II
Anonymous Thankyou for yout repply, i just found the problem, that was wiht the logic, when running if the value of the item was bigger than the available stock, then the logic worked, but, when the quantity was smaller than the stock but the stock was allready used, the logic summed and then keeps summing.. still trying to find the solution
- v-venuppu1 year ago
Community Support
Hi ClaudioF ,
Thank you for reaching out to Microsoft Fabric Community.
Thank you Anonymous for the prompt response.
It sounds like the core issue here isn't the data source, but how the DAX logic is handling stock depletion across filtered orders. You're right in identifying that even after stock is exhausted, the DAX measure continues to evaluate orders as if stock is still available which results in incorrect behavior.
What’s Going Wrong:
DAX measures don’t maintain row-by-row “state” like procedural code. So something like this:
CALCULATE (
SUM ( Orders[Quantity] ),
FILTER ( Orders, Orders[Quantity] <= [RemainingStock] )
)doesn’t subtract quantities across rows, it just filters based on a static condition.
Here's some steps to fix it:
1. Rank the Orders
Assign a rank based on order priority (Order Number or Date).
OrderRank = RANKX(ALL(Orders), Orders[OrderDate], , ASC, DENSE)
2. Calculate Cumulative Demand
In a calculated column, add up the quantities of all prior orders.
CumulativeDemand =
CALCULATE (
SUM ( Orders[Quantity] ),
FILTER (
Orders,
Orders[OrderRank] <= EARLIER ( Orders[OrderRank] )
)
)3. Determine If Stock Is Allocated
Only allocate if the cumulative demand is still within available stock.
IsAllocated =
IF ( Orders[CumulativeDemand] <= [TotalAvailableStock], 1, 0 )You can then filter or sum orders with IsAllocated = 1 to get correct fulfillment values.
If the logic gets messy in DAX, this is actually easier to handle in Power Query with a grouped table and a running total column that lets you stop allocation once stock is exhausted.
If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it!
Thank you.
- v-venuppu1 year ago
Community 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.