Forum Discussion
dax formula help (Distribution) v2
Hello,
Thanks for the answer to the original post.
https://community.powerbi.com/t5/Desktop/dax-formula-help-Distribution/td-p/423428
Distributed Stocks =
VAR stock_to_distirubute =
CALCULATE (
SUM ( Table2[Stock Qty] ),
CROSSFILTER ( Table2[Product], Table1[Product], BOTH )
)
VAR Cumulativestock =
CALCULATE (
SUM ( Table1[Requested Qty] ),
FILTER (
ALLEXCEPT ( Table1, Table1[Product] ),
Table1[Rquested Delivery Date]
<= SELECTEDVALUE ( Table1[Rquested Delivery Date] )
)
)
VAR myqty =
IF (
Cumulativestock > stock_to_distirubute,
SELECTEDVALUE ( Table1[Requested Qty] )
- ( Cumulativestock - stock_to_distirubute ),
SELECTEDVALUE ( Table1[Requested Qty] )
)
RETURN
IF ( myqty < 0, 0, myqty )
I wanted to know if it is possible to add a bit more complexity to the problem by adding another column to table 2. I kept searching to modify the code but i can't manage to make anything work.
Explanation of the problem :
Given the image below, and the algorithm already given, how can i include the idea that the stock is not already available at the beginning ? i receive a bit of stock every week (hence my week column in table 2).
Also, how can i simulate the fact that i might have to distribute the stock during two weeks because not enough stock (see example in grey )? How can i display the week when the distribution occured ?
Thanks a lot in advance.
5 Replies
- v-alq-msftCommunity Support
Hi, Anonymous
It is unavailable to add rows dynamically with Dax. You may try to use Power Query to achieve it. I wonder why you want to achieve the result in desktop.
Best Regards
Allan
- AnonymousNot applicable
Hello v-alq-msft,
so there is no way to achieve what i want to do in DAX ?
I wanted to do it in desktop because i want to be able to display graphs with the distribution on power BI.
At the beginning i did it with SUMIFS in excel, and 3 columns in an excel sheet, then i was loading the results in a query. But as i wanted to automate everything in a query directly to export it on power BI i faced a problem of circular columns. Then i saw this solution in dax.
I can try to share my excel file, to show you what i did with my sumifs, but so far was not able to translate this solution in power query directly.
- AnonymousNot applicable
why can't i post